时空网前端
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.

329 lines
7.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <template>
  2. <view>
  3. <view @click="baocun()">保存相册</view>
  4. <button class='zfbtn m_l' @tap='formSubmit()'>
  5. <image src="../../static/center/collect-active.png" class='img'></image>
  6. </button>
  7. <tki-qrcode ref="qrcode" @result="qrR" :val="checkArea" :size="115" unit="px" background="#fff" foreground="#000"
  8. pdground="#000" :onval="true" :loadMake="true" />
  9. <view class="canvas-box">
  10. <canvas style="width: 375px;height: 667px;position:fixed;top:9999px" canvas-id="mycanvas" />
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. const app = getApp()
  16. import tkiQrcode from "tki-qrcode"; // 二维码生成器
  17. export default {
  18. components: {
  19. tkiQrcode
  20. },
  21. data() {
  22. return {
  23. base64Img: '', //
  24. checkArea: '0',
  25. img: "../../static/images/empty.png",
  26. wechat: "../../static/images/tabbar/home.png",
  27. quan: "../../static/images/tabbar/my.png",
  28. touxiang: "../../static/images/system/payfail.png",
  29. inputValue: "",
  30. maskHidden: false,
  31. name: "kk",
  32. code: "E7A93C"
  33. }
  34. },
  35. methods: {
  36. qrR(data) {
  37. this.base64Img = data;
  38. },
  39. createNewImg() {
  40. var that = this;
  41. var context = wx.createCanvasContext('mycanvas');
  42. context.setFillStyle("#ffe200")
  43. context.fillRect(0, 0, 375, 667)
  44. var path = "../../static/images/empty.png";
  45. //将模板图片绘制到canvas,在开发工具中drawImage()函数有问题,不显示图片
  46. //不知道是什么原因,手机环境能正常显示
  47. context.drawImage(path, 0, 0, 375, 183);
  48. var path1 = that.touxiang;
  49. console.log(path1, "path1")
  50. //将模板图片绘制到canvas,在开发工具中drawImage()函数有问题,不显示图片
  51. var path2 = "../../static/images/system/payfail.png";
  52. var path3 = "../../static/images/system/paysuccess.png";
  53. var path4 = "../../static/images/system/paysuccess.png";
  54. var path5 = "../../static/images/system/refresh.png";
  55. context.drawImage(path2, 126, 186, 120, 120);
  56. //不知道是什么原因,手机环境能正常显示
  57. // context.save(); // 保存当前context的状态
  58. var name = that.name;
  59. //绘制名字
  60. context.setFontSize(24);
  61. context.setFillStyle('#333333');
  62. context.setTextAlign('center');
  63. context.fillText(name, 185, 340);
  64. context.stroke();
  65. //绘制一起吃面标语
  66. context.setFontSize(14);
  67. context.setFillStyle('#333333');
  68. context.setTextAlign('center');
  69. context.fillText("邀请你一起去吃面", 185, 370);
  70. context.stroke();
  71. //绘制验证码背景
  72. context.drawImage(path3, 48, 390, 280, 84);
  73. //绘制code码
  74. context.setFontSize(40);
  75. context.setFillStyle('#ffe200');
  76. context.setTextAlign('center');
  77. context.fillText(that.code, 185, 435);
  78. context.stroke();
  79. //绘制左下角文字背景图
  80. context.drawImage(path4, 25, 520, 184, 82);
  81. context.setFontSize(12);
  82. context.setFillStyle('#333');
  83. context.setTextAlign('left');
  84. context.fillText("进入小程序输入朋友的邀请", 35, 540);
  85. context.stroke();
  86. context.setFontSize(12);
  87. context.setFillStyle('#333');
  88. context.setTextAlign('left');
  89. context.fillText("码,朋友和你各自获得通用", 35, 560);
  90. context.stroke();
  91. context.setFontSize(12);
  92. context.setFillStyle('#333');
  93. context.setTextAlign('left');
  94. context.fillText("优惠券1张哦~", 35, 580);
  95. context.stroke();
  96. //绘制右下角扫码提示语
  97. context.drawImage(path5, 248, 578, 90, 25);
  98. //绘制头像
  99. context.arc(186, 246, 50, 0, 2 * Math.PI) //画出圆
  100. context.strokeStyle = "#ffe200";
  101. context.clip(); //裁剪上面的圆形
  102. context.drawImage(path1, 136, 196, 100, 100); // 在刚刚裁剪的园上画图
  103. context.draw();
  104. //将生成好的图片保存到本地,需要延迟一会,绘制期间耗时
  105. setTimeout(function() {
  106. wx.canvasToTempFilePath({
  107. canvasId: 'mycanvas',
  108. success: function(res) {
  109. var tempFilePath = res.tempFilePath;
  110. that.imagePath = tempFilePath
  111. that.canvasHidden = true
  112. console.log('成功')
  113. console.log(res)
  114. },
  115. fail: function(res) {
  116. console.log(res);
  117. }
  118. });
  119. }, 200);
  120. },
  121. baocun() {
  122. var that = this
  123. wx.saveImageToPhotosAlbum({
  124. filePath: that.imagePath,
  125. success(res) {
  126. wx.showModal({
  127. content: '图片已保存到相册,赶紧晒一下吧~',
  128. showCancel: false,
  129. confirmText: '好的',
  130. confirmColor: '#333',
  131. success: function(res) {
  132. if (res.confirm) {
  133. console.log('用户点击确定');
  134. }
  135. },
  136. fail: function(res) {
  137. console.log(11111)
  138. }
  139. })
  140. }
  141. })
  142. },
  143. formSubmit() {
  144. var that = this;
  145. wx.showToast({
  146. title: '装逼中...',
  147. icon: 'loading',
  148. duration: 1000
  149. });
  150. setTimeout(function() {
  151. wx.hideToast()
  152. that.createNewImg();
  153. }, 1000)
  154. }
  155. },
  156. onLoad(options) {
  157. this.qrcode = 'dadaa'
  158. }
  159. }
  160. </script>
  161. <style>
  162. .bgImg {
  163. display: block;
  164. width: 100%;
  165. height: 366rpx;
  166. }
  167. .mine {
  168. display: block;
  169. text-align: center;
  170. color: #333;
  171. margin-top: 44rpx;
  172. }
  173. .code {
  174. display: block;
  175. text-align: center;
  176. color: #333;
  177. font-size: 76rpx;
  178. font-weight: bold;
  179. margin-top: 30rpx;
  180. }
  181. .who {
  182. display: block;
  183. margin-top: 80rpx;
  184. font-size: 32rpx;
  185. color: #333;
  186. text-align: center;
  187. }
  188. .inputBox {
  189. text-align: center;
  190. margin-top: 44rpx;
  191. }
  192. .input {
  193. text-align: center;
  194. width: 440rpx;
  195. height: 88rpx;
  196. border-radius: 44rpx;
  197. background: #f5f5f5;
  198. font-size: 32rpx;
  199. display: inline-block;
  200. }
  201. .btn {
  202. width: 160rpx;
  203. height: 88rpx;
  204. border-radius: 44rpx;
  205. background: linear-gradient(90deg, rgba(255, 226, 0, 1), rgba(255, 200, 11, 1));
  206. box-shadow: 0px 4px 8px 0px rgba(255, 200, 11, 0.5);
  207. color: #333;
  208. font-size: 32rpx;
  209. display: inline-block;
  210. line-height: 88rpx;
  211. margin-left: 40rpx;
  212. }
  213. button[class="btn"]::after {
  214. border: 0;
  215. }
  216. .tishi {
  217. display: block;
  218. text-align: center;
  219. color: #999;
  220. margin-top: 30rpx;
  221. }
  222. .shareText {
  223. display: block;
  224. text-align: center;
  225. color: #333;
  226. font-size: 28rpx;
  227. margin-top: 100rpx;
  228. }
  229. .imgBox {
  230. text-align: center;
  231. width: 100%;
  232. margin-top: 60rpx;
  233. padding-bottom: 120rpx;
  234. }
  235. .img {
  236. display: inline-block;
  237. width: 100%;
  238. height: 100%;
  239. }
  240. .m_l {
  241. margin-left: 180rpx;
  242. }
  243. .zfbtn {
  244. display: inline-block;
  245. width: 120rpx;
  246. height: 120rpx;
  247. border-radius: 50%;
  248. background: transparent;
  249. outline: none;
  250. border: 0;
  251. padding: 0;
  252. }
  253. button[class="zfbtn"]::after {
  254. border: 0;
  255. }
  256. button[class="zfbtn m_l"]::after {
  257. border: 0;
  258. }
  259. .imagePathBox {
  260. width: 100%;
  261. height: 100%;
  262. background: rgba(0, 0, 0, 0.7);
  263. position: fixed;
  264. top: 0;
  265. left: 0;
  266. right: 0;
  267. bottom: 0;
  268. z-index: 10;
  269. }
  270. .shengcheng {
  271. width: 80%;
  272. height: 80%;
  273. position: fixed;
  274. top: 50rpx;
  275. left: 50%;
  276. margin-left: -40%;
  277. z-index: 10;
  278. }
  279. .baocun {
  280. display: block;
  281. width: 80%;
  282. height: 80rpx;
  283. padding: 0;
  284. line-height: 80rpx;
  285. text-align: center;
  286. position: fixed;
  287. bottom: 50rpx;
  288. left: 10%;
  289. background: #ffe200;
  290. color: #333;
  291. font-size: 32rpx;
  292. border-radius: 44rpx;
  293. }
  294. button[class="baocun"]::after {
  295. border: 0;
  296. }
  297. </style>
  298. }
  299. </style>