Skip to content

Commit 37964e7

Browse files
committed
feat: 审批签名代码评审
1 parent 8e5271a commit 37964e7

File tree

5 files changed

+42
-44
lines changed

5 files changed

+42
-44
lines changed

src/api/bpm/processInstance/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export type ApprovalTaskInfo = {
3636
assigneeUser: User
3737
status: number
3838
reason: string
39-
sign: string // TODO @lesan:字段改成 signPicUrl 签名照片。只有 sign 感觉是签名文本哈。
39+
signPicUrl: string
4040
}
4141

4242
// 审批节点信息

src/utils/download.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,33 @@ const download = {
6565
a.download = 'image.png'
6666
a.click()
6767
}
68+
},
69+
base64ToFile: (base64, fileName) => {
70+
// 将base64按照 , 进行分割 将前缀 与后续内容分隔开
71+
const data = base64.split(',')
72+
// 利用正则表达式 从前缀中获取图片的类型信息(image/png、image/jpeg、image/webp等)
73+
const type = data[0].match(/:(.*?);/)[1]
74+
// 从图片的类型信息中 获取具体的文件格式后缀(png、jpeg、webp)
75+
const suffix = type.split('/')[1]
76+
// 使用atob()对base64数据进行解码 结果是一个文件数据流 以字符串的格式输出
77+
const bstr = window.atob(data[1])
78+
// 获取解码结果字符串的长度
79+
let n = bstr.length
80+
// 根据解码结果字符串的长度创建一个等长的整形数字数组
81+
// 但在创建时 所有元素初始值都为 0
82+
const u8arr = new Uint8Array(n)
83+
// 将整形数组的每个元素填充为解码结果字符串对应位置字符的UTF-16 编码单元
84+
while (n--) {
85+
// charCodeAt():获取给定索引处字符对应的 UTF-16 代码单元
86+
u8arr[n] = bstr.charCodeAt(n)
87+
}
88+
// 利用构造函数创建File文件对象
89+
// new File(bits, name, options)
90+
const file = new File([u8arr], `${fileName}.${suffix}`, {
91+
type: type
92+
})
93+
// 将File文件对象返回给方法的调用者
94+
return file
6895
}
6996
}
7097

src/views/bpm/processInstance/detail/ProcessInstanceOperationButton.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@
4747
<el-form-item
4848
v-if="runningTask.signEnable"
4949
label="签名"
50-
prop="sign"
50+
prop="signPicUrl"
5151
ref="approveSignFormRef"
5252
>
5353
<el-button @click="signRef.open()">点击签名</el-button>
5454
<el-image
5555
class="w-90px h-40px ml-5px"
56-
v-if="approveReasonForm.sign"
57-
:src="approveReasonForm.sign"
58-
:preview-src-list="[approveReasonForm.sign]"
56+
v-if="approveReasonForm.signPicUrl"
57+
:src="approveReasonForm.signPicUrl"
58+
:preview-src-list="[approveReasonForm.signPicUrl]"
5959
/>
6060
</el-form-item>
6161
<el-form-item>
@@ -553,11 +553,11 @@ const signRef = ref()
553553
const approveSignFormRef = ref()
554554
const approveReasonForm = reactive({
555555
reason: '',
556-
sign: ''
556+
signPicUrl: ''
557557
})
558558
const approveReasonRule = reactive<FormRules<typeof approveReasonForm>>({
559559
reason: [{ required: true, message: '审批意见不能为空', trigger: 'blur' }],
560-
sign: [{ required: true, message: '签名不能为空', trigger: 'change' }]
560+
signPicUrl: [{ required: true, message: '签名不能为空', trigger: 'change' }]
561561
})
562562
// 拒绝表单
563563
const rejectFormRef = ref<FormInstance>()
@@ -705,7 +705,7 @@ const handleAudit = async (pass: boolean, formRef: FormInstance | undefined) =>
705705
}
706706
// 签名
707707
if (runningTask.value.signEnable) {
708-
data.sign = approveReasonForm.sign
708+
data.signPicUrl = approveReasonForm.signPicUrl
709709
}
710710
// 多表单处理,并且有额外的 approveForm 表单,需要校验 + 拼接到 data 表单里提交
711711
// TODO 芋艿 任务有多表单这里要如何处理,会和可编辑的字段冲突
@@ -1002,7 +1002,7 @@ const getUpdatedProcessInstanceVariables = () => {
10021002
10031003
/** 处理签名完成 */
10041004
const handleSignFinish = (url: string) => {
1005-
approveReasonForm.sign = url
1005+
approveReasonForm.signPicUrl = url
10061006
approveSignFormRef.value.validate('change')
10071007
}
10081008

src/views/bpm/processInstance/detail/ProcessInstanceTimeline.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@
124124
审批意见:{{ task.reason }}
125125
</div>
126126
<div
127-
v-if="task.sign && activity.nodeType === NodeType.USER_TASK_NODE"
127+
v-if="task.signPicUrl && activity.nodeType === NodeType.USER_TASK_NODE"
128128
class="text-#a5a5a5 text-13px mt-1 w-full bg-#f8f8fa p2 rounded-md"
129129
>
130130
签名:
131131
<el-image
132132
class="w-90px h-40px ml-5px"
133-
:src="task.sign"
134-
:preview-src-list="[task.sign]"
133+
:src="task.signPicUrl"
134+
:preview-src-list="[task.signPicUrl]"
135135
/>
136136
</div>
137137
</teleport>

src/views/bpm/processInstance/detail/SignDialog.vue

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
<el-dialog v-model="signDialogVisible" title="签名" width="935">
33
<div class="position-relative">
44
<Vue3Signature class="b b-solid b-gray" ref="signature" w="900px" h="400px" />
5-
<!-- @lesan:建议改成 unocss 哈 -->
65
<el-button
7-
style="position: absolute; bottom: 20px; right: 10px"
6+
class="pos-absolute bottom-20px right-10px"
87
type="primary"
98
text
109
size="small"
@@ -26,6 +25,7 @@
2625
<script setup lang="ts">
2726
import Vue3Signature from 'vue3-signature'
2827
import * as FileApi from '@/api/infra/file'
28+
import download from '@/utils/download'
2929
3030
const message = useMessage() // 消息弹窗
3131
const signDialogVisible = ref(false)
@@ -40,40 +40,11 @@ const emits = defineEmits(['success'])
4040
const submit = async () => {
4141
message.success('签名上传中请稍等。。。')
4242
const res = await FileApi.updateFile({
43-
file: base64ToFile(signature.value.save('image/png'), '签名')
43+
file: download.base64ToFile(signature.value.save('image/png'), '签名')
4444
})
4545
emits('success', res.data)
4646
signDialogVisible.value = false
4747
}
48-
49-
// TODO @lesan:这个要不抽到 download.js 里,让这个组件更简洁干净?
50-
const base64ToFile = (base64, fileName) => {
51-
// 将base64按照 , 进行分割 将前缀 与后续内容分隔开
52-
let data = base64.split(',')
53-
// 利用正则表达式 从前缀中获取图片的类型信息(image/png、image/jpeg、image/webp等)
54-
let type = data[0].match(/:(.*?);/)[1]
55-
// 从图片的类型信息中 获取具体的文件格式后缀(png、jpeg、webp)
56-
let suffix = type.split('/')[1]
57-
// 使用atob()对base64数据进行解码 结果是一个文件数据流 以字符串的格式输出
58-
const bstr = window.atob(data[1])
59-
// 获取解码结果字符串的长度
60-
let n = bstr.length
61-
// 根据解码结果字符串的长度创建一个等长的整形数字数组
62-
// 但在创建时 所有元素初始值都为 0
63-
const u8arr = new Uint8Array(n)
64-
// 将整形数组的每个元素填充为解码结果字符串对应位置字符的UTF-16 编码单元
65-
while (n--) {
66-
// charCodeAt():获取给定索引处字符对应的 UTF-16 代码单元
67-
u8arr[n] = bstr.charCodeAt(n)
68-
}
69-
// 利用构造函数创建File文件对象
70-
// new File(bits, name, options)
71-
const file = new File([u8arr], `${fileName}.${suffix}`, {
72-
type: type
73-
})
74-
// 将File文件对象返回给方法的调用者
75-
return file
76-
}
7748
</script>
7849

7950
<style scoped></style>

0 commit comments

Comments
 (0)