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

319 lines
6.2 KiB

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