123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- <template>
- <view class="content">
- <view class="box">
- <view class="music">
- <view class="player playing" :class="playing?'none':'keepgo'" @click.stop="play">
- <image src="../../static/img/music.png" style="width: 68rpx;height: 68rpx;" :animation="animationData"></image>
- </view>
- </view>
- <canvas v-if="showcanvas" id="qrShareBox" canvas-id="qrShareBox" class="tki-qrcode-canvas" />
- <image class="imgbox" v-else :src="img"></image>
- </view>
- </view>
- </template>
- <script>
- // #ifdef H5
- // import { weixindata, weixinhideMenu } from '@/utils/wxAuthorized';
- import {
- weixindata,
- weixinlocation
- } from '@/utils/wxAuthorized.js';
- // #endif
- export default {
- data() {
- return {
- url:'',
- img:'',
- showcanvas:true,
- loading: true, //是否载入图片中
- size: 180,
- ratio: 1, //页面比例用于计算
- canHeight: '',
- canWeidth: '',
- playing: true,
- current: {
- src: '../../static/audio/xx.mp3',
- },
- rotateIndex: '',
- animation: {},
- animationData: {},
- audioAction: {
- method: 'pause'
- },
- ran: -1,
- isStop: true,
- demo: 0
- }
- },
- onReady() {
- let query = uni.createSelectorQuery();
- let obj = this
- // 获取页面比例
- query
- .select('.box')
- .fields({
- size: true
- },
- e => {
- console.log('获取页面比例', e)
- // 保存比例
- this.ratio = e.width / 750;
- }
- )
- .exec();
- // 获取画布宽高信息
- query
- .select('#qrShareBox')
- .fields({
- size: true
- },
- e => {
- console.log('获取画布宽高信息', e)
- obj.canHeight = e.height;
- obj.canWeidth = e.width;
- }
- )
- .exec();
- let ctxBg = '/index/static/img/thanks.png'; //画布背景
- let src = '/index/static/erweima.png' // 二维码
- let context = uni.createCanvasContext('qrShareBox');
- // 插入背景图片
- console.log('插入背景图片', ctxBg, 0, 0, obj.canWeidth, obj.canHeight)
- context.drawImage(ctxBg, 0, 0, obj.canWeidth, obj.canHeight);
- const codeSize = obj.size * obj.ratio; //计算二维码大小
- const codeX = ((750 - obj.size) * obj.ratio) / 2; //二维码所在x轴位置
- const codeY = 999 * obj.ratio; //二维码所在y轴位置
- const codeBoxColor = '#FFFFFF'; //包裹框颜色
- const codeBoxWidht = 0; //包裹边框宽度
- const codeBoxSize = (codeBoxWidht / 2) * obj.ratio; //计算二维码白色包裹框大小
- const codeBoxX = codeX - codeBoxSize; //包裹框初始X轴
- const codeBoxY = codeY - codeBoxSize; //包裹框初始Y轴
- const codeBoxEnd = codeSize + codeBoxWidht * obj.ratio; //计算包裹框大小
- const fontTop = codeY + codeBoxEnd + (codeBoxWidht + 20) * obj.ratio; //文字距离上边距高度
- const fontSize = 24 * obj.ratio; //文字大小
- const fontText = ''; //文字内容
- const fontLeft = (codeSize - fontSize * fontText.length) / 2 + codeX; //文字左侧距离
- // // 插入文字
- context.setFontSize(28)
- // context.setColor('#FFFFFF')
- context.setFillStyle('#FFFFFF')
- context.fillText('感谢信', ((750 - obj.size) * obj.ratio) / 2, 260 * obj.ratio)
- context.setFontSize(30 * obj.ratio)
- context.fillText('感谢您积极参与武汉市江夏区红十字会志愿者', (110 * obj.ratio), 340 * obj.ratio)
- // context.fillText('感谢您积极参与武汉市江夏区红十字会志', (115* obj.ratio), 370 * obj.ratio)
- context.fillText('的各项活动。关爱他人、无私奉献,为有需要的人', (50 * obj.ratio), 390 * obj.ratio)
- context.fillText('送去温暖,用实际行动诠释“人道、博爱、奉献”', (50 * obj.ratio), 440 * obj.ratio)
- context.fillText('的红十字精神。', (50 * obj.ratio), 490 * obj.ratio)
- context.fillText('祝您及家人身体健康,万事如意!我们一起', (110 * obj.ratio), 540 * obj.ratio)
- context.fillText('将大爱传递”。', (50 * obj.ratio), 590 * obj.ratio)
- // context.fillText('此致', (640 * obj.ratio), 630 * obj.ratio)
- // context.fillText('谨表谢意', (580 * obj.ratio), 680 * obj.ratio)
- context.fillText('武汉市江夏区红十字会', (400 * obj.ratio), 730 * obj.ratio)
- // 插入二维码
- // console.log(codeX, codeY, codeSize, 999)
- context.drawImage(src, codeX, codeY, codeSize, codeSize);
- // context.draw()
- // 生成
- context.draw(false, (e) => {
- uni.canvasToTempFilePath({
- x: 0,
- y: 0,
- width: obj.canWeidth,
- height: obj.canHeight,
- destWidth: obj.canWeidth,
- destHeight: obj.canHeight,
- canvasId: 'qrShareBox',
- success: function(res) {
- console.log(333, res)
- // 在H5平台下,tempFilePath 为 base64
- obj.showcanvas = false;
- obj.img = res.tempFilePath
- // let url = res.tempFilePath
- // console.log('res.tempFilePath',res.tempFilePath)
- // function dataURLtoFile(dataurl, filename = 'file') {
- // let arr = dataurl.split(',')
- // let mime = arr[0].match(/:(.*?);/)[1]
- // let suffix = mime.split('/')[1]
- // let bstr = atob(arr[1])
- // let n = bstr.length
- // let u8arr = new Uint8Array(n)
- // while (n--) {
- // u8arr[n] = bstr.charCodeAt(n)
- // }
- // return new File([u8arr], `${filename}.${suffix}`, {
- // type: mime
- // })
- // }
- // var base64Img = res.tempFilePath // base64编码的图片
- // var imgFile = dataURLtoFile(base64Img)
- // console.log('imgFile====>', imgFile)
-
- // let url = imgFile
-
- // uni.downloadFile({
- // url: url,
- // // url: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/uni@2x.png',
- // success(res) {
- // console.log('res.tempFilePath:', res.tempFilePath)
- // obj.showcanvas = false;
- // obj.img = res.tempFilePath
- // }
- // })
- }
- })
- })
- },
- onShow() {
- var animation = uni.createAnimation()
- this.animation = animation
- if (this.isStop) {
- // 使用动画
- this.scaleAndScale()
- this.timer = setInterval(() => { //创建定时器,3秒执行异一次
- this.scaleAndScale()
- // console.log('每三秒执行一次 , 达到往复运动的效果')
- }, 1000)
- } else {
- this.noscaleAndScale()
- }
- },
- onLoad() {
- this.shareIs();
- this.ScanAudio(true)
- // app.audioMusic.src = '../../static/audio/xx.png';
- // const innerAudioContext = uni.createInnerAudioContext();
- // innerAudioContext.autoplay = true;
- // innerAudioContext.src = '../../static/audio/xx.png';
- // console.log(1123);
- // innerAudioContext.onPlay(() => {
- // console.log('开始播放');
- // });
- // innerAudioContext.onError((res) => {
- // console.log('出错了');
- // console.log(res);
- // // console.log(res);
- // });
- },
- onHide() { //在页面隐藏时也要清除定时器
- if (this.timer) {
- // console.log('清除定时器-' + this.timer)
- clearInterval(this.timer)
- }
- },
- onUnload() { //在页面卸载时清除定时器 避免出现多个定时器连续创建动画
- if (this.timer) {
- console.log('清除定时器-' + this.timer)
- clearInterval(this.timer)
- }
- },
- methods: {
- // 加载分享
- shareIs(data) {
-
- let obj = this;
- let item = {
- link: 'http://jxred.igxys.com/index/#/pages/form/donaSuccess',// 分享链接
- imgUrl: '/index/static/img/002.png',
- desc: '感谢信',
- title: '武汉市江夏区红十字会',
- success: console.log('分享加载成功')
- };
- console.log('分享加',item)
- weixindata(item);
-
- },
-
- musicClick() {
- // if (this.isRoate) {
- // this.isRoate = false
- // this.stopScanAudio()
- // } else {
- // this.isRoate = true
- // this.ScanAudio()
- // }
- },
- play() {
- this.playing = !this.playing;
- this.ScanAudio(this.playing);
- if (this.playing == true) {
- this.timer = setInterval(() => { //创建定时器,3秒执行异一次
- this.scaleAndScale()
- console.log('每1秒执行一次')
- }, 1000)
- } else {
- clearInterval(this.timer)
- }
- // var music = uni.createInnerAudioContext();
- // music.src= "../../static/audio/xx.mp3"; //选择播放的音频
- // music.onPause(); //暂停播放
- // console.log('暂停播放')
- // console.log('dianjizanting')
- // this.stopAudio()
- // this.playing = !this.playing; //背景音乐点击,暂停或继续
- },
- // 定义动画内容
- scaleAndScale() {
- // 定义动画内容
- // this.animation.scale(1.2, 1.2).step() //先放大1,2倍
- // this.animation.scale(1, 1).step() //缩小至原来的大小
- // 导出动画数据传递给data层
- // this.animationData = this.animation.export(); //每次执行导出动画时 会覆盖之前的动画
- this.animation.rotate(this.demo).step({
- duration: 1000
- })
- this.animationData = this.animation.export()
- this.demo += 360;
- },
- noscaleAndScale() {
- this.animation.rotate(0).step({
- duration: 1000
- })
- this.animationData = this.animation.export()
- },
- // ScanAudio(){
- // this.$api.music.play(); //执行播放
- // console.log('执行播放')
- // }
- }
- }
- </script>
- <style lang="scss">
- page {
- width: 100%;
- height: 100%;
- }
- .content {
- // background-color: pink;
- width: 100%;
- height: 100%;
- position: relative;
- .bgimg {
- width: 100%;
- height: 100%;
- // background-color: pink;
- image {
- width: 100%;
- height: 100%;
- }
- }
- .tki-qrcode-canvas {
- width: 750rpx;
- height: 1350rpx;
- margin: 0 auto;
- // background-color: pink;
- }
- .box {
- // position: absolute;
- // left: 0;
- // top: 0;
- // background-color: pink;
- // width: 100%;
- // height: 100%;
- // display: flex;
- // flex-direction: column;
- // align-items: center;
- // color: #FFFFFF;
- // padding: 0rpx 32rpx 0 32rpx;
- color: #FFFFFF;
- width: 100%;
- height: 100vh;
- // background-color: pink;
- .music {
- // width: 55rpx;
- // height: 55rpx;
- border-radius: 28rpx;
- // background-color: pink;
- position: absolute;
- left: 12rpx;
- top: 250rpx;
- z-index: 999;
- }
- // .title {
- // margin-top: 234rpx;
- // font-size: 54rpx;
- // }
- // .main {
- // margin-top: 20rpx;
- // font-size: 32rpx;
- // .box-2 {
- // text-indent: 68rpx;
- // margin-top: 12rpx;
- // }
- // }
- // .footer {
- // margin-top: 32rpx;
- // // background-color: pink;
- // width: 100%;
- // .box-1 {
- // display: flex;
- // justify-content: flex-end;
- // font-size: 28rpx;
- // // padding-right: 14rpx;
- // }
- // }
- }
- // .playing {
- // animation: run 10s linear 0s infinite;
- // }
- // .player {
- // width: 65rpx;
- // height: 65rpx;
- // border-radius: 50%;
- // background-color: rgba(0, 0, 0, 0.1);
- // z-index: 999999;
- // }
- .keepgo {
- animation-play-state: paused;
- }
- .imgbox{
- height: 1350rpx;
- width:750rpx;
- }
- }
- </style>
|