wxy 4 ماه پیش
والد
کامیت
c759055731

+ 5 - 0
src/api/path/dict.js

@@ -23,4 +23,9 @@ export function dictionaryUpdate(param) {
 // 删除字典
 export function dictionaryDelete(params) {
     return service.get('/admin/system/deleteDic', { params })
+}
+
+// 获取下级分类
+export function dictionaryDeleteAll(params) {
+    return service.get('/admin/system/getDic', { params })
 }

+ 2 - 1
src/i18n/zh/tariffManagement.js

@@ -31,5 +31,6 @@ export default {
     soundName: '供应商名称',
     FlowType: '流量类型',
     BillingType:'计费分类',
-    ChargingCycle:'计费周期'
+    ChargingCycle:'计费周期',
+    userName:'客户名称'
 }

+ 46 - 17
src/views/login/login-form.vue

@@ -5,18 +5,18 @@
 
     <a-form ref="loginForm" :model="formData" class="login-form" @submit-success="handleSubmit">
       <a-form-item field="username" :rules="[{ required: true, message: '用户名不能为空' }]"
-        :validate-trigger="['change', 'blur']" hide-label>
+                   :validate-trigger="['change', 'blur']" hide-label>
         <a-input v-model="formData.username" placeholder="用户名:">
           <template #prefix>
-            <icon-user />
+            <icon-user/>
           </template>
         </a-input>
       </a-form-item>
       <a-form-item field="password" :rules="[{ required: true, message: '密码不能为空' }]"
-        :validate-trigger="['change', 'blur']" hide-label>
+                   :validate-trigger="['change', 'blur']" hide-label>
         <a-input-password v-model="formData.password" placeholder="密码:" allow-clear>
           <template #prefix>
-            <icon-lock />
+            <icon-lock/>
           </template>
         </a-input-password>
       </a-form-item>
@@ -29,20 +29,20 @@
           </a-checkbox>
           <!-- <a-link>忘记密码</a-link> -->
         </div>
-        <a-button type="primary" html-type="submit" long :loading="formLoading"> 登陆 </a-button>
+        <a-button type="primary" html-type="submit" long :loading="formLoading"> 登陆</a-button>
       </a-space>
     </a-form>
   </div>
 </template>
 
 <script setup>
-import { ref, reactive } from 'vue'
-import { encryptByDES } from "@/utils"
-import { loginApi } from "@/api/path/login.api"
-import { useSystemStore } from "@/store/modules/systemStore"
-import { useRouter } from 'vue-router'
-import { updateRouteByMenu } from '@/router/router.update'
-import { dictionaryList } from "@/api/path/dict"
+import {ref, reactive} from 'vue'
+import {encryptByDES} from "@/utils"
+import {loginApi} from "@/api/path/login.api"
+import {useSystemStore} from "@/store/modules/systemStore"
+import {useRouter} from 'vue-router'
+import {updateRouteByMenu} from '@/router/router.update'
+import {dictionaryDeleteAll, dictionaryList} from "@/api/path/dict"
 
 const router = useRouter()
 const formData = ref({
@@ -54,7 +54,7 @@ const rememberPassword = ref(true)
 const systemStore = useSystemStore()
 
 const handleSubmit = async () => {
-  const { data } = await loginApi({
+  const {data} = await loginApi({
     username: formData.value.username,
     password: encryptByDES(formData.value.password)
   })
@@ -67,7 +67,7 @@ const handleSubmit = async () => {
   })
   systemStore.setStateValue({
     key: 'user_login_information',
-    value: JSON.stringify(data.userInfo?data.userInfo:data),
+    value: JSON.stringify(data.userInfo ? data.userInfo : data),
     localStorage: true,
   })
   systemStore.setStateValue({
@@ -87,10 +87,10 @@ const handleSubmit = async () => {
         current: 1,
       })
       if (res.code == 200) {
-        window.localStorage.setItem('dictList', JSON.stringify(res.data))
+        processDataAndSave(res)
+
       }
-    }
-    catch (error){
+    } catch (error) {
       console.error(error)
     }
   }
@@ -101,6 +101,35 @@ const setRememberPassword = (e) => {
     window.localStorage.removeItem('remember_user_name')
   }
 }
+
+// 调用所有字典
+const processDataAndSave = async (res) => {
+  try {
+    // 遍历 res.data 并收集所有异步操作的 Promise
+    const promises = res.data.map((item) =>
+        dictionaryDeleteAll({ typeKey: item.typeKey }).then(response => {
+          // 如果成功返回结果,将返回数据合并
+          if (response.code === 200) {
+            return response.data; // 假设 response.data 是需要的部分
+          } else {
+            console.error(`处理失败: typeKey=${item.typeKey}`, response.message);
+            return []; // 返回空数组避免错误
+          }
+        })
+    );
+
+    // 等待所有异步操作完成并合并所有返回数据
+    const results = await Promise.all(promises);
+    const mergedData = results.flat(); // 合并所有结果为一个数组
+
+    // 将合并后的数据存储到 localStorage
+    window.localStorage.setItem('dictList', JSON.stringify(mergedData));
+    console.log("所有操作完成,数据已存储到 localStorage");
+  } catch (error) {
+    console.error("处理过程中发生错误:", error);
+  }
+};
+
 </script>
 
 <style lang="less" scoped>

+ 37 - 44
src/views/system/dict/index.vue

@@ -11,8 +11,8 @@
       </div>
     </div>
 
-    <a-table :data="dataSource"  row-key="id" :columns="columns" :scroll="{ x: 'auto' }" :pagination="pageData"
-             @page-change="evChangePage">
+    <a-table :data="dataSource" row-key="typeKey" :columns="columns" :scroll="{ x: 'auto' }" :pagination="pageData"
+             @page-change="evChangePage" @expanded-change="expandTableIds">
       <template #operation="{ record }">
         <a class="a-link" href="javascript:;" style="margin: 0 1rem;" @click="dictShowModel(2, record)">修改</a>
         <a-popconfirm :content="`是否确认删除字典编号为 ${record.id} 的数据项?`" @ok="deleteChange(record.id)"
@@ -34,15 +34,15 @@
         <a-form-item label="字典类型" field="typeKey">
           <a-input v-model="formState.typeKey"/>
         </a-form-item>
-<!--        <a-form-item label="数据标签" field="label">-->
-<!--          <a-input v-model="formState.label"/>-->
-<!--        </a-form-item>-->
+        <a-form-item label="数据标签" field="label">
+          <a-input v-model="formState.label"/>
+        </a-form-item>
         <a-form-item label="数据键值" field="value">
           <a-input v-model="formState.value"/>
         </a-form-item>
-<!--        <a-form-item label="备注" field="remark">-->
-<!--          <a-textarea v-model="formState.remark"/>-->
-<!--        </a-form-item>-->
+        <a-form-item label="备注" field="remark">
+          <a-textarea v-model="formState.remark"/>
+        </a-form-item>
         <a-form-item>
           <a-button type="primary" html-type="submit" style="margin-right: 10px;">确定</a-button>
           <a-button @click="resetForm">取消</a-button>
@@ -54,17 +54,15 @@
 
 <script setup>
 import {onMounted, ref, reactive} from "vue";
-import {dictionaryList, dictionaryAdd, dictionaryDelete, dictionaryUpdate} from '@/api/path/dict';
+import {dictionaryList, dictionaryAdd, dictionaryDelete, dictionaryUpdate, dictionaryDeleteAll} from '@/api/path/dict';
 
 const visible = ref(false);
 const typeCurrent = ref(null);
 const formRef = ref();
 const dicId = ref(null);
-
 const formData = ref({
   typeKey: '',
   typeLabel: '',
-
 });
 const columns = ref([
 
@@ -117,11 +115,11 @@ const rules = {
 };
 
 const formState = reactive({
-  label: '',
+  // label: '',
   value: '',
   typeKey: '',
   typeLabel: '',
-  remark: '',
+  // remark: '',
 });
 
 const pageData = ref({
@@ -139,26 +137,14 @@ const intData = async () => {
     ...formData.value
   }
   const {data} = await dictionaryList(param)
-  dataSource.value = data.reduce((acc, res) => {
-    let existingItem = acc.find(item => item.typeKey === res.typeKey);
-
-    if (existingItem) {
-      // 如果已经存在相同typeKey的项,将当前项添加到其children数组中
-      if (!existingItem.children) {
-        existingItem.children = [];
-      }
-      existingItem.children.push(res);
-    } else {
-      // 如果不存在相同typeKey的项,直接添加到结果数组acc中
-      acc.push(res);
-    }
-
-    return acc;
-  }, []);
+  dataSource.value = data.map(res => ({
+    ...res,
+    children: []
+  }))
   pageData.value.total = data.total;
 }
 // 提交
-const handleSubmit = ({values, errors}) => {
+const handleSubmit = async ({values, errors}) => {
   const submitData = {
     label: formState.label,
     value: formState.value,
@@ -167,20 +153,10 @@ const handleSubmit = ({values, errors}) => {
     remark: formState.remark,
     id: typeCurrent.value == 1 ? undefined : dicId.value
   }
-  if (typeCurrent.value == 1) {
-    dictionaryAdd(submitData).then(res => {
-      if(res.code===200){
-        intData();
-        resetForm();
-      }
-    })
-  } else {
-    dictionaryUpdate(submitData).then(res => {
-      if(res.code===200){
-        intData();
-        resetForm();
-      }
-    })
+  let res = await typeCurrent.value === 1 ? dictionaryAdd(submitData) : dictionaryUpdate(submitData)
+  if (res.code === 200) {
+    intData();
+    resetForm();
   }
 
 }
@@ -229,6 +205,23 @@ const resetSelectData = () => {
   intData();
 }
 
+const expandTableIds = async (e) => {
+  if (e.length === 0) return
+  let res = await dictionaryDeleteAll({typeKey: e[0]});
+  if (res.code === 200) {
+    dataSource.value.forEach((item) => {
+      // 检查 item.typeKey 是否包含 e 中的任意一个值
+      if (e.some((key) => item.typeKey.includes(key))) {
+        // 判断 children 是否为空,为空则添加数据
+        if (item.children.length === 0) {
+          item.children = [...res.data];
+        }
+      }
+    });
+  }
+};
+
+
 onMounted(() => {
   intData();
 })

+ 3 - 2
src/views/tariffManagement/config.js

@@ -1,15 +1,16 @@
 export let columns = [
     { title: window.$t('tariffManagement.id'), dataIndex: 'id', align: 'center', width: 200 },
     { title: window.$t('tariffManagement.feeCode'), dataIndex: 'feeCode', align: 'center', width: 200 },
+    { title: window.$t('tariffManagement.userName'), dataIndex: 'userName', align: 'center', width: 200 },
     { title: window.$t('tariffManagement.label'), dataIndex: 'label', align: 'center', width: 200 },
     { title: window.$t('tariffManagement.source'), dataIndex: 'sourceName', align: 'center', width: 200 },
     { title: window.$t('tariffManagement.trafficType'), dataIndex: 'trafficTypeName', align: 'center', width: 200 },
     { title: window.$t('tariffManagement.billingType'), dataIndex: 'billingTypeName', align: 'center', width: 200 },
     { title: window.$t('tariffManagement.billingCycle'), dataIndex: 'billingCycleName', align: 'center', width: 200 },
-    { title: window.$t('tariffManagement.bagSize'), dataIndex: 'bag_size', align: 'center', width: 200 },
+    { title: window.$t('tariffManagement.bagSize'), dataIndex: 'bagSize', align: 'center', width: 200 },
     { title: window.$t('tariffManagement.pricing'), dataIndex: 'pricing', align: 'center', width: 200 },
     // { title: window.$t('tariffManagement.billingMethod'), dataIndex: 'billing_method', align: 'center', width: 200 },
-    { title: window.$t('tariffManagement.settlementCycleLabel'), dataIndex: 'settlement_cycle', align: 'center', width: 200 },
+    { title: window.$t('tariffManagement.settlementCycleLabel'), dataIndex: 'settlementCycle', align: 'center', width: 200 },
     { title: window.$t('tariffManagement.feeStatus'), dataIndex: 'status', align: 'center', width: 200 },
     {
         title: window.$t('global.common.operations'),

+ 30 - 30
src/views/tariffManagement/index.vue

@@ -44,13 +44,13 @@
           </a-select>
         </a-form-item>
 <!--        计费周期-->
-        <a-form-item field="label" :label="$t('tariffManagement.ChargingCycle')">
-          <a-select v-model="formState.pricingUnit" style="width: 140px; margin-left: 8px;"  :placeholder="$t('lotCard.ChargingCycleName')">
-            <a-option value="天">天</a-option>
-            <a-option value="年">年</a-option>
-            <a-option value="月">月</a-option>
-          </a-select>
-        </a-form-item>
+<!--        <a-form-item field="label" :label="$t('tariffManagement.ChargingCycle')">-->
+<!--          <a-select v-model="formState.pricingUnit" style="width: 140px; margin-left: 8px;"  :placeholder="$t('lotCard.ChargingCycleName')">-->
+<!--            <a-option value="天">天</a-option>-->
+<!--            <a-option value="年">年</a-option>-->
+<!--            <a-option value="月">月</a-option>-->
+<!--          </a-select>-->
+<!--        </a-form-item>-->
         <a-form-item>
           <a-space>
             <a-button type="primary" @click="handleSearch">{{ $t('form.Search') }}</a-button>
@@ -184,11 +184,11 @@
         </a-form-item>
         <a-form-item field="bagSize" :label="$t('tariffManagement.bagSize')">
           <a-input v-model="formState.bagSize" :placeholder="$t('tariffManagement.bagSize')"/>
-          <a-select v-model="formState.bagSizeUnit" style="width: 80px; margin-left: 8px;">
-            <a-option value="KB">KB</a-option>
-            <a-option value="MB">MB</a-option>
-            <a-option value="GB">GB</a-option>
-          </a-select>
+<!--          <a-select v-model="formState.bagSizeUnit" style="width: 80px; margin-left: 8px;">-->
+<!--            <a-option value="KB">KB</a-option>-->
+<!--            <a-option value="MB">MB</a-option>-->
+<!--            <a-option value="GB">GB</a-option>-->
+<!--          </a-select>-->
         </a-form-item>
         <a-form-item field="pricing" :label="$t('tariffManagement.pricing')" required>
           <a-input v-model="formState.pricing" :placeholder="$t('tariffManagement.pricing')">
@@ -196,11 +196,11 @@
             </template>
           </a-input>
-          <a-select v-model="formState.pricingUnit" style="width: 80px; margin-left: 8px;" placeholder="周期分类">
-            <a-option value="天">天</a-option>
-            <a-option value="年">年</a-option>
-            <a-option value="月">月</a-option>
-          </a-select>
+<!--          <a-select v-model="formState.pricingUnit" style="width: 80px; margin-left: 8px;" placeholder="周期分类">-->
+<!--            <a-option value="天">天</a-option>-->
+<!--            <a-option value="年">年</a-option>-->
+<!--            <a-option value="月">月</a-option>-->
+<!--          </a-select>-->
         </a-form-item>
         <a-form-item field="settlementCycle" :label="$t('tariffManagement.cycleBuy')">
           <a-input v-model="formState.settlementCycleMap.starTime">
@@ -439,8 +439,8 @@ const handleSubmit = ({values, errors}) => {
     if (!errors) {
       const formVal = JSON.parse(JSON.stringify(values))
       delete formVal.settlementCycleMap
-      delete formVal.bagSizeUnit
-      delete formVal.pricingUnit
+      // delete formVal.bagSizeUnit
+      // delete formVal.pricingUnit
 
       formVal.currency = '1'
       formVal.userId = Number(values.userId)
@@ -453,12 +453,12 @@ const handleSubmit = ({values, errors}) => {
           duration: 2000,
         })
       }
-      if (values.bagSize && values.bagSizeUnit) {
-        values.bagSize = values.bagSize + values.bagSizeUnit
-      }
-      if (values.pricingUnit) {
-        values.pricing = values.pricing + '元/' + values.pricingUnit
-      }
+      // if (values.bagSize && values.bagSizeUnit) {
+      //   values.bagSize = values.bagSize + values.bagSizeUnit
+      // }
+      // if (values.pricingUnit) {
+      //   values.pricing = values.pricing + '元/' + values.pricingUnit
+      // }
       if (formState.value.id) {
         const {code, data} = await updateTariff(formVal)
 
@@ -499,11 +499,11 @@ const dictShowModel = (type, data) => {
     formState.value.simDataPlanId = Number(formState.value.simDataPlanId)
     formState.value.userId = Number(formState.value.userId)
     if (data.bagSize) {
-      formState.value.bagSizeUnit = data.bagSize.replace(/\d/g, '')
+      // formState.value.bagSizeUnit = data.bagSize.replace(/\d/g, '')
       formState.value.bagSize = data.bagSize.match(/\d+/)[0]
     }
     if (data.pricing) {
-      formState.value.pricingUnit = data.pricing.split('/')[1] || ''
+      // formState.value.pricingUnit = data.pricing.split('/')[1] || ''
       formState.value.pricing = data.pricing.match(/\d+/)[0] || ''
     }
     if (data.settlementCycle) {
@@ -590,10 +590,10 @@ const handleDictValue = () => {
   const dictList = JSON.parse(window.localStorage.getItem('dictList')) ?? []
   sourceList.value = dictList.filter((item) => item.typeKey == enum_dict.SOURCE)
   trafficList.value = dictList.filter((item) => item.typeKey == enum_dict.BILLING_TYPE) // 计费分类
-  cycleist.value = dictList.filter((item) => item.typeKey == enum_dict.billingCycle)
-  typeList.value = dictList.filter((item) => item.typeKey == enum_dict.billingType)
+  cycleist.value = dictList.filter((item) => item.typeKey == enum_dict.BILLING_CYCLE)
+  typeList.value = dictList.filter((item) => item.typeKey == enum_dict.BILLING_CYCLE)
   methodList.value = dictList.filter((item) => item.typeKey == enum_dict.BILLING_METHOD)
-  settlementCycleMap.value = dictList.filter((item) => item.typeKey == enum_dict.settlementCycle)
+  // settlementCycleMap.value = dictList.filter((item) => item.typeKey == enum_dict.settlementCycle)
   currency.value = dictList.filter(item=>item.typeKey == enum_dict.CURRENCY_TYPE)
 }