donaSuccess.vue 9.7 KB

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