Browse Source

feature/excel限制提示

dengrui 1 year ago
parent
commit
e6ca434348
3 changed files with 49 additions and 2 deletions
  1. 45 1
      src/components/ExcelView/index.vue
  2. 0 1
      src/main.ts
  3. 4 0
      src/views/pro-steps/components/excel.vue

+ 45 - 1
src/components/ExcelView/index.vue

@@ -20,7 +20,7 @@
           class="in"
           v-if="option.in"
         >
-<!--          <template #trigger>
+          <!--          <template #trigger>
             <span class="btn">导入</span>
           </template>-->
         </el-upload>
@@ -67,6 +67,16 @@ const props = defineProps({
       inName: "",
     }),
   },
+  //校验区域
+  verifications: {
+    type: Array,
+    default: () => [],
+  },
+  //校验状态
+  checkStatus: {
+    type: Boolean,
+    default: false,
+  },
 });
 //update:data : v-model表格data ,confirm : 获取此时表格data
 const emits = defineEmits(["update:data", "confirm"]);
@@ -204,6 +214,29 @@ const saveCellData = () => {
   };
   enter();
 };
+//配置单元格校验
+const setVerification = () => {
+  for (let i = 0; i < props.verifications.length; i++) {
+    if (
+      !props.verifications[i].checkStr ||
+      props.verifications[i].checkStr === ""
+    ) {
+    } else {
+      let option = {
+        type: "number",
+        type2: "bw",
+        value1: JSON.parse(props.verifications[i].checkStr).down,
+        value2: JSON.parse(props.verifications[i].checkStr).up,
+        hintShow: true,
+        hintText: `请输入${JSON.parse(props.verifications[i].checkStr).down}-${JSON.parse(props.verifications[i].checkStr).up}的数字`,
+      };
+      luckysheet.setDataVerification(
+        { ...option },
+        { range: props.verifications[i].position }
+      );
+    }
+  }
+};
 defineExpose({ confirm, reset, saveCellData, getData });
 onMounted(() => {
   if (props.data == null) {
@@ -218,6 +251,17 @@ onMounted(() => {
   }
   luckysheet.create(resetOb.value);
 });
+watch(
+  () => props.verifications,
+  () => {
+    nextTick(() => {
+      if (props.checkStatus == true && props.verifications.length > 0) {
+        setVerification();
+      }
+    });
+  },
+  { immediate: true }
+);
 </script>
 
 <style lang="scss" scoped>

+ 0 - 1
src/main.ts

@@ -44,4 +44,3 @@ setupPermission();
 
 setupEleAvue(app);
 app.use(Loading).use(print).use(router).mount("#app");
-console.log(222);

+ 4 - 0
src/views/pro-steps/components/excel.vue

@@ -69,6 +69,8 @@
         v-model:data="excelData"
         :option="excelOptions"
         ref="excelViewRef"
+        :checkStatus="true"
+        :verifications="setting"
       />
     </div>
     <div class="opeara">
@@ -94,6 +96,7 @@ defineOptions({
 import { getExcelData, setExcelData } from "@/api/prosteps/excel";
 import { useProcessStore } from "@/store";
 import { useDictionaryStore } from "@/store";
+const setting = ref([]);
 const dictS = useDictionaryStore();
 const store = useProcessStore();
 const tableData = ref([]);
@@ -156,6 +159,7 @@ const useExcelHook = () => {
     }
     excelOptions.value.inName = row.formName;
     excelViewStatus.value = true;
+    setting.value = row.settings;
   };
   const handleLook = (row) => {
     excelOptions.value.edit = false;