refactor(api): 重构信用模块API请求和数据作用域逻辑

- 将companyId API中的参数处理改为查询字符串拼接方式
- 优化数据作用域工具函数,改用Taro存储并增加H5降级方案
- 统一所有信用相关API的响应数据结构访问方式
- 将API请求方法调用格式统一为更简洁的形式
- 修改文件上传接口的headers字段名为header以适配Taro
- 更新批量删除接口的数据传递方式为直接传递数组参数
This commit is contained in:
2026-03-05 12:13:46 +08:00
parent 6e6fd43017
commit 31098f889b
31 changed files with 990 additions and 1085 deletions

View File

@@ -1,5 +1,5 @@
import Taro from '@tarojs/taro';
import { hasRole } from '@/utils/permission';
import { useUserStore } from '@/store/modules/user';
function isSuperAdmin(): boolean {
try {
@@ -11,20 +11,22 @@ function isSuperAdmin(): boolean {
function getCurrentUserId(): number | undefined {
try {
const store = useUserStore();
const id = store?.info?.userId;
if (typeof id === 'number' && Number.isFinite(id) && id > 0) {
return id;
}
const raw = Taro.getStorageSync('UserId');
const n = Number(raw);
if (Number.isFinite(n) && n > 0) return n;
} catch {
// Pinia may not be active in some early-init code paths.
// ignore
}
const raw = localStorage.getItem('UserId');
if (!raw) {
// H5 fallback
try {
const raw = typeof localStorage !== 'undefined' ? localStorage.getItem('UserId') : null;
if (!raw) return undefined;
const n = Number(raw);
return Number.isFinite(n) && n > 0 ? n : undefined;
} catch {
return undefined;
}
const n = Number(raw);
return Number.isFinite(n) && n > 0 ? n : undefined;
}
/**
@@ -43,7 +45,7 @@ export function withCreditUserScope<T extends Record<string, any> | undefined>(
return params;
}
if (!params) {
return { userId } as T;
return ({ userId } as unknown) as T;
}
return { ...(params as any), userId } as T;
}