feat(credit): 添加企业信用模块功能
- 在应用配置中注册公司管理页面路由 - 实现首页轮播图组件优化,支持CSS尺寸转换和图片加载 - 新增企业ID修正API功能 - 实现信用模块数据权限控制工具 - 添加客户、联系人、数据查询等页面配置 - 完善行政许可、破产重整、分支机构等信用数据模型 - 实现各类信用数据的增删改查和导入导出接口 - 建立企业信用数据完整管理功能体系
This commit is contained in:
49
src/api/credit/utils/data-scope.ts
Normal file
49
src/api/credit/utils/data-scope.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { hasRole } from '@/utils/permission';
|
||||
import { useUserStore } from '@/store/modules/user';
|
||||
|
||||
function isSuperAdmin(): boolean {
|
||||
try {
|
||||
return hasRole('superAdmin');
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function getCurrentUserId(): number | undefined {
|
||||
try {
|
||||
const store = useUserStore();
|
||||
const id = store?.info?.userId;
|
||||
if (typeof id === 'number' && Number.isFinite(id) && id > 0) {
|
||||
return id;
|
||||
}
|
||||
} catch {
|
||||
// Pinia may not be active in some early-init code paths.
|
||||
}
|
||||
const raw = localStorage.getItem('UserId');
|
||||
if (!raw) {
|
||||
return undefined;
|
||||
}
|
||||
const n = Number(raw);
|
||||
return Number.isFinite(n) && n > 0 ? n : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Credit module data scope:
|
||||
* - superAdmin: see all data
|
||||
* - others: only see data published by themselves (userId)
|
||||
*/
|
||||
export function withCreditUserScope<T extends Record<string, any> | undefined>(
|
||||
params: T
|
||||
): T {
|
||||
if (isSuperAdmin()) {
|
||||
return params;
|
||||
}
|
||||
const userId = getCurrentUserId();
|
||||
if (!userId) {
|
||||
return params;
|
||||
}
|
||||
if (!params) {
|
||||
return { userId } as T;
|
||||
}
|
||||
return { ...(params as any), userId } as T;
|
||||
}
|
||||
Reference in New Issue
Block a user