时空网前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

346 lines
7.2 KiB

  1. <template>
  2. <view>
  3. <view class="flex justify-center lf-m-t-20">
  4. <!-- <image src="../../static/images/bill.png" mode="widthFix" style="height: 1220rpx;width: 686rpx;"></image> -->
  5. <image v-if="imagePath" :src="imagePath" mode="widthFix"></image>
  6. </view>
  7. <tki-qrcode v-if="info.avatar" style="visibility: hidden;position: fixed;left: -500rpx;" ref="qrcode" @result="qrR" :val="checkArea" :size="115" unit="px" background="#fff"
  8. foreground="#000" pdground="#000" :onval="true" :loadMake="true" :icon="info.avatar" />
  9. <tki-qrcode v-else ref="qrcode" style="visibility: hidden;position: fixed;left: -500rpx;" @result="qrR" :val="checkArea" :size="115" unit="px" background="#fff"
  10. foreground="#000" pdground="#000" :onval="true" :loadMake="true" :icon="require('@/static/images/system/payfail.png')" />
  11. <view class="canvas-box">
  12. <canvas style="width: 375px;height: 667px;position:fixed;top:9999px" canvas-id="mycanvas" />
  13. </view>
  14. <view class="btn-bottom" style="bottom: 40rpx;">
  15. <view class="padding-lr-lg">
  16. <button class="cu-btn block bg-orange lg" style="border-radius: 42rpx;" @tap="saveBill()">
  17. <text class="text-df text-white">保存</text>
  18. </button>
  19. </view>
  20. <view class="flex justify-center align-center lf-m-t-30">
  21. <view class="lf-color-gray lf-font-28">https//hbdsufiewhuifusikj.com</view>
  22. <view class="lf-font-24 text-orange lf-m-l-30" @click="copy('https://hbdsufiewhuifusikj.com')">复制</view>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import tkiQrcode from "tki-qrcode"; // 二维码生成器
  29. export default {
  30. data() {
  31. return {
  32. base64Img: '',
  33. checkArea: 'Cannot find module',
  34. maskHidden: false,
  35. info: {
  36. avatar: '',
  37. nickname: '',
  38. id: '',
  39. tel: '',
  40. tags: []
  41. },
  42. showLogin: true,
  43. imagePath: '',
  44. userToken: ''
  45. }
  46. },
  47. components: {
  48. tkiQrcode
  49. },
  50. onLoad() {
  51. wx.showToast({
  52. title: '生成海报中...',
  53. icon: 'loading',
  54. duration: 1000
  55. });
  56. this.getData();
  57. this.createNewImg();
  58. },
  59. methods:{
  60. //保存头像
  61. saveAvatar() {
  62. var that = this
  63. console.log(that.info.avatar)
  64. wx.saveImageToPhotosAlbum({
  65. filePath: that.info.avatar,
  66. success(res) {
  67. wx.showModal({
  68. content: '图片已保存到相册,赶紧晒一下吧~',
  69. showCancel: false,
  70. confirmText: '好的',
  71. confirmColor: '#333',
  72. success: function(res) {
  73. if (res.confirm) {
  74. console.log('用户点击确定');
  75. that.maskHidden = false
  76. }
  77. },
  78. fail: function(res) {
  79. that.maskHidden = false
  80. console.log(res)
  81. }
  82. })
  83. },
  84. fail(err) {
  85. console.log(err)
  86. }
  87. })
  88. },
  89. qrR(data) {
  90. this.base64Img = data;
  91. console.log('base64',this.base64Img)
  92. },
  93. getData() {
  94. let userinfo = uni.getStorageSync('userinfo') || {};
  95. if (userinfo) {
  96. this.info = userinfo
  97. console.log('用户数据缓存',this.info)
  98. } else {
  99. this.$http(this.API.API_USER_CENTER).then(res => {
  100. this.info = res.data;
  101. console.log('用户数据接口',this.info)
  102. })
  103. }
  104. },
  105. createNewImg() {
  106. var that = this;
  107. var context = wx.createCanvasContext('mycanvas');
  108. var path = "../../static/images/bill.png";
  109. context.drawImage(path, 0, 0, 375, 667);
  110. //绘制二维码
  111. var path1 = "../../static/logo.png";
  112. context.drawImage(path1, 24, 530,120, 120);
  113. //绘制名字
  114. // context.setFontSize(24);
  115. // context.setFillStyle('#fff');
  116. // context.setTextAlign('center');
  117. // context.fillText(name, 34, 620);
  118. context.stroke();
  119. context.draw();
  120. //将生成好的图片保存到本地,需要延迟一会,绘制期间耗时
  121. setTimeout(function() {
  122. wx.canvasToTempFilePath({
  123. canvasId: 'mycanvas',
  124. success: function(res) {
  125. that.imagePath = res.tempFilePath;
  126. if(that.imagePath) {
  127. that.canvasHidden = true
  128. that.maskHidden = true
  129. }
  130. console.log('海报生成成功')
  131. console.log(res)
  132. console.log('图片链接', that.imagePath)
  133. },
  134. fail: function(res) {
  135. console.log(res);
  136. }
  137. });
  138. }, 900);
  139. },
  140. saveBill() {
  141. var that = this
  142. wx.saveImageToPhotosAlbum({
  143. filePath: that.imagePath,
  144. success(res) {
  145. wx.showModal({
  146. content: '图片已保存到相册,赶紧晒一下吧~',
  147. showCancel: false,
  148. confirmText: '好的',
  149. confirmColor: '#333',
  150. success: function(res) {
  151. if (res.confirm) {
  152. console.log('用户点击确定');
  153. that.maskHidden = false
  154. }
  155. },
  156. fail: function(res) {
  157. that.maskHidden = false
  158. }
  159. })
  160. }
  161. })
  162. },
  163. formSubmit() {
  164. var that = this;
  165. wx.showToast({
  166. title: '生成海报中...',
  167. icon: 'loading',
  168. duration: 1000
  169. });
  170. wx.hideToast()
  171. that.createNewImg()
  172. },
  173. // 点击复制
  174. copy(text) {
  175. uni.setClipboardData({
  176. data: text
  177. });
  178. },
  179. }
  180. }
  181. </script>
  182. <style>
  183. .bgImg {
  184. display: block;
  185. width: 100%;
  186. height: 366rpx;
  187. }
  188. .mine {
  189. display: block;
  190. text-align: center;
  191. color: #333;
  192. margin-top: 44rpx;
  193. }
  194. .code {
  195. display: block;
  196. text-align: center;
  197. color: #333;
  198. font-size: 76rpx;
  199. font-weight: bold;
  200. margin-top: 30rpx;
  201. }
  202. .who {
  203. display: block;
  204. margin-top: 80rpx;
  205. font-size: 32rpx;
  206. color: #333;
  207. text-align: center;
  208. }
  209. .inputBox {
  210. text-align: center;
  211. margin-top: 44rpx;
  212. }
  213. .input {
  214. text-align: center;
  215. width: 440rpx;
  216. height: 88rpx;
  217. border-radius: 44rpx;
  218. background: #f5f5f5;
  219. font-size: 32rpx;
  220. display: inline-block;
  221. }
  222. .btn {
  223. width: 160rpx;
  224. height: 88rpx;
  225. border-radius: 44rpx;
  226. background: linear-gradient(90deg, rgba(255, 226, 0, 1), rgba(255, 200, 11, 1));
  227. box-shadow: 0px 4px 8px 0px rgba(255, 200, 11, 0.5);
  228. color: #333;
  229. font-size: 32rpx;
  230. display: inline-block;
  231. line-height: 88rpx;
  232. margin-left: 40rpx;
  233. }
  234. button[class="btn"]::after {
  235. border: 0;
  236. }
  237. .tishi {
  238. display: block;
  239. text-align: center;
  240. color: #999;
  241. margin-top: 30rpx;
  242. }
  243. .shareText {
  244. display: block;
  245. text-align: center;
  246. color: #333;
  247. font-size: 28rpx;
  248. margin-top: 100rpx;
  249. }
  250. .imgBox {
  251. text-align: center;
  252. width: 100%;
  253. margin-top: 60rpx;
  254. padding-bottom: 120rpx;
  255. }
  256. .img {
  257. display: inline-block;
  258. width: 100%;
  259. height: 100%;
  260. }
  261. .m_l {
  262. margin-left: 180rpx;
  263. }
  264. .zfbtn {
  265. display: inline-block;
  266. width: 120rpx;
  267. height: 120rpx;
  268. border-radius: 50%;
  269. background: transparent;
  270. outline: none;
  271. border: 0;
  272. padding: 0;
  273. }
  274. button[class="zfbtn"]::after {
  275. border: 0;
  276. }
  277. button[class="zfbtn m_l"]::after {
  278. border: 0;
  279. }
  280. .imagePathBox {
  281. width: 100%;
  282. height: 100%;
  283. background: rgba(0, 0, 0, 0.7);
  284. position: fixed;
  285. top: 0;
  286. left: 0;
  287. right: 0;
  288. bottom: 0;
  289. z-index: 10;
  290. }
  291. .shengcheng {
  292. width: 80%;
  293. height: 80%;
  294. position: fixed;
  295. top: 50rpx;
  296. left: 50%;
  297. margin-left: -40%;
  298. z-index: 10;
  299. }
  300. .baocun {
  301. display: block;
  302. width: 80%;
  303. height: 80rpx;
  304. padding: 0;
  305. line-height: 80rpx;
  306. text-align: center;
  307. position: fixed;
  308. bottom: 50rpx;
  309. left: 10%;
  310. background: #ffe200;
  311. color: #333;
  312. font-size: 32rpx;
  313. border-radius: 44rpx;
  314. }
  315. button[class="baocun"]::after {
  316. border: 0;
  317. }
  318. </style>