thank.vue 9.6 KB

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