thank.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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()+1
  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 = '/static/img/zszs.png'; //画布背景
  85. let src = '/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('#000');
  106. // context.fillText('感谢信', ((750 - obj.size) * obj.ratio) / 2, 260 * obj.ratio)
  107. context.setFontSize(40 * obj.ratio);
  108. context.fillText('感谢 ' , 100 * obj.ratio, 460* obj.ratio)
  109. let name = obj.userName
  110. if(name.length <= 12) {
  111. context.fillText(name, 200* obj.ratio, 460* obj.ratio)
  112. }else if(name.length <= 18) {
  113. let name1 = name.slice(0,9)
  114. let name2 = name.slice(9,)
  115. context.fillText(name1, 200* obj.ratio, 434* obj.ratio)
  116. context.setTextAlign('center')
  117. context.fillText(name2, 380* obj.ratio, 483* obj.ratio)
  118. context.setTextAlign('left')
  119. }else if(name.length <= 24) {
  120. let name1 = name.slice(0,12)
  121. let name2 = name.slice(12,)
  122. context.fillText(name1, 200* obj.ratio, 434* obj.ratio)
  123. context.setTextAlign('center')
  124. context.fillText(name2, 438* obj.ratio, 483* obj.ratio)
  125. context.setTextAlign('left')
  126. }else if(name.length <= 30) {
  127. let name1 = name.slice(0,12)
  128. let name2 = name.slice(12,22)
  129. let name3 = name.slice(22,)
  130. context.fillText(name1, 200* obj.ratio, 400* obj.ratio)
  131. context.setTextAlign('center')
  132. context.fillText(name2, 438* obj.ratio, 450* obj.ratio)
  133. context.fillText(name3, 438* obj.ratio, 500* obj.ratio)
  134. context.setTextAlign('left')
  135. }else if(name.length <= 36) {
  136. let name1 = name.slice(0,12)
  137. let name2 = name.slice(12,24)
  138. let name3 = name.slice(24,)
  139. context.fillText(name1, 200* obj.ratio, 400* obj.ratio)
  140. context.setTextAlign('center')
  141. context.fillText(name2, 438* obj.ratio, 450* obj.ratio)
  142. context.fillText(name3, 438* obj.ratio, 500* obj.ratio)
  143. context.setTextAlign('left')
  144. }
  145. context.setFontSize(38 * obj.ratio);
  146. context.fillText("感谢您于" + obj.showtime + "对", 180* obj.ratio, 560* obj.ratio)
  147. let str = '“' + obj.itemName + "”" + '的爱心捐赠。'
  148. if(str.length < 15) {
  149. context.fillText(str ,90* obj.ratio, 615* obj.ratio )
  150. context.setTextAlign('center')
  151. context.fillText('特发此证书,以示感谢!',(750/2)* obj.ratio,695 * obj.ratio)
  152. context.setTextAlign('left')
  153. }else if(str.length < 30) {
  154. if(str.length == 17) {
  155. context.fillText(str ,85* obj.ratio, 615* obj.ratio )
  156. context.setTextAlign('center')
  157. context.fillText('特发此证书,以示感谢!',(750/2)* obj.ratio,695 * obj.ratio)
  158. context.setTextAlign('left')
  159. }else {
  160. let str1 = str.slice(0,16)
  161. let str2 = str.slice(16,)
  162. context.fillText(str1 ,85* obj.ratio, 615* obj.ratio )
  163. context.fillText(str2 ,100* obj.ratio, 670* obj.ratio )
  164. context.setTextAlign('center')
  165. context.fillText('特发此证书,以示感谢!',(750/2)* obj.ratio,750 * obj.ratio)
  166. context.setTextAlign('left')
  167. }
  168. }else if(str.length < 48) {
  169. let str1 = str.slice(0,16)
  170. let str2 = str.slice(16,31)
  171. let str3 = str.slice(31,)
  172. context.fillText(str1 ,85* obj.ratio, 615* obj.ratio )
  173. context.fillText(str2 ,100* obj.ratio, 670* obj.ratio )
  174. context.fillText(str3 ,100* obj.ratio, 725* obj.ratio )
  175. context.setTextAlign('center')
  176. context.fillText('特发此证书,以示感谢!',(750/2)* obj.ratio,805 * obj.ratio)
  177. context.setTextAlign('left')
  178. }else if(str.length < 63) {
  179. let str1 = str.slice(0,16)
  180. let str2 = str.slice(16,31)
  181. let str3 = str.slice(31,46)
  182. let str4 = str.slice(46,)
  183. context.fillText(str1 ,85* obj.ratio, 615* obj.ratio )
  184. context.fillText(str2 ,100* obj.ratio, 670* obj.ratio )
  185. context.fillText(str3 ,100* obj.ratio, 725* obj.ratio )
  186. context.fillText(str4 ,100* obj.ratio, 780* obj.ratio )
  187. context.setTextAlign('center')
  188. context.fillText('特发此证书,以示感谢!',(750/2)* obj.ratio,860 * obj.ratio)
  189. context.setTextAlign('left')
  190. }
  191. context.drawImage(src, 490 * obj.ratio, 1140 * obj.ratio, codeSize, codeSize);
  192. // 生成
  193. context.draw(false, e => {
  194. uni.canvasToTempFilePath({
  195. x: 0,
  196. y: 0,
  197. width: obj.canWeidth,
  198. height: obj.canHeight,
  199. destWidth: obj.canWeidth,
  200. destHeight: obj.canHeight,
  201. canvasId: 'qrShareBox',
  202. success: function(res) {
  203. console.log(333, res);
  204. // 在H5平台下,tempFilePath 为 base64
  205. obj.showcanvas = false;
  206. obj.img = res.tempFilePath;
  207. }
  208. });
  209. });
  210. },
  211. onShow() {
  212. },
  213. onLoad(option) {
  214. this.pid = option.project_id
  215. this.userName = option.name
  216. this.time = option.time
  217. this.itemName = option.title
  218. this.IndexShare()
  219. },
  220. onHide() {
  221. //在页面隐藏时也要清除定时器
  222. if (this.timer) {
  223. // console.log('清除定时器-' + this.timer)
  224. clearInterval(this.timer);
  225. }
  226. },
  227. onUnload() {
  228. },
  229. methods: {
  230. // 分享
  231. IndexShare() {
  232. let obj = this;
  233. let item = {
  234. link: 'http://slj.igxys.com/index/#/pages/user/thank?project_id=' + obj.pid + '&name=' + obj.userName + '&time=' + obj.time + '&title=' + obj.itemName, // 分享链接
  235. imgUrl: 'http://slj.igxys.com/static/img/22.jpg',
  236. desc: '感谢信',
  237. title: '咸宁市红十字会',
  238. success: console.log('分享加载成功')
  239. };
  240. console.log('分享加', item);
  241. weixindata(item);
  242. },
  243. musicClick() {
  244. // if (this.isRoate) {
  245. // this.isRoate = false
  246. // this.stopScanAudio()
  247. // } else {
  248. // this.isRoate = true
  249. // this.ScanAudio()
  250. // }
  251. },
  252. play() {
  253. this.playing = !this.playing;
  254. this.ScanAudio(this.playing);
  255. if (this.playing == true) {
  256. this.timer = setInterval(() => {
  257. //创建定时器,3秒执行异一次
  258. this.scaleAndScale();
  259. console.log('每1秒执行一次');
  260. }, 1000);
  261. } else {
  262. clearInterval(this.timer);
  263. }
  264. // var music = uni.createInnerAudioContext();
  265. // music.src= "../../static/audio/xx.mp3"; //选择播放的音频
  266. // music.onPause(); //暂停播放
  267. // console.log('暂停播放')
  268. // console.log('dianjizanting')
  269. // this.stopAudio()
  270. // this.playing = !this.playing; //背景音乐点击,暂停或继续
  271. },
  272. // 定义动画内容
  273. scaleAndScale() {
  274. // 定义动画内容
  275. // this.animation.scale(1.2, 1.2).step() //先放大1,2倍
  276. // this.animation.scale(1, 1).step() //缩小至原来的大小
  277. // 导出动画数据传递给data层
  278. // this.animationData = this.animation.export(); //每次执行导出动画时 会覆盖之前的动画
  279. this.animation.rotate(this.demo).step({
  280. duration: 1000
  281. });
  282. this.animationData = this.animation.export();
  283. this.demo += 360;
  284. },
  285. noscaleAndScale() {
  286. this.animation.rotate(0).step({
  287. duration: 1000
  288. });
  289. this.animationData = this.animation.export();
  290. }
  291. // ScanAudio(){
  292. // this.$api.music.play(); //执行播放
  293. // console.log('执行播放')
  294. // }
  295. }
  296. };
  297. </script>
  298. <style lang="scss">
  299. page {
  300. width: 100%;
  301. height: 100%;
  302. }
  303. .content {
  304. // background-color: pink;
  305. width: 100%;
  306. // height: 100vh;
  307. position: relative;
  308. // overflow: hidden;
  309. .image {
  310. width: 100%;
  311. height: 100vh;
  312. }
  313. .bgimg {
  314. width: 100%;
  315. height: 100%;
  316. // background-color: pink;
  317. image {
  318. width: 100%;
  319. height: 100%;
  320. }
  321. }
  322. // .tki-qrcode-canvas {
  323. // width: 750rpx;
  324. // height: 100vh;
  325. // margin: 0 auto;
  326. // // background-color: pink;
  327. // }
  328. .box {
  329. color: #ffffff;
  330. width: 100%;
  331. height: 100vh;
  332. .tki-qrcode-canvas {
  333. // width: 700rpx;
  334. // height: 1245rpx;
  335. width: 750rpx;
  336. // padding: 32rpx;
  337. height: 1350rpx;
  338. margin: 0 auto;
  339. }
  340. // background-color: pink;
  341. // .music {
  342. // // width: 55rpx;
  343. // // height: 55rpx;
  344. // border-radius: 28rpx;
  345. // // background-color: pink;
  346. // position: absolute;
  347. // left: 12rpx;
  348. // top: 250rpx;
  349. // z-index: 999;
  350. // }
  351. }
  352. .imgbox {
  353. height: 1334rpx;
  354. width: 750rpx;
  355. }
  356. }
  357. .image {
  358. width: 100%;
  359. height: 100%;
  360. }
  361. </style>