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

318 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=home&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. console.log(this.onceCode)
  83. this.createNewImg()
  84. }
  85. },
  86. fail: err => {
  87. console.log(err)
  88. }
  89. })
  90. },
  91. createNewImg() {
  92. var that = this;
  93. var context = wx.createCanvasContext('mycanvas');
  94. var path = "../../static/images/bill.png";
  95. context.drawImage(path, 0, 0, 375, 667);
  96. //绘制二维码
  97. let wxcode = that.onceCode
  98. context.drawImage(wxcode, 18, 530, 120, 120);
  99. //绘制名字
  100. // context.setFontSize(24);
  101. // context.setFillStyle('#fff');
  102. // context.setTextAlign('center');
  103. // context.fillText(name, 34, 620);
  104. context.stroke();
  105. context.draw();
  106. //将生成好的图片保存到本地,需要延迟一会,绘制期间耗时
  107. setTimeout(function() {
  108. wx.canvasToTempFilePath({
  109. canvasId: 'mycanvas',
  110. success: function(res) {
  111. that.imagePath = res.tempFilePath;
  112. if(that.imagePath) {
  113. that.canvasHidden = true
  114. that.maskHidden = true
  115. }
  116. console.log('海报生成成功,图片链接', that.imagePath)
  117. },
  118. fail: function(res) {
  119. console.log(res);
  120. }
  121. });
  122. },900);
  123. },
  124. saveBill() {
  125. var that = this
  126. wx.saveImageToPhotosAlbum({
  127. filePath: that.imagePath,
  128. success(res) {
  129. wx.showModal({
  130. content: '图片已保存到相册,赶紧晒一下吧~',
  131. showCancel: false,
  132. confirmText: '好的',
  133. confirmColor: '#333',
  134. success: function(res) {
  135. if (res.confirm) {
  136. console.log('用户点击确定');
  137. that.maskHidden = false
  138. }
  139. },
  140. fail: function(res) {
  141. that.maskHidden = false
  142. }
  143. })
  144. }
  145. })
  146. },
  147. // 点击复制
  148. copy(text) {
  149. uni.setClipboardData({
  150. data: text
  151. });
  152. },
  153. }
  154. }
  155. </script>
  156. <style>
  157. .bgImg {
  158. display: block;
  159. width: 100%;
  160. height: 366rpx;
  161. }
  162. .mine {
  163. display: block;
  164. text-align: center;
  165. color: #333;
  166. margin-top: 44rpx;
  167. }
  168. .code {
  169. display: block;
  170. text-align: center;
  171. color: #333;
  172. font-size: 76rpx;
  173. font-weight: bold;
  174. margin-top: 30rpx;
  175. }
  176. .who {
  177. display: block;
  178. margin-top: 80rpx;
  179. font-size: 32rpx;
  180. color: #333;
  181. text-align: center;
  182. }
  183. .inputBox {
  184. text-align: center;
  185. margin-top: 44rpx;
  186. }
  187. .input {
  188. text-align: center;
  189. width: 440rpx;
  190. height: 88rpx;
  191. border-radius: 44rpx;
  192. background: #f5f5f5;
  193. font-size: 32rpx;
  194. display: inline-block;
  195. }
  196. .btn {
  197. width: 160rpx;
  198. height: 88rpx;
  199. border-radius: 44rpx;
  200. background: linear-gradient(90deg, rgba(255, 226, 0, 1), rgba(255, 200, 11, 1));
  201. box-shadow: 0px 4px 8px 0px rgba(255, 200, 11, 0.5);
  202. color: #333;
  203. font-size: 32rpx;
  204. display: inline-block;
  205. line-height: 88rpx;
  206. margin-left: 40rpx;
  207. }
  208. button[class="btn"]::after {
  209. border: 0;
  210. }
  211. .tishi {
  212. display: block;
  213. text-align: center;
  214. color: #999;
  215. margin-top: 30rpx;
  216. }
  217. .shareText {
  218. display: block;
  219. text-align: center;
  220. color: #333;
  221. font-size: 28rpx;
  222. margin-top: 100rpx;
  223. }
  224. .imgBox {
  225. text-align: center;
  226. width: 100%;
  227. margin-top: 60rpx;
  228. padding-bottom: 120rpx;
  229. }
  230. .img {
  231. display: inline-block;
  232. width: 100%;
  233. height: 100%;
  234. }
  235. .m_l {
  236. margin-left: 180rpx;
  237. }
  238. .zfbtn {
  239. display: inline-block;
  240. width: 120rpx;
  241. height: 120rpx;
  242. border-radius: 50%;
  243. background: transparent;
  244. outline: none;
  245. border: 0;
  246. padding: 0;
  247. }
  248. button[class="zfbtn"]::after {
  249. border: 0;
  250. }
  251. button[class="zfbtn m_l"]::after {
  252. border: 0;
  253. }
  254. .imagePathBox {
  255. width: 100%;
  256. height: 100%;
  257. background: rgba(0, 0, 0, 0.7);
  258. position: fixed;
  259. top: 0;
  260. left: 0;
  261. right: 0;
  262. bottom: 0;
  263. z-index: 10;
  264. }
  265. .shengcheng {
  266. width: 80%;
  267. height: 80%;
  268. position: fixed;
  269. top: 50rpx;
  270. left: 50%;
  271. margin-left: -40%;
  272. z-index: 10;
  273. }
  274. .baocun {
  275. display: block;
  276. width: 80%;
  277. height: 80rpx;
  278. padding: 0;
  279. line-height: 80rpx;
  280. text-align: center;
  281. position: fixed;
  282. bottom: 50rpx;
  283. left: 10%;
  284. background: #ffe200;
  285. color: #333;
  286. font-size: 32rpx;
  287. border-radius: 44rpx;
  288. }
  289. button[class="baocun"]::after {
  290. border: 0;
  291. }
  292. </style>