Procházet zdrojové kódy

feat(auth): 增加业务类型权限支持及搜索表单过滤功能

- 在用户权限数据结构中新增businessTypes字段,支持业务类型权限列表
- 后端服务SysUserServiceImpl获取业务类型权限,ROOT用户返回null表示不限制
- 修改UserInfoVO和UserConverter,添加业务类型权限字段支持
- 为权限模块auth状态新增businessTypes初始值
- normal-order模块新增getSearchForm函数,基于用户业务类型权限过滤业务类型下拉选项
- normal-order及after-sales-order视图中,将搜索表单改为使用getSearchForm函数以实现权限过滤
- 更新相关接口声明,支持业务类型权限字段的传递和使用
Sheep před 12 hodinami
rodič
revize
1051013d38

+ 2 - 1
src/store/modules/auth/index.ts

@@ -29,7 +29,8 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
     email: '',
     mobile: '',
     perms: [],
-    nickname: ''
+    nickname: '',
+    businessTypes: null
   });
 
   /** is super role in static route */

+ 2 - 0
src/typings/api.d.ts

@@ -71,6 +71,8 @@ declare namespace Api {
       email: string;
       mobile: string;
       perms: string[];
+      /** 业务类型权限列表,null表示不限制(ROOT用户) */
+      businessTypes?: string[] | null;
     }
     interface UserPassWord {
       password: string;

+ 2 - 0
src/typings/api/auth.d.ts

@@ -17,6 +17,8 @@ declare namespace Api {
       buttons: string[];
       perms: string[];
       nickname: string;
+      /** 业务类型权限列表,null表示不限制(ROOT用户) */
+      businessTypes?: string[] | null;
     }
   }
 }

+ 2 - 0
src/typings/api/system-manage.d.ts

@@ -70,6 +70,8 @@ declare namespace Api {
       status: number;
       roleIdList: string;
       depts: DepartmentModel[];
+      /** 业务类型权限列表 */
+      businessTypeList?: string[];
     };
     type CommonSearchParams = Pick<Common.PaginatingCommonParams, 'current' | 'size'>;
     type RoleMenuList = {

+ 2 - 2
src/views/order-manage/after-sales-order/index.vue

@@ -10,7 +10,7 @@ import {
 // import { copyTextToClipboard } from '@/utils/zt';
 import { useTable } from '@/components/zt/Table/hooks/useTable';
 // import { type } from '../../../../packages/axios/src/index';
-import { DJKOrderStatus, SearchForm, businessType, orderStatus, refundOrderStatus } from '../normal-order/normal-order';
+import { DJKOrderStatus, SearchForm, businessType, getSearchForm, orderStatus, refundOrderStatus } from '../normal-order/normal-order';
 const router = useRouter();
 // const ShipmentModal = useTemplateRef('Shipment');
 const columns: NaiveUI.TableColumn<Api.delivery.deliveryOrder>[] = [
@@ -108,7 +108,7 @@ const columns: NaiveUI.TableColumn<Api.delivery.deliveryOrder>[] = [
 const [registerTable] = useTable({
   searchFormConfig: {
     schemas: [
-      ...SearchForm,
+      ...getSearchForm(),
       {
         label: '售后编号',
         component: 'NInput',

+ 2 - 2
src/views/order-manage/normal-order/index.vue

@@ -18,7 +18,7 @@ import { commonExport } from '@/utils/common';
 import { useModal } from '@/components/zt/Modal/hooks/useModal';
 import { useTable } from '@/components/zt/Table/hooks/useTable';
 // import { type } from '../../../../packages/axios/src/index';
-import { DJKOrderStatus, SearchForm, businessType, orderStatus } from './normal-order';
+import { DJKOrderStatus, SearchForm, businessType, getSearchForm, orderStatus } from './normal-order';
 const router = useRouter();
 const route = useRoute();
 const activeTab = ref('all');
@@ -104,7 +104,7 @@ const columns: NaiveUI.TableColumn<Api.delivery.deliveryOrder>[] = [
 
 const [registerTable, { refresh, setTableLoading, getSeachForm, getTableData, setFieldsValue }] = useTable({
   searchFormConfig: {
-    schemas: [...SearchForm]
+    schemas: [...getSearchForm()]
   },
   tableConfig: {
     keyField: 'id',

+ 35 - 0
src/views/order-manage/normal-order/normal-order.ts

@@ -4,6 +4,7 @@ import { NFlex, NImage, NTag } from 'naive-ui';
 import { fetchGetStoreList } from '@/service/api/xsb-manage/store-info';
 import { fetchGetDictDataList } from '@/service/api/system-manage';
 // import { useAuth } from '@/hooks/business/auth';
+import { useAuthStore } from '@/store/modules/auth';
 import type { FormSchema } from '@/components/zt/Form/types/form';
 
 export const SearchForm: FormSchema[] = [
@@ -120,6 +121,40 @@ export const SearchForm: FormSchema[] = [
   // }
 ];
 
+/**
+ * 获取搜索表单schema,业务类型下拉框根据当前用户权限过滤
+ * ROOT用户:显示全量字典选项
+ * 非ROOT用户:只显示有权限的业务类型
+ */
+export function getSearchForm(): FormSchema[] {
+  const authStore = useAuthStore();
+  const userBusinessTypes = authStore.userInfo.businessTypes;
+
+  // businessTypes 为 null 或 undefined 表示不限制(ROOT用户),使用原始ApiSelect拉全量
+  if (!userBusinessTypes || userBusinessTypes.length === 0) {
+    return [...SearchForm];
+  }
+
+  // 非ROOT用户:用NSelect + 静态选项,只显示有权限的业务类型
+  const filteredOptions = userBusinessTypes.map(type => ({
+    label: businessType[type as keyof typeof businessType] || type,
+    value: type
+  }));
+
+  return SearchForm.map(schema => {
+    if (schema.field === 'businessType') {
+      return {
+        ...schema,
+        component: 'NSelect',
+        componentProps: {
+          options: filteredOptions
+        }
+      };
+    }
+    return schema;
+  });
+}
+
 export enum orderStatusEnum {
   /**
    *