donaSuccess.vue 9.8 KB

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