Explorar el Código

feat(router): 动态router

gemercheung hace 3 años
padre
commit
cf7577b090

+ 1 - 1
.env.development

@@ -7,7 +7,7 @@ VITE_PUBLIC_PATH = /
 # Cross-domain proxy, you can configure multiple
 # Please note that no line breaks
 # http://192.168.0.38:8190/shop
-VITE_PROXY = [["/basic-api","http://192.168.0.47:8190"],["/upload","http://localhost:3300/upload"],["/zfb-api","http://192.168.0.47:7081"]]
+VITE_PROXY = [["/basic-api","http://192.168.0.47:8190"],["/upload","http://localhost:3300/upload"],["/zfb-api","http://192.168.0.38:7081"]]
 #["/zfb-api","http://192.168.0.47:7081"]]
 # VITE_PROXY=[["/api","https://vvbin.cn/test"]]
 

+ 1 - 1
src/api/corporation/model.ts

@@ -14,7 +14,7 @@ export interface checkDeiceParam {
 }
 export interface auditParam {
   state: number | null;
-  id: number | null;
+  id: number | string;
 }
 
 export interface addPointParam {

+ 2 - 2
src/api/sys/menu.ts

@@ -2,7 +2,7 @@ import { defHttp } from '/@/utils/http/axios';
 import { getMenuListResultModel } from './model/menuModel';
 
 enum Api {
-  GetMenuList = '/getMenuList',
+  GetMenuList = '/zfb-api/zfb/shop/sys/menu/user',
 }
 
 /**
@@ -10,5 +10,5 @@ enum Api {
  */
 
 export const getMenuList = () => {
-  return defHttp.get<getMenuListResultModel>({ url: Api.GetMenuList });
+  return defHttp.post<getMenuListResultModel>({ url: Api.GetMenuList });
 };

+ 3 - 0
src/api/system/model/systemModel.ts

@@ -4,6 +4,9 @@ export type AccountParams = BasicPageParams & {
   account?: string;
   nickname?: string;
 };
+export type DelAccountParams = {
+  userId: string;
+};
 
 export type RoleParams = {
   roleName?: string;

+ 15 - 0
src/api/system/system.ts

@@ -1,5 +1,6 @@
 import {
   AccountParams,
+  DelAccountParams,
   DeptListItem,
   MenuParams,
   RoleParams,
@@ -27,7 +28,10 @@ enum Api {
   MenuUser = '/zfb-api/zfb/shop/sys/menu/delete',
 
   AccountList = '/zfb-api/zfb/shop/sys/user/list',
+  saveAccount = '/zfb-api/zfb/shop/sys/user/save',
+  updateAccount = '/zfb-api/zfb/shop/sys/user/update',
   IsAccountExist = '/basic-api/system/accountExist',
+  deleteAccountUser = '/zfb-api/zfb/shop/sys/user/preDeleteStaff',
 
   RolePageList = '/zfb-api/zfb/shop/sys/role/list',
   setRoleStatus = '/basic-api/system/setRoleStatus',
@@ -45,6 +49,17 @@ enum Api {
 export const getAccountList = (params: AccountParams) =>
   defHttp.post<AccountListGetResultModel>({ url: Api.AccountList, params });
 
+export const deleteAccountUserApi = (params: DelAccountParams) =>
+  defHttp.post<AccountListGetResultModel>({ url: Api.deleteAccountUser, params });
+
+export const saveAccountUserApi = (params: AccountParams) =>
+  defHttp.post<AccountListGetResultModel>({ url: Api.saveAccount, params });
+
+export const updateAccountUserApi = (params: AccountParams) =>
+  defHttp.post<AccountListGetResultModel>({ url: Api.updateAccount, params });
+
+//decpored
+
 export const getDeptList = (params?: DeptListItem) =>
   defHttp.get<DeptListGetResultModel>({ url: Api.DeptList, params });
 

+ 1 - 0
src/router/types.ts

@@ -16,6 +16,7 @@ export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> {
   children?: AppRouteRecordRaw[];
   props?: Recordable;
   fullPath?: string;
+  menuId?: number;
 }
 
 export interface MenuTag {

+ 2 - 2
src/settings/projectSetting.ts

@@ -24,8 +24,8 @@ const setting: ProjectConfig = {
   settingButtonPosition: SettingButtonPositionEnum.AUTO,
 
   // Permission mode
-  permissionMode: PermissionModeEnum.ROUTE_MAPPING,
-
+  // permissionMode: PermissionModeEnum.BACK,
+  permissionMode: PermissionModeEnum.BACK,
   // Permission-related cache is stored in sessionStorage or localStorage
   permissionCacheType: CacheTypeEnum.LOCAL,
 

+ 9 - 2
src/store/modules/permission.ts

@@ -24,6 +24,8 @@ import { getPermCode } from '/@/api/sys/user';
 import { useMessage } from '/@/hooks/web/useMessage';
 import { PageEnum } from '/@/enums/pageEnum';
 
+import { makeMenuTree } from '/@/utils/treeUtils';
+
 interface PermissionState {
   // Permission code list
   permCodeList: string[] | number[];
@@ -185,8 +187,13 @@ export const usePermissionStore = defineStore({
           // this function may only need to be executed once, and the actual project can be put at the right time by itself
           let routeList: AppRouteRecordRaw[] = [];
           try {
-            this.changePermissionCode();
-            routeList = (await getMenuList()) as AppRouteRecordRaw[];
+            // this.changePermissionCode();
+            const tdata = await getMenuList();
+            console.log('tdata', tdata);
+            console.log(' makeMenuTree(tdata)', makeMenuTree(tdata));
+            routeList = makeMenuTree(tdata) as AppRouteRecordRaw[];
+
+            console.log('routeList', routeList);
           } catch (error) {
             console.error(error);
           }

+ 8 - 2
src/views/dashboard/system/account/AccountModal.vue

@@ -8,7 +8,7 @@
   import { BasicModal, useModalInner } from '/@/components/Modal';
   import { BasicForm, useForm } from '/@/components/Form/index';
   import { accountFormSchema } from './account.data';
-  // import { getDeptList } from '/@/api/system/system';
+  import { saveAccountUserApi, updateAccountUserApi } from '/@/api/system/system';
   // import { makeMenuTree, TreeMenuNode } from '/@/utils/treeUtils';
 
   export default defineComponent({
@@ -63,8 +63,14 @@
           setModalProps({ confirmLoading: true });
           // TODO custom api
           console.log(values);
+          if (!unref(isUpdate)) {
+            await saveAccountUserApi(values);
+          } else {
+            await updateAccountUserApi(values);
+          }
+
           closeModal();
-          emit('success', { isUpdate: unref(isUpdate), values: { ...values, id: rowId.value } });
+          emit('success');
         } finally {
           setModalProps({ confirmLoading: false });
         }

+ 2 - 2
src/views/dashboard/system/account/account.data.ts

@@ -93,7 +93,7 @@ export const accountFormSchema: FormSchema[] = [
   // },
   {
     label: '角色',
-    field: 'role',
+    field: 'roleId',
     component: 'ApiSelect',
     componentProps: {
       api: roleSelectListApi,
@@ -124,7 +124,7 @@ export const accountFormSchema: FormSchema[] = [
   },
 
   {
-    field: 'phoneNum',
+    field: 'phone',
     label: '手机号',
     component: 'Input',
     required: true,

+ 14 - 17
src/views/dashboard/system/account/index.vue

@@ -12,11 +12,11 @@
       <template #action="{ record }">
         <TableAction
           :actions="[
-            {
-              icon: 'clarity:info-standard-line',
-              tooltip: '查看用户详情',
-              onClick: handleView.bind(null, record),
-            },
+            // {
+            //   icon: 'clarity:info-standard-line',
+            //   tooltip: '查看用户详情',
+            //   onClick: handleView.bind(null, record),
+            // },
             {
               icon: 'clarity:note-edit-line',
               tooltip: '编辑用户资料',
@@ -39,10 +39,10 @@
   </PageWrapper>
 </template>
 <script lang="ts">
-  import { defineComponent, reactive } from 'vue';
+  import { defineComponent, reactive, nextTick } from 'vue';
 
   import { BasicTable, useTable, TableAction } from '/@/components/Table';
-  import { getAccountList } from '/@/api/system/system';
+  import { getAccountList, deleteAccountUserApi } from '/@/api/system/system';
   import { PageWrapper } from '/@/components/Page';
   // import DeptTree from './DeptTree.vue';
 
@@ -102,19 +102,16 @@
         });
       }
 
-      function handleDelete(record: Recordable) {
+      async function handleDelete(record: Recordable) {
         console.log(record);
+        await deleteAccountUserApi({
+          userId: record.id,
+        });
+        nextTick(reload);
       }
 
-      function handleSuccess({ isUpdate, values }) {
-        if (isUpdate) {
-          // 演示不刷新表格直接更新内部数据。
-          // 注意:updateTableDataRecord要求表格的rowKey属性为string并且存在于每一行的record的keys中
-          // const result = updateTableDataRecord(values.id, values);
-          console.log(values);
-        } else {
-          reload();
-        }
+      function handleSuccess() {
+        nextTick(reload);
       }
 
       function handleSelect(deptId = '') {

+ 2 - 2
src/views/dashboard/system/menu/menu.data.ts

@@ -13,8 +13,8 @@ export const columns: BasicColumn[] = [
     width: 80,
   },
   {
-    title: 'parentId(debug)',
-    dataIndex: 'parentId',
+    title: '组件路径',
+    dataIndex: 'component',
     width: 80,
   },
   {