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

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