thank.vue 11 KB

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