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

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