Bläddra i källkod

修复表单多选框、修复审批验证

iZaiZaiA 2 år sedan
förälder
incheckning
7ab3270427

+ 47 - 26
src/components/plugins/table-form/hc-form-checkbox-group.vue

@@ -1,19 +1,20 @@
 <template>
-    <el-checkbox-group :model-value="isModelVal" size="large" @change="checkboxChange">
-        <template v-for="item in datas">
-            <el-checkbox :label="item"/>
+    <div class="ui-checkbox-group" :class="ui">
+        <template v-for="item in checkboxDatas" :key="item.key">
+            <el-checkbox :checked="item.checked" size="large" @change="onCheckboxChange($event, item)">{{item.name}}</el-checkbox>
         </template>
-        <template v-for="item in objs">
-            <el-checkbox :label="item.key">{{item.name}}</el-checkbox>
-        </template>
-    </el-checkbox-group>
+    </div>
 </template>
 
 <script setup>
 import {ref, nextTick, watch} from 'vue'
-import { ElCheckboxGroup, ElCheckbox } from 'element-plus'
-import { isValueNull } from "vue-utils-plus"
+import { ElCheckbox } from 'element-plus'
+import { isNullAll, deepClone, getIndex } from "vue-utils-plus"
 const props = defineProps({
+    ui: {
+        type: String,
+        default: ''
+    },
     datas: {
         type: Array,
         default: () => ([])
@@ -26,10 +27,6 @@ const props = defineProps({
         type: [String,Number],
         default: ''
     },
-    value: {
-        type: [String,Number],
-        default: ''
-    },
     keyname: {
         type: [String,Number],
         default: ''
@@ -37,7 +34,12 @@ const props = defineProps({
 })
 
 //变量
-const isModelVal = ref([])
+const checkboxDatas = ref([])
+
+//渲染完成
+nextTick(() => {
+    setInitDatas(deepClone(props.datas), deepClone(props.objs))
+})
 
 //监听表头
 watch(() => [
@@ -46,33 +48,52 @@ watch(() => [
     setModelVal(val)
 })
 
-//渲染完成
-nextTick(() => {
+//处理初始数据
+const setInitDatas = (datas, objs) => {
+    for (let i = 0; i < datas.length; i++) {
+        objs.push({key: String(datas[i]), name: datas[i]})
+    }
+    checkboxDatas.value = objs
     setModelVal(props.val)
-})
+}
 
 //处理数据
 const setModelVal = (val) => {
-    if (!isValueNull(val)) {
-        let newArr = [], arr = String(val).split(',')
+    const datas = deepClone(checkboxDatas.value)
+    if (!isNullAll(val)) {
+        const arr = String(val).split(',')
         for (let i = 0; i < arr.length; i++) {
-            newArr.push(Number(arr[i]))
+            const item = String(arr[i])
+            const index = getIndex(datas, 'key', item)
+            datas[index].checked = true
         }
-        isModelVal.value = newArr
-    } else {
-        isModelVal.value = []
     }
+    checkboxDatas.value = datas
 }
 
 //事件
 const emit = defineEmits(['change'])
 
 //当绑定值变化时触发的事件
-const checkboxChange = (arr) => {
-    isModelVal.value = arr
+const onCheckboxChange = (val, item) => {
+    item.checked = val
+    getCheckedValue()
+}
+
+//取选中的值
+const getCheckedValue = () => {
+    let valString = '';
+    const datas = checkboxDatas.value
+    for (let i = 0; i < datas.length; i++) {
+        if (datas[i].checked) {
+            const key = String(datas[i].key)
+            valString = valString ? `${valString},${key}`: key
+        }
+    }
+    //事件返回
     emit('change', {
         key: props.keyname,
-        val: arr.join()
+        val: valString
     })
 }
 </script>

+ 1 - 1
src/plugins/HTableForm.js

@@ -79,7 +79,7 @@ export default class HTableForm {
                     })
                 },
                 //多选框处理
-                checkboxGroupChange({val, key}) {
+                checkboxGroupChange({key, val}) {
                     this.formData[key] = val
                 }
             }

+ 2 - 2
src/views/tasks/hc-data.vue

@@ -233,10 +233,10 @@ const ConfirmApprovalClick = async () => {
         window?.$message?.warning('请先输入审核意见')
     } else {
         SMSAuthLoading.value = true
-        const {error, code, msg} = await checkFlowUserIsExistPfxFile()
+        const {error, code, msg, data} = await checkFlowUserIsExistPfxFile()
         //判断数据
         SMSAuthLoading.value = false
-        if (!error && code === 200) {
+        if (!error && code === 200 && data === true) {
             const ShowAuth = isCheckSmsCodeTime()
             SMSAuthShow.value = ShowAuth
             //免短信验证