Bläddra i källkod

修改使用字典multy来添加风控配置

wangzhiqiang 5 månader sedan
förälder
incheckning
9810427c26

+ 0 - 85
src/hooks/useGetDictList.js

@@ -1,88 +1,3 @@
-/* import { ref } from 'vue'
-import { getCommonDictList } from '@/api/common'  // 假设这是你的 API 请求
-
-const DICT_CACHE_KEY = 'system_dict_data';
-
-export function useGetDictList() {
-    const dictData = ref({});
-
-    const loadDictData = async () => {
-        const cached = sessionStorage.getItem(DICT_CACHE_KEY);
-        if (cached) {
-            dictData.value = JSON.parse(cached);
-        } else {
-            const res = await getCommonDictList(); // 后端返回字典 JSON
-            dictData.value = res.data;
-            sessionStorage.setItem(DICT_CACHE_KEY, JSON.stringify(res.data));
-        }
-
-        const { uniqueTypes, optionsByType } = dictData.value.reduce((acc, item) => {
-            // 1. 收集唯一的 typeCode + typeName
-            const typeKey = `${item.typeCode}|${item.typeName}`;
-            if (!acc.uniqueTypeKeys.has(typeKey)) {
-                acc.uniqueTypes.push(
-                    {
-                        typeCode: item.typeCode,
-                        typeName: item.typeName
-                        //  dictionaryCode: item.dictionaryCode,
-                        //  dictionaryId: item.dictionaryId,
-                        //  dictionaryName: item.dictionaryName,
-                        //  enabled: item.enabled,
-                        //  sort: item.sort,
-                        //  typeCode: item.typeCode,
-                        //  typeName: item.typeName, 
-                    });
-                acc.uniqueTypeKeys.add(typeKey);
-            }
-
-            // 2. 按 typeCode 分组生成 options
-            if (!acc.optionsByType[item.typeCode]) {
-                acc.optionsByType[item.typeCode] = [];
-            }
-            acc.optionsByType[item.typeCode].push({
-                value: item.dictionaryCode,
-                label: item.dictionaryName
-            });
-
-            return acc;
-        },
-            { uniqueTypes: [], uniqueTypeKeys: new Set(), optionsByType: {} }
-        );
-
-        return uniqueTypes, optionsByType
-    };
-
-
-
-    // 拿到单个的Options
-    function getOptions(name) {
-        const options = dictData.value
-            .filter(item => item.typeCode === name) // 只取启用的项
-            .sort((a, b) => a.sort - b.sort)   // 按 sort 排序
-            .map(item => ({
-                label: item.dictionaryName,
-                value: Number(item.dictionaryCode) // 将字符串"1"/"0"转为数字
-            }));
-        return options
-    }
-
-    const clearDictCache = () => {
-        sessionStorage.removeItem(DICT_CACHE_KEY);
-    };
-
-    return {
-        dictData,//字典原数据
-        loadDictData,//加载字典
-        clearDictCache, //移除字典
-        getOptions,//字典 单个Options
-        // uniqueTypes, //单项字典合集
-        // optionsByType, //字典options合集
-    };
-}
- */
-
-
-
 import { ref } from 'vue'
 import { getCommonDictList } from '@/api/common'
 

+ 1 - 1
src/views/main/agentModule/index.vue

@@ -1,4 +1,4 @@
-<template></template>
+<template>
   <div class="layout-container">
     代理模块
   </div>

+ 26 - 28
src/views/main/riskModule/components/configForm.vue

@@ -59,19 +59,19 @@
                         <el-select :disabled="layer.disabled" v-model="item.multy"
                             @change="handleTypeTwo(index,item.configType,item.multy)"
                             style="width: 140px;margin: 0 10px;" placeholder="请选择" filterable>
-                            <el-option v-if="item.configType === '1'" label="比较" value="3"></el-option>
-                            <el-option v-if="item.configType === '1'" label="不比较" value="4"></el-option>
-                            <template v-else>
-                                <el-option label="单选" value="1"></el-option>
-                                <el-option label="多选" value="2"></el-option>
+                            <template v-if="item.configType === '2' || item.configType === '3'">
+                                <el-option v-for="option in getOptions('multy').slice(0,2)" :key="option.label"
+                                    :label="option.label" :value="option.value"></el-option>
                             </template>
+                            <el-option v-else v-for="option in getOptions('multy')" :key="option.label" :label="option.label"
+                                :value="option.value"></el-option>
                         </el-select>
 
 
                         <!-- 输入框 -->
                         <template v-if="item.configType === '1'">
                             <!-- 比较 -->
-                            <el-input v-if="item.multy === '3'" style="width: 240px;" v-model="item.configVal"
+                            <el-input v-if="item.multy === 1" style="width: 240px;" v-model="item.configVal"
                                 placeholder="如: 100-500" :class="{ 'is-error': item.error_configVal }"
                                 @input="clearFieldError(index, 'configVal')">
                                 <template #prepend>
@@ -91,7 +91,7 @@
 
                         <!-- 选择框 -->
                         <template v-else-if="item.configType === '2'">
-                            <el-select :multiple="item.multy === '2'" v-model="item.configVal" placeholder="请选择"
+                            <el-select :multiple="item.multy === 1" v-model="item.configVal" placeholder="请选择"
                                 style="width: 240px" :class="{ 'is-error': item.error_configVal }"
                                 @input="clearFieldError(index, 'configVal')">
                                 <el-option v-for="option in getOptions(camelToSnake(item.fieldName))"
@@ -102,7 +102,7 @@
                         <!-- 日期 -->
                         <template v-else-if="item.configType === '3'">
                             <div style="width: 240px !important;">
-                                <el-date-picker v-if="item.multy === '1'" v-model="item.configVal" type="date"
+                                <el-date-picker v-if="item.multy === 2" v-model="item.configVal" type="date"
                                     placeholder="请选择" :class="{ 'is-error': item.error_configVal }"
                                     @input="clearFieldError(index, 'configVal')" />
 
@@ -248,7 +248,7 @@
                 return false;
             }
 
-            if (!item.multy && item.multy !== '0') {
+            if (!item.multy && item.multy !== 0) {
                 markFieldError(i, 'multy');
                 scrollToError(i);
                 ElMessage.error(`第 ${i + 1} 条配置的「配置方式」不能为空`);
@@ -336,15 +336,15 @@
     const handleTypeOne = (index, configType) => {
         console.log('选择1变化:', 'index', index, 'configType', configType)
         // configType:1-输入框 2-选择框 3-日期
-        // multy:1-单选 2-多选 3-比较 4-不比较
+        // multy:1-多选 2-单选 3-大于> 4-小于<
 
         configFormList.value.configList[index][`error_configType`] = false;
 
         if (configType === '1') {
-            configFormList.value.configList[index].multy = '4'
+            configFormList.value.configList[index].multy = 2
             configFormList.value.configList[index].configVal = ''
         } else if (configType === '2' || configType === '3') {
-            configFormList.value.configList[index].multy = '1'
+            configFormList.value.configList[index].multy = 2
             configFormList.value.configList[index].configVal = ''
         }
         console.log('1-handleTypeOne-configVal', configFormList.value.configList[index].configVal)
@@ -354,9 +354,9 @@
     const handleTypeTwo = (index, configType, multy) => {
         console.log('选择2变化:', 'index', index, 'configType', configType, 'multy', multy)
         // configType:1-输入框 2-选择框 3-日期
-        // multy:1-单选 2-多选 3-比较 4-不比较
+        // multy:1-多选 2-单选 3-大于> 4-小于<
 
-        if (configType === '3' && multy === '2' || configType === '2' && multy === '2') {
+        if (configType === '3' && multy === 1 || configType === '2' && multy === 1) {
             configFormList.value.configList[index].configVal = []
         } else {
             configFormList.value.configList[index].configVal = ''
@@ -405,10 +405,10 @@
             // 选择框
             if (item.configType === '2') {
                 const typeCode = camelToSnake(item.fieldName)
-                if (item.multy === '1') {
+                if (item.multy === 2) {
                     // 单选
                     valueText = getDictionaryName(typeCode, item.configVal)
-                } else if (item.multy === '2') {
+                } else if (item.multy === 1) {
                     // 多选
                     // valueText = item.configVal.map((v) => getDictionaryName(typeCode, v)).join('、')
                     valueText = Array.isArray(item.configVal)
@@ -417,17 +417,14 @@
                             .split(',')
                             .map(v => getDictionaryName(typeCode, v))
                             .join('、')
-
-                    console.log('选择框多选', valueText)
-
                 }
             }
 
             // 日期
             else if (item.configType === '3') {
-                if (item.multy === '1') {
+                if (item.multy === 2) {
                     valueText = formatDateToYMD(item.configVal)
-                } else if (item.multy === '2') {
+                } else if (item.multy === 1) {
                     if (item.configVal[0] || item.configVal[1]) {
                         valueText = `${formatDateToYMD(item.configVal[0])}到${formatDateToYMD(item.configVal[1])}`
                     } else {
@@ -438,7 +435,7 @@
 
             // 输入框
             else {
-                if (item.multy === '3') {
+                if (item.multy === 1) {
                     if (item.configVal) {
                         const [min, max] = item.configVal.split('-').map(Number)
                         valueText = `${min}到${max}`
@@ -450,8 +447,9 @@
                 }
             }
             if (fieldDesc && valueText && valueText.length > 0) {
-                item.fieldDesc = `${fieldDesc}为${valueText}`
-                return `${fieldDesc}为${valueText}`
+                // getOptions('multy')[item.multy - 1].label
+                item.fieldDesc = `${fieldDesc}为${getOptions('multy')[item.multy - 1].label}${valueText}`
+                return `${fieldDesc}为${getOptions('multy')[item.multy - 1].label}${valueText}`
             } else {
                 return ''
             }
@@ -469,20 +467,20 @@
 
             res.configList.forEach((item, index) => {
                 // configType:1-输入框 2-选择框 3-日期
-                // multy:1-单选 2-多选 3-比较 4-不比较
+                // multy:1-多选 2-单选 3-大于> 4-小于<
 
                 if (item.configType === 2) {
-                    if (item.multy === 1) {
+                    if (item.multy === 2) {
                         item.configVal = Number(item.configVal)
                     } else {
                         item.configVal = item.configVal.split(',').map(Number)
                     }
-                } else if (item.configType === 3 && item.multy === 2) {
+                } else if (item.configType === 3 && item.multy === 1) {
                     item.configVal = item.configVal.split(',');
                 }
 
                 configFormList.value.configList[index].configType = String(item.configType)
-                configFormList.value.configList[index].multy = String(item.multy)
+                configFormList.value.configList[index].multy = item.multy
                 configFormList.value.configList[index].configVal = item.configVal
             })
 

+ 1 - 0
src/views/main/riskModule/riskControlConfig.vue

@@ -313,6 +313,7 @@
       let res = await riskUpdateConfig({ ...data })
       if (res.code === 200) {
         ElMessage.success('配置保存成功')
+        getList();
       }
     } else {
       let res = await riskSaveConfig(