Procházet zdrojové kódy

feat: 下拉选项接口获取

曾坤森 před 2 měsíci
rodič
revize
b08e6fe0b1

+ 29 - 1
src/api/dict.ts

@@ -52,6 +52,30 @@ export interface SuccessRes {
   code: string;
   data: number;
 }
+export interface AdditionalProp {
+  dictCode: number;
+  name: string;
+  chsName: string;
+  chtName: string;
+}
+
+export interface AdditionalProp {
+  dictCode: number;
+  name: string;
+  chsName: string;
+  chtName: string;
+}
+
+export interface DictQueryList {
+  [key: string]: AdditionalProp[]; // 索引签名,允许任意字符串键
+}
+
+export interface DictQueryRes {
+  success: boolean;
+  message: string;
+  code: string;
+  data: DictQueryList;
+}
 export async function getDictList(params: object): Promise<DictRes> {
   const res = await instance.post('/api/Dict/List', params);
   return res.data;
@@ -64,6 +88,10 @@ export async function fetchDeleteDict(params: object): Promise<SuccessRes> {
   const res = await instance.post('/api/Dict/Delete', params);
   return res.data;
 }
+export async function getDictQueryList(params: object): Promise<DictQueryRes> {
+  const res = await instance.post('/api/Dict/DictQuery', params);
+  return res.data;
+}
 export async function getDictItemList(params: object): Promise<DictItemList> {
   const res = await instance.post('/api/DictItem/List', params);
   return res.data;
@@ -73,6 +101,6 @@ export async function fetchSaveDictItem(params: object): Promise<SuccessRes> {
   return res.data;
 }
 export async function fetchDeleteDictItem(params: object): Promise<SuccessRes> {
-  const res = await instance.post('/api/Dict/Delete', params);
+  const res = await instance.post('/api/DictItem/Delete', params);
   return res.data;
 }

+ 1 - 1
src/router/routes/modules/system.ts

@@ -8,7 +8,7 @@ const SYSTEM: AppRouteRecordRaw = {
   meta: {
     locale: 'menu.system',
     requiresAuth: true,
-    icon: 'icon-list',
+    icon: 'icon-settings',
     order: 2,
   },
   children: [

+ 1 - 1
src/utils/const.ts

@@ -15,7 +15,7 @@ export interface DeviceInfo {
   label: string;
   value: string;
 }
-export const entityTypeList = [
+export const DeviceTypeList = [
   { value: 1, label: 'Camera' },
   { value: 2, label: 'Server' },
   { value: 3, label: 'Temperature sensor' },

+ 9 - 5
src/views/dashboard/manage/edit.vue

@@ -39,9 +39,9 @@
                 @clear="form.deviceType = null"
               >
                 <a-option
-                  v-for="item of entityTypeList"
-                  :value="item.value"
-                  :label="t(item.label)"
+                  v-for="item of deviceTypeList"
+                  :value="item.dictCode"
+                  :label="item.name"
                 />
               </a-select>
             </a-form-item>
@@ -55,7 +55,8 @@
 import { reactive, ref, shallowRef, watch, getCurrentInstance } from 'vue';
 import { getDeviceDetails, saveDeviceDetails } from '@/api/dashboard';
 import type { DataList } from '@/api/dashboard';
-import { privilegeList, entityTypeList } from '@/utils/const';
+import type { AdditionalProp } from '@/api/dict';
+import { getDictQueryList } from '@/api/dict';
 import { useI18n } from 'vue-i18n';
 import { getRules } from '@/utils/const';
 const formRef = ref();
@@ -77,7 +78,7 @@ const props = withDefaults(defineProps<EditDialogProps>(), {
 });
 const emit = defineEmits<EditDialogEmits>();
 const visible = shallowRef<boolean>(false);
-
+const deviceTypeList = ref<AdditionalProp[]>([] as AdditionalProp[]);
 watch(
   () => props.modelValue,
   value => {
@@ -121,6 +122,9 @@ const handleBeforeOk = (done: (closed: boolean) => void) => {
     }
   });
 };
+getDictQueryList({ names: ['DeviceType'] }).then(res => {
+  deviceTypeList.value = res.data['DeviceType'];
+});
 const handleCancel = () => {
   form.value = formModel();
   visible.value = false;

+ 13 - 7
src/views/dashboard/manage/index.vue

@@ -49,9 +49,9 @@
                     @clear="formModel.entityType = null"
                   >
                     <a-option
-                      v-for="item of entityTypeList"
-                      :value="item.value"
-                      :label="item.label"
+                      v-for="item of deviceTypeList"
+                      :value="item.dictCode"
+                      :label="item.name"
                     />
                   </a-select>
                 </a-form-item>
@@ -135,8 +135,8 @@
         <template #entityType="{ record }">
           <span>
             {{
-              entityTypeList.find(item => item.value === record.entityType)
-                ?.label
+              deviceTypeList.find(item => item.dictCode === record.entityType)
+                ?.name
             }}
           </span>
         </template>
@@ -220,10 +220,11 @@ import useLoading from '@/hooks/loading';
 import { useI18n } from 'vue-i18n';
 import { statusTypeList } from '../workplace/conf';
 import dayjs from 'dayjs';
-import { downLoadFun, DeviceInfo, entityTypeList } from '@/utils/const';
+import { downLoadFun, DeviceInfo } from '@/utils/const';
 import { useIntervalFn } from '@vueuse/core';
 import { Modal } from '@arco-design/web-vue';
-
+import type { AdditionalProp } from '@/api/dict';
+import { getDictQueryList } from '@/api/dict';
 const { t } = useI18n();
 
 const { loading, setLoading } = useLoading(true);
@@ -300,6 +301,11 @@ const showEditDialog = shallowRef<boolean>(false);
 const deviceId = ref<number | null>(null);
 const this_ = getCurrentInstance()?.appContext.config.globalProperties;
 const deviceInfo = ref<DeviceInfo[]>([] as DeviceInfo[]);
+const deviceTypeList = ref<AdditionalProp[]>([] as AdditionalProp[]);
+
+getDictQueryList({ names: ['DeviceType'] }).then(res => {
+  deviceTypeList.value.push(...res.data['DeviceType']);
+});
 function searchTable() {
   // setLoading(true);
   const [startTime, endTime] = formModel.value.time

+ 13 - 7
src/views/dashboard/workplace/index.vue

@@ -49,9 +49,9 @@
                     @clear="formModel.entityType = null"
                   >
                     <a-option
-                      v-for="item of entityTypeList"
-                      :value="item.value"
-                      :label="item.label"
+                      v-for="item of deviceTypeList"
+                      :value="item.dictCode"
+                      :label="item.name"
                     />
                   </a-select>
                 </a-form-item>
@@ -118,7 +118,7 @@
         row-key="name"
         :loading="loading"
         :pagination="pagination"
-        :columns="(cloneColumns as TableColumnData[])"
+        :columns="cloneColumns as TableColumnData[]"
         :data="renderData"
         :bordered="false"
         :size="size"
@@ -133,8 +133,8 @@
         <template #entityType="{ record }">
           <span>
             {{
-              entityTypeList.find(item => item.value === record.entityType)
-                ?.label
+              deviceTypeList.find(item => item.dictCode === record.entityType)
+                ?.name
             }}
           </span>
         </template>
@@ -186,7 +186,9 @@ import type { TableColumnData } from '@arco-design/web-vue';
 import useLoading from '@/hooks/loading';
 import { useI18n } from 'vue-i18n';
 import { statusTypeList } from './conf';
-import { entityTypeList, DeviceInfo } from '@/utils/const';
+import { DeviceInfo } from '@/utils/const';
+import type { AdditionalProp } from '@/api/dict';
+import { getDictQueryList } from '@/api/dict';
 import dayjs from 'dayjs';
 import { downLoadFun } from '@/utils/const';
 import { useIntervalFn } from '@vueuse/core';
@@ -260,6 +262,10 @@ const formModel = ref<DashboardParams>(generateFormModel());
 const visible = shallowRef<boolean>(false);
 const this_ = getCurrentInstance()?.appContext.config.globalProperties;
 const deviceInfo = ref<DeviceInfo[]>([] as DeviceInfo[]);
+const deviceTypeList = ref<AdditionalProp[]>([] as AdditionalProp[]);
+getDictQueryList({ names: ['DeviceType'] }).then(res => {
+  deviceTypeList.value.push(...res.data['DeviceType']);
+});
 function searchTable() {
   // setLoading(true);
   const [startTime, endTime] = formModel.value.time

+ 3 - 3
src/views/system/dict-item/edit.vue

@@ -85,9 +85,9 @@
 </template>
 <script setup lang="ts" name="DictItemDialog">
 import { reactive, ref, shallowRef, watch, getCurrentInstance } from 'vue';
-import { fetchSaveDict } from '@/api/dict';
+import { fetchSaveDictItem } from '@/api/dict';
 import type { ItemDataList } from '@/api/dict';
-import { privilegeList, getRules } from '@/utils/const';
+import { getRules } from '@/utils/const';
 import { useI18n } from 'vue-i18n';
 import { useRoute } from 'vue-router';
 const {
@@ -140,7 +140,7 @@ const form = ref<ItemDataList>(formModel());
 const handleBeforeOk = (done: (closed: boolean) => void) => {
   formRef.value.validate().then((data: ItemDataList) => {
     if (!data) {
-      fetchSaveDict(form.value)
+      fetchSaveDictItem(form.value)
         .then(res => {
           if (res.success) {
             this_?.$message.success(t('message.success'));

+ 1 - 1
src/views/system/dict/edit.vue

@@ -37,7 +37,7 @@
 import { reactive, ref, shallowRef, watch, getCurrentInstance } from 'vue';
 import { fetchSaveDict } from '@/api/dict';
 import type { DataList } from '@/api/dict';
-import { privilegeList, getRules } from '@/utils/const';
+import { getRules } from '@/utils/const';
 import { useI18n } from 'vue-i18n';
 import type { UserData, UserParams } from '@/api/user';