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

317 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('海报生成成功,图片链接', that.imagePath)
  116. },
  117. fail: function(res) {
  118. console.log(res);
  119. }
  120. });
  121. },800);
  122. },
  123. saveBill() {
  124. var that = this
  125. wx.saveImageToPhotosAlbum({
  126. filePath: that.imagePath,
  127. success(res) {
  128. wx.showModal({
  129. content: '图片已保存到相册,赶紧晒一下吧~',
  130. showCancel: false,
  131. confirmText: '好的',
  132. confirmColor: '#333',
  133. success: function(res) {
  134. if (res.confirm) {
  135. console.log('用户点击确定');
  136. that.maskHidden = false
  137. }
  138. },
  139. fail: function(res) {
  140. that.maskHidden = false
  141. }
  142. })
  143. }
  144. })
  145. },
  146. // 点击复制
  147. copy(text) {
  148. uni.setClipboardData({
  149. data: text
  150. });
  151. },
  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>