Sfoglia il codice sorgente

实现签名功能及相关API,优化签署流程

yuanmingze 8 mesi fa
parent
commit
dafa52a62e

+ 4 - 4
src/pages-common/signature/components/SignaturePad.vue

@@ -81,18 +81,18 @@ const drawBackground = () => {
   ctx.value.draw()
 }
 
-const onTouchStart = (e: UniApp.TouchEvent) => {
-  const touch = e.touches?.[0]
+const onTouchStart = (e: TouchEvent) => {
+  const touch = (e as any).touches?.[0]
   if (!touch || !ctx.value) return
 
   drawing.value = true
   lastPoint.value = { x: touch.x, y: touch.y }
 }
 
-const onTouchMove = (e: UniApp.TouchEvent) => {
+const onTouchMove = (e: TouchEvent) => {
   if (!drawing.value || !ctx.value || !lastPoint.value) return
 
-  const touch = e.touches?.[0]
+  const touch = (e as any).touches?.[0]
   if (!touch) return
 
   const current = { x: touch.x, y: touch.y }

+ 54 - 5
src/pages-common/signature/index.vue

@@ -7,21 +7,70 @@ import { ref } from 'vue'
 
 import { onLoad } from '@dcloudio/uni-app'
 
+import { signAgreementApi } from '@/services/modules/common'
+import { fileApi } from '@/services/modules/file'
+
+import { useUserStore } from '@/stores/modules/user'
+
 import SignaturePad from './components/SignaturePad.vue'
 
 const type = ref('')
 onLoad((e) => {
-  type.value = e.type || ''
+  type.value = e?.type || ''
 })
 
+const userStore = useUserStore()
 const handleSignatureDone = (filePath: string) => {
-  console.log('Signature done, file path:', filePath)
+  uni.showLoading({
+    title: '保存中',
+  })
 
-  saveSignature(filePath)
+  uni.uploadFile({
+    url: fileApi.fileUpload(),
+    filePath: filePath,
+    name: 'file',
+    header: {
+      Authorization: `Bearer ${userStore.access_token}`,
+    },
+    success(res) {
+      uni.hideLoading()
+      if (res.statusCode === 200 && res.data) {
+        const uploadRes = JSON.parse(res.data)
+        if (uploadRes.code === 0) {
+          if (type.value === 'HONEST_AGREEMENT_V2') {
+            saveSignature(uploadRes.data.url)
+            return
+          }
+        } else {
+          uni.showToast({
+            title: uploadRes.msg || '上传失败',
+            icon: 'none',
+            duration: 1500,
+          })
+        }
+      }
+    },
+    fail() {
+      uni.hideLoading()
+      uni.showToast({
+        title: '上传失败',
+        icon: 'none',
+        duration: 1500,
+      })
+    },
+  })
 }
 
-const saveSignature = (filePath: string) => {
-  console.log('filePath', filePath)
+// 签署协议
+const saveSignature = async (url: string) => {
+  const res = await signAgreementApi({
+    agreementType: type.value,
+    signatureUrl: url,
+  })
+  if (res.code === 0 && res.data) {
+    uni.showTabBar()
+    uni.navigateBack()
+  }
 }
 
 const handleClear = () => {

+ 9 - 0
src/services/modules/common/index.ts

@@ -0,0 +1,9 @@
+import http from '../../index'
+import type { SignAgreementRequest } from './type'
+
+export const signAgreementApi = (data: SignAgreementRequest) => {
+  return http.post<boolean>('/admin/api/sign-agreement', data, {
+    loading: true,
+    loadingText: '签署中...',
+  })
+}

+ 4 - 0
src/services/modules/common/type.d.ts

@@ -0,0 +1,4 @@
+export interface SignAgreementRequest {
+  agreementType: string
+  signatureUrl: string
+}

+ 6 - 0
src/services/modules/file/index.ts

@@ -0,0 +1,6 @@
+export const fileApi = {
+  // 上传文件
+  fileUpload: () => {
+    return `${import.meta.env.VITE_BASE_API}/admin/sys-file/upload`
+  },
+}