aixin.vue 11 KB

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