Browse Source

perf: 优化下拉数据以及退出登陆重定向路径

曾坤森 1 month ago
parent
commit
7b16ec6c4b

+ 1 - 0
components.d.ts

@@ -2,6 +2,7 @@
 // @ts-nocheck
 // Generated by unplugin-vue-components
 // Read more: https://github.com/vuejs/core/pull/3399
+// biome-ignore lint: disable
 export {};
 
 /* prettier-ignore */

+ 1 - 2
src/hooks/user.ts

@@ -8,13 +8,12 @@ export default function useUser() {
   const userStore = useUserStore();
   const logout = async (logoutTo?: string) => {
     await userStore.logout();
-    const currentRoute = router.currentRoute.value;
     Message.success('登出成功');
     router.push({
       name: logoutTo && typeof logoutTo === 'string' ? logoutTo : 'login',
       query: {
         ...router.currentRoute.value.query,
-        redirect: currentRoute.name as string,
+        redirect: encodeURIComponent(router.currentRoute.value.fullPath),
       },
     });
   };

+ 1 - 7
src/utils/const.ts

@@ -15,13 +15,7 @@ export interface DeviceInfo {
   label: string;
   value: string;
 }
-export const DeviceTypeList = [
-  { value: 1, label: 'Camera' },
-  { value: 2, label: 'Server' },
-  { value: 3, label: 'Temperature sensor' },
-  { value: 4, label: 'SQU' },
-  { value: 5, label: 'MCS' },
-];
+
 // 将 rules 改为函数,接收 t 函数作为参数
 export const getRules = (t: (key: string) => string) => ({
   email: [

+ 8 - 6
src/views/dashboard/manage/index.vue

@@ -69,9 +69,9 @@
                     @clear="formModel.status = null"
                   >
                     <a-option
-                      v-for="item of statusTypeList"
-                      :value="item.value"
-                      :label="item.label"
+                      v-for="item of deviceStatusList"
+                      :value="item.dictCode"
+                      :label="item.name"
                     />
                   </a-select>
                 </a-form-item>
@@ -143,7 +143,8 @@
         <template #status="{ record }">
           <BTag :status="record.status">
             {{
-              statusTypeList.find(item => item.value === record.status)?.label
+              deviceStatusList.find(item => item.dictCode === record.status)
+                ?.name
             }}
           </BTag>
         </template>
@@ -218,7 +219,6 @@ import EditDialog from './edit.vue';
 import type { TableColumnData } from '@arco-design/web-vue';
 import useLoading from '@/hooks/loading';
 import { useI18n } from 'vue-i18n';
-import { statusTypeList } from '../workplace/conf';
 import dayjs from 'dayjs';
 import { downLoadFun, DeviceInfo } from '@/utils/const';
 import { useIntervalFn } from '@vueuse/core';
@@ -302,9 +302,11 @@ const deviceId = ref<number | null>(null);
 const this_ = getCurrentInstance()?.appContext.config.globalProperties;
 const deviceInfo = ref<DeviceInfo[]>([] as DeviceInfo[]);
 const deviceTypeList = ref<AdditionalProp[]>([] as AdditionalProp[]);
+const deviceStatusList = ref<AdditionalProp[]>([] as AdditionalProp[]);
 
-getDictQueryList({ names: ['DeviceType'] }).then(res => {
+getDictQueryList({ names: ['DeviceType', 'DeviceStatus'] }).then(res => {
   deviceTypeList.value.push(...res.data['DeviceType']);
+  deviceStatusList.value.push(...res.data['DeviceStatus']);
 });
 function searchTable() {
   // setLoading(true);

+ 9 - 12
src/views/dashboard/workplace/index.vue

@@ -58,7 +58,7 @@
               </a-col>
               <a-col :span="6">
                 <a-form-item
-                  field="statusTypeList"
+                  field="status"
                   :label="t('dashboard.form.status')"
                   label-col-flex="60px"
                 >
@@ -69,9 +69,9 @@
                     @clear="formModel.status = null"
                   >
                     <a-option
-                      v-for="item of statusTypeList"
-                      :value="item.value"
-                      :label="item.label"
+                      v-for="item of deviceStatusList"
+                      :value="item.dictCode"
+                      :label="item.name"
                     />
                   </a-select>
                 </a-form-item>
@@ -114,7 +114,6 @@
         </a-col>
       </a-row>
       <a-table
-        class="table-list"
         row-key="name"
         :loading="loading"
         :pagination="pagination"
@@ -141,7 +140,8 @@
         <template #status="{ record }">
           <BTag :status="record.status">
             {{
-              statusTypeList.find(item => item.value === record.status)?.label
+              deviceStatusList.find(item => item.dictCode === record.status)
+                ?.name
             }}
           </BTag>
         </template>
@@ -185,7 +185,6 @@ import BTag from '@/components/business/b-tag/index.vue';
 import type { TableColumnData } from '@arco-design/web-vue';
 import useLoading from '@/hooks/loading';
 import { useI18n } from 'vue-i18n';
-import { statusTypeList } from './conf';
 import { DeviceInfo } from '@/utils/const';
 import type { AdditionalProp } from '@/api/dict';
 import { getDictQueryList } from '@/api/dict';
@@ -263,8 +262,10 @@ 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 => {
+const deviceStatusList = ref<AdditionalProp[]>([] as AdditionalProp[]);
+getDictQueryList({ names: ['DeviceType', 'DeviceStatus'] }).then(res => {
   deviceTypeList.value.push(...res.data['DeviceType']);
+  deviceStatusList.value.push(...res.data['DeviceStatus']);
 });
 function searchTable() {
   // setLoading(true);
@@ -355,9 +356,5 @@ const handleCancel = () => {
       margin-top: 20px;
     }
   }
-
-  .table-list {
-    margin-top: 0;
-  }
 }
 </style>

+ 21 - 6
src/views/login/components/login-form.vue

@@ -100,12 +100,27 @@ const handleSubmit = async ({
       const res = await userStore.login(values as LoginData);
       const { redirect, ...othersQuery } = router.currentRoute.value.query;
       if (res.success) {
-        await router.push({
-          name: (redirect as string) || 'Workplace',
-          query: {
-            ...othersQuery,
-          },
-        });
+        if (redirect) {
+          try {
+            const decodedPath = decodeURIComponent(redirect as string);
+            await router.push(decodedPath);
+          } catch (error) {
+            await router.push({
+              name: 'Workplace',
+              query: {
+                ...othersQuery,
+              },
+            });
+          }
+        } else {
+          await router.push({
+            name: 'Workplace',
+            query: {
+              ...othersQuery,
+            },
+          });
+        }
+
         Message.success(t('login.form.login.success'));
         const { rememberPassword } = loginInfo.value;
         const { name, id, privilege } = res.data;

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

@@ -122,6 +122,7 @@ watch(
       if (!props.listObj.id) {
         form.value.id = 0;
         form.value.dictId = Number(id);
+        form.value.status = 1;
       }
     }
   }

+ 0 - 5
src/views/system/dict-item/index.vue

@@ -77,7 +77,6 @@
         </a-col>
       </a-row>
       <a-table
-        class="table-list"
         row-key="name"
         :loading="loading"
         :pagination="pagination"
@@ -296,10 +295,6 @@ const handleDeleteFun = (id: number) => {
     }
   }
 
-  .table-list {
-    margin-top: 10px;
-  }
-
   .action-button {
     margin-right: 10px;
   }

+ 11 - 4
src/views/user/manage/index.vue

@@ -124,8 +124,10 @@ import type { TableColumnData } from '@arco-design/web-vue';
 import useLoading from '@/hooks/loading';
 import EditDialog from './components/edit.vue';
 import { useI18n } from 'vue-i18n';
-import { privilegeList } from '@/utils/const';
+// import { privilegeList } from '@/utils/const';
 import { Modal } from '@arco-design/web-vue';
+import type { AdditionalProp } from '@/api/dict';
+import { getDictQueryList } from '@/api/dict';
 
 const { t } = useI18n();
 
@@ -180,6 +182,10 @@ const formModel = ref<UserParams>(generateFormModel());
 const userId = shallowRef<number>(0);
 const showEditDialog = shallowRef<boolean>(false);
 const this_ = getCurrentInstance()?.appContext.config.globalProperties;
+const privilegeList = ref<AdditionalProp[]>([]);
+getDictQueryList({ names: ['Privilege'] }).then(res => {
+  privilegeList.value.push(...res.data['Privilege']);
+});
 const search = () => {
   searchTable();
 };
@@ -231,9 +237,10 @@ const handleDeleteFun = (id: number) => {
 };
 const getPrivilegeLabel = computed(() => {
   return (privilegeValue: string | number) => {
-    if (!privilegeValue || !privilegeList) return '-';
-    const privilege = privilegeList.find(item => item.value === privilegeValue);
-    return privilege ? t(privilege.label as string) : '-';
+    const privilege = privilegeList.value.find(
+      item => item.dictCode === privilegeValue
+    );
+    return privilege ? t(privilege.name as string) : '-';
   };
 });
 </script>