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

357 lines
7.1 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 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. const app = getApp()
  25. import tkiQrcode from "tki-qrcode"; // 二维码生成器
  26. export default {
  27. components: {
  28. tkiQrcode
  29. },
  30. data() {
  31. return {
  32. base64Img: '',
  33. checkArea: 'Cannot find module',
  34. inputValue: "",
  35. maskHidden: false,
  36. name: "kk",
  37. info: {
  38. avatar: '',
  39. nickname: '',
  40. id: '',
  41. tel: '',
  42. tags: []
  43. },
  44. showLogin: true,
  45. imagePath: '',
  46. userToken: ''
  47. }
  48. },
  49. methods: {
  50. saveAvatar() {
  51. var that = this
  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. // if(that.imagePath) {
  174. // that.maskHidden = true
  175. // }
  176. }
  177. },
  178. onLoad(options) {
  179. this.qrcode = 'dadaa'
  180. this.verifyUserInfo();
  181. this.getData();
  182. }
  183. }
  184. </script>
  185. <style>
  186. .bgImg {
  187. display: block;
  188. width: 100%;
  189. height: 366rpx;
  190. }
  191. .mine {
  192. display: block;
  193. text-align: center;
  194. color: #333;
  195. margin-top: 44rpx;
  196. }
  197. .code {
  198. display: block;
  199. text-align: center;
  200. color: #333;
  201. font-size: 76rpx;
  202. font-weight: bold;
  203. margin-top: 30rpx;
  204. }
  205. .who {
  206. display: block;
  207. margin-top: 80rpx;
  208. font-size: 32rpx;
  209. color: #333;
  210. text-align: center;
  211. }
  212. .inputBox {
  213. text-align: center;
  214. margin-top: 44rpx;
  215. }
  216. .input {
  217. text-align: center;
  218. width: 440rpx;
  219. height: 88rpx;
  220. border-radius: 44rpx;
  221. background: #f5f5f5;
  222. font-size: 32rpx;
  223. display: inline-block;
  224. }
  225. .btn {
  226. width: 160rpx;
  227. height: 88rpx;
  228. border-radius: 44rpx;
  229. background: linear-gradient(90deg, rgba(255, 226, 0, 1), rgba(255, 200, 11, 1));
  230. box-shadow: 0px 4px 8px 0px rgba(255, 200, 11, 0.5);
  231. color: #333;
  232. font-size: 32rpx;
  233. display: inline-block;
  234. line-height: 88rpx;
  235. margin-left: 40rpx;
  236. }
  237. button[class="btn"]::after {
  238. border: 0;
  239. }
  240. .tishi {
  241. display: block;
  242. text-align: center;
  243. color: #999;
  244. margin-top: 30rpx;
  245. }
  246. .shareText {
  247. display: block;
  248. text-align: center;
  249. color: #333;
  250. font-size: 28rpx;
  251. margin-top: 100rpx;
  252. }
  253. .imgBox {
  254. text-align: center;
  255. width: 100%;
  256. margin-top: 60rpx;
  257. padding-bottom: 120rpx;
  258. }
  259. .img {
  260. display: inline-block;
  261. width: 100%;
  262. height: 100%;
  263. }
  264. .m_l {
  265. margin-left: 180rpx;
  266. }
  267. .zfbtn {
  268. display: inline-block;
  269. width: 120rpx;
  270. height: 120rpx;
  271. border-radius: 50%;
  272. background: transparent;
  273. outline: none;
  274. border: 0;
  275. padding: 0;
  276. }
  277. button[class="zfbtn"]::after {
  278. border: 0;
  279. }
  280. button[class="zfbtn m_l"]::after {
  281. border: 0;
  282. }
  283. .imagePathBox {
  284. width: 100%;
  285. height: 100%;
  286. background: rgba(0, 0, 0, 0.7);
  287. position: fixed;
  288. top: 0;
  289. left: 0;
  290. right: 0;
  291. bottom: 0;
  292. z-index: 10;
  293. }
  294. .shengcheng {
  295. width: 80%;
  296. height: 80%;
  297. position: fixed;
  298. top: 50rpx;
  299. left: 50%;
  300. margin-left: -40%;
  301. z-index: 10;
  302. }
  303. .baocun {
  304. display: block;
  305. width: 80%;
  306. height: 80rpx;
  307. padding: 0;
  308. line-height: 80rpx;
  309. text-align: center;
  310. position: fixed;
  311. bottom: 50rpx;
  312. left: 10%;
  313. background: #ffe200;
  314. color: #333;
  315. font-size: 32rpx;
  316. border-radius: 44rpx;
  317. }
  318. button[class="baocun"]::after {
  319. border: 0;
  320. }
  321. </style>
  322. }
  323. </style>