donaSuccess.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <view class="content">
  3. <view class="box">
  4. <view class="music">
  5. <view class="player playing" :class="playing?'none':'keepgo'" @click.stop="play">
  6. <image src="../../static/img/music2.png" style="width: 68rpx;height: 68rpx;" :animation="animationData"></image>
  7. </view>
  8. </view>
  9. <canvas v-if="showcanvas" id="qrShareBox" canvas-id="qrShareBox" class="tki-qrcode-canvas" />
  10. <image class="imgbox" v-else :src="img"></image>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. import {
  16. weixindata
  17. } from '@/utils/wxAuthorized.js';
  18. export default {
  19. data() {
  20. return {
  21. money:'',
  22. url:'',
  23. img:'',
  24. showcanvas:true,
  25. loading: true, //是否载入图片中
  26. size: 180,
  27. ratio: 1, //页面比例用于计算
  28. canHeight: '',
  29. canWeidth: '',
  30. playing: true,
  31. current: {
  32. src: '../../static/audio/xx.mp3',
  33. },
  34. rotateIndex: '',
  35. animation: {},
  36. animationData: {},
  37. audioAction: {
  38. method: 'pause'
  39. },
  40. ran: -1,
  41. isStop: true,
  42. demo: 0
  43. }
  44. },
  45. onReady() {
  46. let query = uni.createSelectorQuery();
  47. let obj = this
  48. console.log(999,obj.money)
  49. // 获取页面比例
  50. query
  51. .select('.box')
  52. .fields({
  53. size: true
  54. },
  55. e => {
  56. console.log('获取页面比例', e)
  57. // 保存比例
  58. this.ratio = e.width / 750;
  59. }
  60. )
  61. .exec();
  62. // 获取画布宽高信息
  63. query
  64. .select('#qrShareBox')
  65. .fields({
  66. size: true
  67. },
  68. e => {
  69. console.log('获取画布宽高信息', e)
  70. obj.canHeight = e.height;
  71. obj.canWeidth = e.width;
  72. }
  73. )
  74. .exec();
  75. let ctxBg = '/index/static/img/thanks.png'; //画布背景
  76. let src = '/index/static/img/erweima.jpg' // 二维码
  77. let context = uni.createCanvasContext('qrShareBox');
  78. // 插入背景图片
  79. console.log('插入背景图片', ctxBg, 0, 0, obj.canWeidth, obj.canHeight)
  80. context.drawImage(ctxBg, 0, 0, obj.canWeidth, obj.canHeight);
  81. const codeSize = obj.size * obj.ratio; //计算二维码大小
  82. const codeX = ((750 - obj.size) * obj.ratio) / 2; //二维码所在x轴位置
  83. const codeY = 950 * obj.ratio; //二维码所在y轴位置
  84. const codeBoxColor = '#FFFFFF'; //包裹框颜色
  85. const codeBoxWidht = 0; //包裹边框宽度
  86. const codeBoxSize = (codeBoxWidht / 2) * obj.ratio; //计算二维码白色包裹框大小
  87. const codeBoxX = codeX - codeBoxSize; //包裹框初始X轴
  88. const codeBoxY = codeY - codeBoxSize; //包裹框初始Y轴
  89. const codeBoxEnd = codeSize + codeBoxWidht * obj.ratio; //计算包裹框大小
  90. const fontTop = codeY + codeBoxEnd + (codeBoxWidht + 20) * obj.ratio; //文字距离上边距高度
  91. const fontSize = 24 * obj.ratio; //文字大小
  92. const fontText = ''; //文字内容
  93. const fontLeft = (codeSize - fontSize * fontText.length) / 2 + codeX; //文字左侧距离
  94. // // 插入文字
  95. context.setFontSize(28)
  96. context.setFillStyle('#d5493b')
  97. // context.fillText('感谢信', ((750 - obj.size) * obj.ratio) / 2, 260 * obj.ratio)
  98. context.setFontSize(30 * obj.ratio)
  99. // context.fillText('感谢信', ((750 - obj.size) * obj.ratio) / 2, 260 * obj.ratio)
  100. context.setFontSize(30 * obj.ratio)
  101. context.fillText('感谢您积极参与武汉市东西湖区红十字会志愿', (110 * obj.ratio), 400 * obj.ratio)
  102. // context.fillText('感谢您积极参与武汉市江夏区红十字会志', (115* obj.ratio), 370 * obj.ratio)
  103. context.fillText('者的各项活动。关爱他人、无私奉献,为有需要的', (50 * obj.ratio), 450 * obj.ratio)
  104. context.fillText('人送去温暖,用实际行动诠释“人道、博爱、奉献”', (50 * obj.ratio), 500 * obj.ratio)
  105. context.fillText('的红十字精神。', (50 * obj.ratio), 550 * obj.ratio)
  106. context.fillText('祝您及家人身体健康,万事如意!我们一起', (110 * obj.ratio), 640 * obj.ratio)
  107. context.fillText('将大爱传递”。', (50 * obj.ratio), 690 * obj.ratio)
  108. // context.fillText('此致', (640 * obj.ratio), 630 * obj.ratio)
  109. // context.fillText('谨表谢意', (580 * obj.ratio), 680 * obj.ratio)
  110. context.fillText('武汉市东西湖区红十字会', (370 * obj.ratio), 880 * obj.ratio)
  111. // 插入二维码
  112. // console.log(codeX, codeY, codeSize, 999)
  113. context.drawImage(src, codeX, codeY, codeSize, codeSize);
  114. // 生成
  115. context.draw(false, (e) => {
  116. uni.canvasToTempFilePath({
  117. x: 0,
  118. y: 0,
  119. width: obj.canWeidth,
  120. height: obj.canHeight,
  121. destWidth: obj.canWeidth,
  122. destHeight: obj.canHeight,
  123. canvasId: 'qrShareBox',
  124. success: function(res) {
  125. console.log(333, res)
  126. // 在H5平台下,tempFilePath 为 base64
  127. obj.showcanvas = false;
  128. obj.img = res.tempFilePath
  129. }
  130. })
  131. })
  132. },
  133. onShow() {
  134. var animation = uni.createAnimation()
  135. this.animation = animation
  136. if (this.isStop) {
  137. // 使用动画
  138. this.scaleAndScale()
  139. this.timer = setInterval(() => { //创建定时器,3秒执行异一次
  140. this.scaleAndScale()
  141. // console.log('每三秒执行一次 , 达到往复运动的效果')
  142. }, 1000)
  143. } else {
  144. this.noscaleAndScale()
  145. }
  146. },
  147. onLoad(option) {
  148. console.log(333,option)
  149. this.money = option.money
  150. this.IndexShare();
  151. this.ScanAudio(true)
  152. },
  153. onHide() { //在页面隐藏时也要清除定时器
  154. if (this.timer) {
  155. // console.log('清除定时器-' + this.timer)
  156. clearInterval(this.timer)
  157. }
  158. },
  159. onUnload() { //在页面卸载时清除定时器 避免出现多个定时器连续创建动画
  160. if (this.timer) {
  161. console.log('清除定时器-' + this.timer)
  162. clearInterval(this.timer)
  163. }
  164. },
  165. methods: {
  166. // 分享
  167. IndexShare() {
  168. let obj = this;
  169. let item = {
  170. link: 'http://jxred.igxys.com/home/#/pages/donaSuccess/donaSuccess',// 分享链接
  171. imgUrl: '/index/static/img/002.png',
  172. desc: '感谢信',
  173. title: '武汉市东西湖区红十字会',
  174. success: console.log('分享加载成功')
  175. };
  176. console.log('分享加',item)
  177. weixindata(item);
  178. },
  179. musicClick() {
  180. // if (this.isRoate) {
  181. // this.isRoate = false
  182. // this.stopScanAudio()
  183. // } else {
  184. // this.isRoate = true
  185. // this.ScanAudio()
  186. // }
  187. },
  188. play() {
  189. this.playing = !this.playing;
  190. this.ScanAudio(this.playing);
  191. if (this.playing == true) {
  192. this.timer = setInterval(() => { //创建定时器,3秒执行异一次
  193. this.scaleAndScale()
  194. console.log('每1秒执行一次')
  195. }, 1000)
  196. } else {
  197. clearInterval(this.timer)
  198. }
  199. // var music = uni.createInnerAudioContext();
  200. // music.src= "../../static/audio/xx.mp3"; //选择播放的音频
  201. // music.onPause(); //暂停播放
  202. // console.log('暂停播放')
  203. // console.log('dianjizanting')
  204. // this.stopAudio()
  205. // this.playing = !this.playing; //背景音乐点击,暂停或继续
  206. },
  207. // 定义动画内容
  208. scaleAndScale() {
  209. // 定义动画内容
  210. // this.animation.scale(1.2, 1.2).step() //先放大1,2倍
  211. // this.animation.scale(1, 1).step() //缩小至原来的大小
  212. // 导出动画数据传递给data层
  213. // this.animationData = this.animation.export(); //每次执行导出动画时 会覆盖之前的动画
  214. this.animation.rotate(this.demo).step({
  215. duration: 1000
  216. })
  217. this.animationData = this.animation.export()
  218. this.demo += 360;
  219. },
  220. noscaleAndScale() {
  221. this.animation.rotate(0).step({
  222. duration: 1000
  223. })
  224. this.animationData = this.animation.export()
  225. },
  226. // ScanAudio(){
  227. // this.$api.music.play(); //执行播放
  228. // console.log('执行播放')
  229. // }
  230. }
  231. }
  232. </script>
  233. <style lang="scss">
  234. page {
  235. width: 100%;
  236. height: 100%;
  237. }
  238. .content {
  239. // background-color: pink;
  240. width: 100%;
  241. height: 100%;
  242. position: relative;
  243. .bgimg {
  244. width: 100%;
  245. height: 100%;
  246. // background-color: pink;
  247. image {
  248. width: 100%;
  249. height: 100%;
  250. }
  251. }
  252. .tki-qrcode-canvas {
  253. width: 750rpx;
  254. height: 1340rpx;
  255. margin: 0 auto;
  256. // background-color: pink;
  257. }
  258. .box {
  259. // position: absolute;
  260. // left: 0;
  261. // top: 0;
  262. // background-color: pink;
  263. // width: 100%;
  264. // height: 100%;
  265. // display: flex;
  266. // flex-direction: column;
  267. // align-items: center;
  268. // color: #FFFFFF;
  269. // padding: 0rpx 32rpx 0 32rpx;
  270. color: #FFFFFF;
  271. width: 100%;
  272. height: 100vh;
  273. // background-color: pink;
  274. .music {
  275. // width: 55rpx;
  276. // height: 55rpx;
  277. border-radius: 28rpx;
  278. // background-color: pink;
  279. position: absolute;
  280. left: 12rpx;
  281. top: 250rpx;
  282. z-index: 999;
  283. }
  284. // .title {
  285. // margin-top: 234rpx;
  286. // font-size: 54rpx;
  287. // }
  288. // .main {
  289. // margin-top: 20rpx;
  290. // font-size: 32rpx;
  291. // .box-2 {
  292. // text-indent: 68rpx;
  293. // margin-top: 12rpx;
  294. // }
  295. // }
  296. // .footer {
  297. // margin-top: 32rpx;
  298. // // background-color: pink;
  299. // width: 100%;
  300. // .box-1 {
  301. // display: flex;
  302. // justify-content: flex-end;
  303. // font-size: 28rpx;
  304. // // padding-right: 14rpx;
  305. // }
  306. // }
  307. }
  308. // .playing {
  309. // animation: run 10s linear 0s infinite;
  310. // }
  311. // .player {
  312. // width: 65rpx;
  313. // height: 65rpx;
  314. // border-radius: 50%;
  315. // background-color: rgba(0, 0, 0, 0.1);
  316. // z-index: 999999;
  317. // }
  318. .keepgo {
  319. animation-play-state: paused;
  320. }
  321. .imgbox{
  322. height: 1340rpx;
  323. width:100%;
  324. }
  325. }
  326. </style>