thank.vue 10 KB

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