donaSuccess.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <template>
  2. <view class="content">
  3. <view class="box">
  4. <view class="music" v-if="money*1 < 1000">
  5. <view class="player playing" :class="playing ? 'none' : 'keepgo'" @click.stop="play">
  6. <image src="../../static/img/music.png" style="width: 68rpx;height: 68rpx;"
  7. :animation="animationData"></image>
  8. </view>
  9. </view>
  10. <canvas v-if="showcanvas" id="qrShareBox" canvas-id="qrShareBox" class="tki-qrcode-canvas" />
  11. <image class="imgbox" v-else :src="img"></image>
  12. </view>
  13. <!-- <image class="image" src="../../static/img/thinks.png" mode=""></image> -->
  14. </view>
  15. </template>
  16. <script>
  17. import {
  18. weixindata
  19. } from '@/utils/wxAuthorized.js';
  20. export default {
  21. data() {
  22. return {
  23. money: '',
  24. url: '',
  25. img: '',
  26. showcanvas: true,
  27. loading: true, //是否载入图片中
  28. size: 180,
  29. ratio: 1, //页面比例用于计算
  30. canHeight: '',
  31. canWeidth: '',
  32. playing: true,
  33. current: {
  34. src: '../../static/audio/xx.mp3'
  35. },
  36. rotateIndex: '',
  37. animation: {},
  38. animationData: {},
  39. audioAction: {
  40. method: 'pause'
  41. },
  42. ran: -1,
  43. isStop: true,
  44. demo: 0,
  45. name: '',
  46. add_time: '',
  47. };
  48. },
  49. onReady() {
  50. let query = uni.createSelectorQuery();
  51. let obj = this;
  52. console.log(999, obj.money);
  53. // 获取页面比例
  54. query
  55. .select('.box')
  56. .fields({
  57. size: true
  58. },
  59. e => {
  60. console.log('获取页面比例', e);
  61. // 保存比例
  62. this.ratio = e.width / 750;
  63. }
  64. )
  65. .exec();
  66. // 获取画布宽高信息
  67. query
  68. .select('#qrShareBox')
  69. .fields({
  70. size: true
  71. },
  72. e => {
  73. console.log('获取画布宽高信息', e);
  74. obj.canHeight = e.height;
  75. obj.canWeidth = e.width;
  76. }
  77. )
  78. .exec();
  79. if (obj.money * 1 >= 1000) {
  80. let ctxBg = '/static/img/jkzs.jpg'; //画布背景
  81. let context = uni.createCanvasContext('qrShareBox');
  82. console.log(context,'context')
  83. context.drawImage(ctxBg, 0, 0, obj.canWeidth, obj.canHeight);
  84. const codeSize = obj.size * obj.ratio; //计算二维码大小
  85. const codeX = ((750 - obj.size) * obj.ratio) / 2; //二维码所在x轴位置
  86. const codeY = 960 * obj.ratio; //二维码所在y轴位置
  87. const codeBoxColor = '#FFFFFF'; //包裹框颜色
  88. const codeBoxWidht = 0; //包裹边框宽度
  89. const codeBoxSize = (codeBoxWidht / 2) * obj.ratio; //计算二维码白色包裹框大小
  90. const codeBoxX = codeX - codeBoxSize; //包裹框初始X轴
  91. const codeBoxY = codeY - codeBoxSize; //包裹框初始Y轴
  92. const codeBoxEnd = codeSize + codeBoxWidht * obj.ratio; //计算包裹框大小
  93. const fontTop = codeY + codeBoxEnd + (codeBoxWidht + 20) * obj.ratio; //文字距离上边距高度
  94. const fontSize = 24 * obj.ratio; //文字大小
  95. const fontText = ''; //文字内容
  96. const fontLeft = (codeSize - fontSize * fontText.length) / 2 + codeX; //文字左侧距离
  97. context.setFillStyle('#000');
  98. // context.fillText('感谢信', ((750 - obj.size) * obj.ratio) / 2, 260 * obj.ratio)
  99. context.setFontSize(32 * obj.ratio);
  100. context.set
  101. context.fillText(this.name + ' 捐款 ' + (this.money*1) + '元', 80 * obj.ratio, 680 * obj.ratio);
  102. context.fillText('上海市长宁区红十字会', 365 * obj.ratio, 1010 * obj.ratio);
  103. context.fillText(obj.add_time, 440 * obj.ratio, 1070 * obj.ratio);
  104. // 生成
  105. context.draw(false, e => {
  106. uni.canvasToTempFilePath({
  107. x: 0,
  108. y: 0,
  109. width: obj.canWeidth,
  110. height: obj.canHeight,
  111. destWidth: obj.canWeidth,
  112. destHeight: obj.canHeight,
  113. canvasId: 'qrShareBox',
  114. success: function(res) {
  115. console.log(333, res);
  116. // 在H5平台下,tempFilePath 为 base64
  117. obj.showcanvas = false;
  118. obj.img = res.tempFilePath;
  119. }
  120. });
  121. });
  122. } else {
  123. let ctxBg = '/static/img/thanks1.png'; //画布背景
  124. let src = '/static/icon/erweima.jpg'; // 二维码
  125. let context = uni.createCanvasContext('qrShareBox');
  126. // 插入背景图片
  127. console.log('插入背景图片', ctxBg, 0, 0, obj.canWeidth, obj.canHeight);
  128. context.drawImage(ctxBg, 0, 0, obj.canWeidth, obj.canHeight);
  129. const codeSize = obj.size * obj.ratio; //计算二维码大小
  130. const codeX = ((750 - obj.size) * obj.ratio) / 2; //二维码所在x轴位置
  131. const codeY = 960 * obj.ratio; //二维码所在y轴位置
  132. const codeBoxColor = '#FFFFFF'; //包裹框颜色
  133. const codeBoxWidht = 0; //包裹边框宽度
  134. const codeBoxSize = (codeBoxWidht / 2) * obj.ratio; //计算二维码白色包裹框大小
  135. const codeBoxX = codeX - codeBoxSize; //包裹框初始X轴
  136. const codeBoxY = codeY - codeBoxSize; //包裹框初始Y轴
  137. const codeBoxEnd = codeSize + codeBoxWidht * obj.ratio; //计算包裹框大小
  138. const fontTop = codeY + codeBoxEnd + (codeBoxWidht + 20) * obj.ratio; //文字距离上边距高度
  139. const fontSize = 24 * obj.ratio; //文字大小
  140. const fontText = ''; //文字内容
  141. const fontLeft = (codeSize - fontSize * fontText.length) / 2 + codeX; //文字左侧距离
  142. // // 插入文字
  143. context.setFontSize(28);
  144. context.setFillStyle('#d5493b');
  145. context.fillText('感谢信', ((750 - obj.size) * obj.ratio) / 2, 260 * obj.ratio)
  146. context.setFontSize(30 * obj.ratio);
  147. context.fillText('尊敬的' + this.name + ':', 60 * obj.ratio, 350 * obj.ratio);
  148. context.fillText('衷心感谢您对长宁区红十字事业的信任与支', 120 * obj.ratio, 410 * obj.ratio);
  149. context.fillText('持!我们已收到您的捐款', 60 * obj.ratio, 465 * obj.ratio);
  150. // 画横线
  151. context.moveTo(380 * obj.ratio, 470 * obj.ratio);
  152. context.lineTo(540 * obj.ratio, 470 * obj.ratio);
  153. context.stroke();
  154. context.setTextAlign('center')
  155. context.fillText('¥' + obj.money, 460 * obj.ratio, 465 * obj.ratio);
  156. context.setTextAlign('left')
  157. context.fillText('元。我们承', 540 * obj.ratio, 465 * obj.ratio);
  158. context.fillText('诺绝不辜负大家的信任,遵照您的意愿,将捐款', 60 * obj.ratio, 520 * obj.ratio);
  159. context.fillText('全部用于相关救助项目。您的善举将给受助人带', 60 * obj.ratio, 575 * obj.ratio);
  160. context.fillText('去温暖!', 60 * obj.ratio, 630 * obj.ratio);
  161. context.fillText('爱心无界,情义无价。谨以此信表达谢意,', 120 * obj.ratio, 680 * obj.ratio);
  162. context.fillText('我们因您更有力量,因您倍感温暖!', 60 * obj.ratio, 735 * obj.ratio);
  163. // context.fillText('谨表谢意', (580 * obj.ratio), 680 * obj.ratio)
  164. // context.setTextAlign('right')
  165. context.fillText('上海市长宁区红十字会', 385* obj.ratio, 850 * obj.ratio);
  166. context.fillText(obj.add_time, 455 * obj.ratio, 910 * obj.ratio);
  167. // 插入二维码
  168. // console.log(codeX, codeY, codeSize, 999)
  169. context.drawImage(src, codeX, codeY, codeSize, codeSize);
  170. // // 生成
  171. // context.draw(false, e => {
  172. // uni.canvasToTempFilePath({
  173. // x: 0,
  174. // y: 0,
  175. // width: obj.canWeidth,
  176. // height: obj.canHeight,
  177. // destWidth: obj.canWeidth,
  178. // destHeight: obj.canHeight,
  179. // canvasId: 'qrShareBox',
  180. // success: function(res) {
  181. // console.log(333, res);
  182. // // 在H5平台下,tempFilePath 为 base64
  183. // obj.showcanvas = false;
  184. // obj.img = res.tempFilePath;
  185. // }
  186. // });
  187. // });
  188. // 生成
  189. context.draw(false, e => {
  190. uni.canvasToTempFilePath({
  191. x: 0,
  192. y: 0,
  193. width: obj.canWeidth,
  194. height: obj.canHeight,
  195. destWidth: obj.canWeidth,
  196. destHeight: obj.canHeight,
  197. canvasId: 'qrShareBox',
  198. success: function(res) {
  199. console.log(333, res);
  200. // 在H5平台下,tempFilePath 为 base64
  201. obj.showcanvas = false;
  202. obj.img = res.tempFilePath;
  203. }
  204. });
  205. });
  206. }
  207. },
  208. onShow() {
  209. var animation = uni.createAnimation();
  210. this.animation = animation;
  211. if (this.isStop) {
  212. // 使用动画
  213. this.scaleAndScale();
  214. this.timer = setInterval(() => {
  215. //创建定时器,3秒执行异一次
  216. this.scaleAndScale();
  217. // console.log('每三秒执行一次 , 达到往复运动的效果')
  218. }, 1000);
  219. } else {
  220. this.noscaleAndScale();
  221. }
  222. },
  223. onLoad(option) {
  224. console.log(333, option);
  225. this.money = option.money;
  226. this.name = decodeURI(option.name)
  227. this.add_time = decodeURI(option.time)
  228. this.IndexShare();
  229. this.ScanAudio(true);
  230. },
  231. onHide() {
  232. //在页面隐藏时也要清除定时器
  233. if (this.timer) {
  234. // console.log('清除定时器-' + this.timer)
  235. clearInterval(this.timer);
  236. }
  237. },
  238. onUnload() {
  239. //在页面卸载时清除定时器 避免出现多个定时器连续创建动画
  240. if (this.timer) {
  241. console.log('清除定时器-' + this.timer);
  242. clearInterval(this.timer);
  243. }
  244. },
  245. methods: {
  246. // 分享
  247. IndexShare() {
  248. let obj = this;
  249. // let money = obj.money;
  250. let item = {
  251. link: obj.$store.state.baseURL + '/index/#/pages/form/donaSuccess?money=' + obj.money + '&name=' +
  252. encodeURI(obj.name) + '&time=' + encodeURI(obj.add_time), // 分享链接
  253. imgUrl: obj.$store.state.baseURL + '/index/static/img/002.png',
  254. desc: '弘扬红十字精神,传播红十字观念,宣传红十字工作,这是一个汇聚爱心、救助之家力量的平台!',
  255. title: '来自长宁区红十字会的感谢信',
  256. success: console.log('分享加载成功')
  257. };
  258. console.log('分享加', item);
  259. weixindata(item);
  260. },
  261. musicClick() {
  262. // if (this.isRoate) {
  263. // this.isRoate = false
  264. // this.stopScanAudio()
  265. // } else {
  266. // this.isRoate = true
  267. // this.ScanAudio()
  268. // }
  269. },
  270. play() {
  271. this.playing = !this.playing;
  272. this.ScanAudio(this.playing);
  273. if (this.playing == true) {
  274. this.timer = setInterval(() => {
  275. //创建定时器,3秒执行异一次
  276. this.scaleAndScale();
  277. console.log('每1秒执行一次');
  278. }, 1000);
  279. } else {
  280. clearInterval(this.timer);
  281. }
  282. // var music = uni.createInnerAudioContext();
  283. // music.src= "../../static/audio/xx.mp3"; //选择播放的音频
  284. // music.onPause(); //暂停播放
  285. // console.log('暂停播放')
  286. // console.log('dianjizanting')
  287. // this.stopAudio()
  288. // this.playing = !this.playing; //背景音乐点击,暂停或继续
  289. },
  290. // 定义动画内容
  291. scaleAndScale() {
  292. // 定义动画内容
  293. // this.animation.scale(1.2, 1.2).step() //先放大1,2倍
  294. // this.animation.scale(1, 1).step() //缩小至原来的大小
  295. // 导出动画数据传递给data层
  296. // this.animationData = this.animation.export(); //每次执行导出动画时 会覆盖之前的动画
  297. this.animation.rotate(this.demo).step({
  298. duration: 1000
  299. });
  300. this.animationData = this.animation.export();
  301. this.demo += 360;
  302. },
  303. noscaleAndScale() {
  304. this.animation.rotate(0).step({
  305. duration: 1000
  306. });
  307. this.animationData = this.animation.export();
  308. }
  309. // ScanAudio(){
  310. // this.$api.music.play(); //执行播放
  311. // console.log('执行播放')
  312. // }
  313. }
  314. };
  315. </script>
  316. <style lang="scss">
  317. page {
  318. width: 100%;
  319. height: 100%;
  320. }
  321. .content {
  322. // background-color: pink;
  323. width: 100%;
  324. height: 100%;
  325. position: relative;
  326. .bgimg {
  327. width: 100%;
  328. height: 100%;
  329. // background-color: pink;
  330. image {
  331. width: 100%;
  332. height: 100%;
  333. }
  334. }
  335. .tki-qrcode-canvas {
  336. width: 750rpx;
  337. height: 1350rpx;
  338. margin: 0 auto;
  339. // background-color: pink;
  340. }
  341. .box {
  342. // position: absolute;
  343. // left: 0;
  344. // top: 0;
  345. // background-color: pink;
  346. // width: 100%;
  347. // height: 100%;
  348. // display: flex;
  349. // flex-direction: column;
  350. // align-items: center;
  351. // color: #FFFFFF;
  352. // padding: 0rpx 32rpx 0 32rpx;
  353. color: #ffffff;
  354. width: 100%;
  355. height: 100vh;
  356. // background-color: pink;
  357. .music {
  358. // width: 55rpx;
  359. // height: 55rpx;
  360. border-radius: 28rpx;
  361. // background-color: pink;
  362. position: absolute;
  363. left: 40rpx;
  364. top: 100rpx;
  365. z-index: 999;
  366. }
  367. // .title {
  368. // margin-top: 234rpx;
  369. // font-size: 54rpx;
  370. // }
  371. // .main {
  372. // margin-top: 20rpx;
  373. // font-size: 32rpx;
  374. // .box-2 {
  375. // text-indent: 68rpx;
  376. // margin-top: 12rpx;
  377. // }
  378. // }
  379. // .footer {
  380. // margin-top: 32rpx;
  381. // // background-color: pink;
  382. // width: 100%;
  383. // .box-1 {
  384. // display: flex;
  385. // justify-content: flex-end;
  386. // font-size: 28rpx;
  387. // // padding-right: 14rpx;
  388. // }
  389. // }
  390. }
  391. // .playing {
  392. // animation: run 10s linear 0s infinite;
  393. // }
  394. // .player {
  395. // width: 65rpx;
  396. // height: 65rpx;
  397. // border-radius: 50%;
  398. // background-color: rgba(0, 0, 0, 0.1);
  399. // z-index: 999999;
  400. // }
  401. .keepgo {
  402. animation-play-state: paused;
  403. }
  404. .imgbox {
  405. height: 1350rpx;
  406. width: 750rpx;
  407. }
  408. }
  409. .image {
  410. width: 100%;
  411. height: 100%;
  412. }
  413. </style>