瀏覽代碼

feat: add create QRCode

wangyuan 2 年之前
父節點
當前提交
fb827728e1
共有 8 個文件被更改,包括 116 次插入27 次删除
  1. 4 1
      api/document.js
  2. 1 14
      package-lock.json
  3. 37 1
      pages/index/index.js
  4. 8 1
      pages/index/index.wxml
  5. 19 1
      pages/index/index.wxss
  6. 28 4
      pages/myFile/myFile.js
  7. 5 5
      pages/myFile/myFile.wxml
  8. 14 0
      pages/myFile/myFile.wxss

+ 4 - 1
api/document.js

@@ -3,5 +3,8 @@
 import { wxRequest } from './request'
 
 const documentListURL = '/get/document/list'
+const createQRcodeURL = '/create/qrcode'
 
-export const documentList =  (data) => wxRequest(documentListURL, data)
+export const documentList =  (data) => wxRequest(documentListURL, data)
+
+export const createQRcode =  (data) => wxRequest(createQRcodeURL, data)

+ 1 - 14
package-lock.json

@@ -1,19 +1,6 @@
 {
-  "name": "wxmini",
-  "lockfileVersion": 2,
   "requires": true,
-  "packages": {
-    "": {
-      "dependencies": {
-        "@vant/weapp": "^1.10.5"
-      }
-    },
-    "node_modules/@vant/weapp": {
-      "version": "1.10.5",
-      "resolved": "https://registry.npmmirror.com/@vant/weapp/-/weapp-1.10.5.tgz",
-      "integrity": "sha512-bAHp9r0ZiRsOqPOLzQHI/ZvkAlXzol1/TFhM70MyghuxkzJTjcDUd8RIfLkCN3c1MCK/PfBGw2an8/afygftCg=="
-    }
-  },
+  "lockfileVersion": 1,
   "dependencies": {
     "@vant/weapp": {
       "version": "1.10.5",

+ 37 - 1
pages/index/index.js

@@ -1,6 +1,8 @@
 // pages/index/index.js
 import { homePage } from '../../api/index'
 import { userEntityRecharge } from '../../api/charge'
+import { createQRcode } from "../../api/document";
+
 Page({
 
   /**
@@ -15,7 +17,10 @@ Page({
     scanTimer: null,
     scanOverShow: false,
     scanResMsg: '',
-    scanSuccess: true
+    scanSuccess: true,
+    baseStr: 'data:image/jpg;base64,',
+    QRCodeBase64: '',
+    qrcodeDialog: false
   },
 
   /**
@@ -94,6 +99,10 @@ Page({
     })
   },
   handleScanCode () {
+    wx.navigateTo({
+      url: '/pages/exchange/exchange?form=index',
+    })
+    return
     var that = this
     wx.scanCode({
       onlyFromCamera: true,
@@ -175,5 +184,32 @@ Page({
     wx.navigateTo({
       url: '/pages/appointment/appointment?form=index',
     })
+  },
+  handleShowQRCode (e) {
+    var that = this
+    var id = e.currentTarget.dataset.id
+    wx.showLoading({
+      title: '生成中...'
+    })
+    createQRcode({ documentId: id }).then(res => {
+      wx.hideLoading()
+      that.setData({
+        QRCodeBase64: that.data.baseStr + res.data,
+        qrcodeDialog: true
+      })
+    }).catch(e => {
+      wx.hideLoading()
+      wx.showModal({
+        content: e,
+        confirmColor: '#333',
+        showCancel: false
+      })
+    })
+  },
+  handleCloseQRCode (e) {
+    this.setData({
+      qrcodeDialog: false,
+      QRCodeBase64: ''
+    })
   }
 })

+ 8 - 1
pages/index/index.wxml

@@ -57,7 +57,9 @@
                 </view>
                 <view class="p-date">{{item.birthDay}}</view>
               </view>
-              <view class="qrcode"></view>
+              <view class="qrcode" data-id="{{item.documentId}}"  bindtap="handleShowQRCode">
+                <image class="qrcode-item" src="../../imaes/erweima@2x.png"></image>
+              </view>
             </view>
             <view class="file-right check-report">查看报告</view>
           </view>
@@ -69,6 +71,11 @@
   <view class="index-banner">
     <image class="index-img" src="../../imaes/index.jpg"></image>
   </view>
+  <view class="my-dialog" wx:if="{{qrcodeDialog}}" bindtap="handleCloseQRCode">
+    <view class="qr-content">
+      <image class="qr-content" src="{{QRCodeBase64}}"></image>
+    </view>
+  </view>
   <van-overlay show="{{ scanOverShow }}" bind:click="onClickHide">
     <view class="wrapper ittflex">
       <view class="modal" catch:tap="noop">

+ 19 - 1
pages/index/index.wxss

@@ -3,6 +3,7 @@
   width: 100%;
   min-height: 100%;
   background-color: #F7F7F7;
+  position: relative;
 }
 .header {
   width: 100%;
@@ -172,7 +173,10 @@
 .qrcode {
   width: 60rpx;
   height: 60rpx;
-  background: #000000;
+}
+.qrcode-item {
+  width: 60rpx;
+  height: 60rpx;
 }
 .no-data {
   width: 100%;
@@ -279,4 +283,18 @@
   font-size: 26rpx;
   font-weight: 400;
   color: #FFFFFF;
+}
+.my-dialog {
+  width: 100%;
+  height: 100%;
+  position: absolute;
+  top: 0;
+  background-color: rgba(0,0,0,0.3);
+  display: flex;
+  justify-content: center;
+  align-items: center;
+}
+.qr-content {
+  width: 500rpx;
+  height: 500rpx;
 }

+ 28 - 4
pages/myFile/myFile.js

@@ -1,4 +1,4 @@
-import { documentList } from "../../api/document";
+import { documentList, createQRcode } from "../../api/document";
 Page({
 
   /**
@@ -8,7 +8,9 @@ Page({
     qrcodeDialog: false,
     currentPage: 1,
     hasNext: false,
-    fileList: []
+    fileList: [],
+    baseStr: 'data:image/jpg;base64,',
+    QRCodeBase64: ''
   },
 
   /**
@@ -76,9 +78,31 @@ Page({
       url: '/pages/handleFile/handleFile',
     })
   },
-  handleShowQRCode () {
+  handleShowQRCode (e) {
+    var that = this
+    var id = e.currentTarget.dataset.id
+    wx.showLoading({
+      title: '生成中...'
+    })
+    createQRcode({ documentId: id }).then(res => {
+      wx.hideLoading()
+      that.setData({
+        QRCodeBase64: that.data.baseStr + res.data,
+        qrcodeDialog: true
+      })
+    }).catch(e => {
+      wx.hideLoading()
+      wx.showModal({
+        content: e,
+        confirmColor: '#333',
+        showCancel: false
+      })
+    })
+  },
+  handleCloseQRCode () {
     this.setData({
-      qrcodeDialog: true
+      qrcodeDialog: false,
+      QRCodeBase64: ''
     })
   }
 })

+ 5 - 5
pages/myFile/myFile.wxml

@@ -15,7 +15,7 @@
           </view>
           <view class="fu-bottom fu-date">{{item.birthDay}}</view>
         </view>
-        <view class="f-qrcode ittflex" bindtap="handleShowQRCode">
+        <view class="f-qrcode ittflex" data-id="{{item.documentId}}" bindtap="handleShowQRCode">
           <image class="qrcode-item" src="../../imaes/erweima@2x.png"></image>
         </view>
       </view>
@@ -29,10 +29,10 @@
       <view class="handle-btn itt-btn" bindtap="handleAddFile">新建档案</view>
     </view>
   </view>
-  <van-dialog use-slot closeOnClickOverlay showConfirmButton="{{false}}" show="{{ qrcodeDialog }}">
-    <view class="qrcode">
-      <image class="qrcode-src" src="../../imaes/erweima@2x.png" />
+  <view class="my-dialog" wx:if="{{qrcodeDialog}}" bindtap="handleCloseQRCode">
+    <view class="qr-content">
+      <image class="qr-content" src="{{QRCodeBase64}}"></image>
     </view>
-  </van-dialog>
+  </view>
 </view>
 

+ 14 - 0
pages/myFile/myFile.wxss

@@ -127,4 +127,18 @@
 .qrcode-src {
   width: 100%;
   height: 100%;
+}
+.my-dialog {
+  width: 100%;
+  height: 100%;
+  position: absolute;
+  top: 0;
+  background-color: rgba(0,0,0,0.3);
+  display: flex;
+  justify-content: center;
+  align-items: center;
+}
+.qr-content {
+  width: 500rpx;
+  height: 500rpx;
 }