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

350 lines
7.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
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. <button class='zfbtn m_l' @tap='saveAvatar()'>
  7. 保存头像
  8. </button>
  9. <image :src="info.avatar" mode="aspectFill"></image>
  10. <tki-qrcode v-if="info.avatar" ref="qrcode" @result="qrR" :val="checkArea" :size="115" unit="px" background="#fff"
  11. foreground="#000" pdground="#000" :onval="true" :loadMake="true" :icon="info.avatar" />
  12. <tki-qrcode v-else ref="qrcode" @result="qrR" :val="checkArea" :size="115" unit="px" background="#fff"
  13. foreground="#000" pdground="#000" :onval="true" :loadMake="true" :icon="require('@/static/images/system/payfail.png')" />
  14. <view class="canvas-box">
  15. <canvas style="width: 375px;height: 667px;position:fixed;top:9999px" canvas-id="mycanvas" />
  16. </view>
  17. <view class='imagePathBox' v-if="maskHidden == true && imagePath" @click="maskHidden = false ">
  18. <image :src="imagePath" class='shengcheng' mode="aspectFill"></image>
  19. <button class='baocun' @click.stop="saveBill()">保存相册分享到朋友圈</button>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import tkiQrcode from "tki-qrcode"; // 二维码生成器
  25. export default {
  26. components: {
  27. tkiQrcode
  28. },
  29. data() {
  30. return {
  31. base64Img: '',
  32. checkArea: 'Cannot find module',
  33. inputValue: "",
  34. maskHidden: false,
  35. name: "kk",
  36. info: {
  37. avatar: '',
  38. nickname: '',
  39. id: '',
  40. tel: '',
  41. tags: []
  42. },
  43. showLogin: true,
  44. imagePath: '',
  45. userToken: ''
  46. }
  47. },
  48. methods: {
  49. saveAvatar() {
  50. var that = this
  51. console.log(that.info.avatar)
  52. wx.saveImageToPhotosAlbum({
  53. filePath: that.info.avatar,
  54. success(res) {
  55. wx.showModal({
  56. content: '图片已保存到相册,赶紧晒一下吧~',
  57. showCancel: false,
  58. confirmText: '好的',
  59. confirmColor: '#333',
  60. success: function(res) {
  61. if (res.confirm) {
  62. console.log('用户点击确定');
  63. that.maskHidden = false
  64. }
  65. },
  66. fail: function(res) {
  67. that.maskHidden = false
  68. console.log(res)
  69. }
  70. })
  71. },
  72. fail(err) {
  73. console.log(err)
  74. }
  75. })
  76. },
  77. qrR(data) {
  78. this.base64Img = data;
  79. console.log('base64',this.base64Img)
  80. },
  81. verifyUserInfo() {
  82. let userInfo = uni.getStorageSync('userinfo') || {};
  83. if (!userInfo.id || !userInfo.nickname || !userInfo.avatar) {
  84. if (this.showLogin) {
  85. this.showLogin = false;
  86. this.$url('/pages/login/index?type=userinfo');
  87. } else {
  88. this.showLogin = true;
  89. this.$url('/pages/index/index', {
  90. type: 'switch'
  91. });
  92. }
  93. }
  94. },
  95. getData() {
  96. let userinfo = uni.getStorageSync('userinfo') || {};
  97. if (userinfo) {
  98. this.info = userinfo
  99. console.log('用户数据缓存',this.info)
  100. } else {
  101. this.$http(this.API.API_USER_CENTER).then(res => {
  102. this.info = res.data;
  103. console.log('用户数据接口',this.info)
  104. })
  105. }
  106. },
  107. createNewImg() {
  108. var that = this;
  109. var context = wx.createCanvasContext('mycanvas');
  110. var path = "../../static/images/poster-1.jpg";
  111. context.drawImage(path, 0, 0, 375, 667);
  112. //绘制二维码
  113. context.drawImage(that.base64Img, 24, 530,120, 120);
  114. //绘制名字
  115. // context.setFontSize(24);
  116. // context.setFillStyle('#fff');
  117. // context.setTextAlign('center');
  118. // context.fillText(name, 34, 620);
  119. context.stroke();
  120. context.draw();
  121. //将生成好的图片保存到本地,需要延迟一会,绘制期间耗时
  122. setTimeout(function() {
  123. wx.canvasToTempFilePath({
  124. canvasId: 'mycanvas',
  125. success: function(res) {
  126. that.imagePath = res.tempFilePath;
  127. if(that.imagePath) {
  128. that.canvasHidden = true
  129. that.maskHidden = true
  130. }
  131. console.log('海报生成成功')
  132. console.log(res)
  133. console.log('图片链接', that.imagePath)
  134. },
  135. fail: function(res) {
  136. console.log(res);
  137. }
  138. });
  139. }, 200);
  140. },
  141. saveBill() {
  142. var that = this
  143. wx.saveImageToPhotosAlbum({
  144. filePath: that.imagePath,
  145. success(res) {
  146. wx.showModal({
  147. content: '图片已保存到相册,赶紧晒一下吧~',
  148. showCancel: false,
  149. confirmText: '好的',
  150. confirmColor: '#333',
  151. success: function(res) {
  152. if (res.confirm) {
  153. console.log('用户点击确定');
  154. that.maskHidden = false
  155. }
  156. },
  157. fail: function(res) {
  158. that.maskHidden = false
  159. }
  160. })
  161. }
  162. })
  163. },
  164. formSubmit() {
  165. var that = this;
  166. wx.showToast({
  167. title: '生成海报中...',
  168. icon: 'loading',
  169. duration: 1000
  170. });
  171. wx.hideToast()
  172. that.createNewImg()
  173. }
  174. },
  175. onLoad(options) {
  176. this.qrcode = 'dadaa'
  177. this.verifyUserInfo();
  178. this.getData();
  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>
  319. }
  320. </style>