feat(contract-payment): 采购合同付款预警
This commit is contained in:
1 parent
5aa431cc8e
commit
03e5e88e27
113 files changed
+11381
-2991
No files matched your search
@@ -2,18 +2,21 @@
|
||||
* shared/utils/auth.ts
|
||||
* 用途:统一封装登录态、记住我偏好、登录页账号密码自动回填、跨标签登出同步等认证相关本地存储能力。
|
||||
* 依赖:浏览器 localStorage/sessionStorage、Casdoor refresh 接口。
|
||||
* 逻辑:把“认证凭据”和“登录页自动回填资料”分开管理,既支持 30 天免登录,也支持按业务确认方案回填账号密码。
|
||||
* 逻辑:把“认证凭据”和“登录页自动回填资料”分开管理,既支持 30 天免登录,也支持按业务确认方案回填账号密码;首页刷新可通过 patchStoredAuthUser 就地更新功能权限。
|
||||
*/
|
||||
export type FeaturePermissions = {
|
||||
training_hr_manage?: boolean;
|
||||
'contract_payment.access'?: boolean;
|
||||
[key: string]: boolean | undefined;
|
||||
};
|
||||
|
||||
export interface AuthUser {
|
||||
id?: number;
|
||||
username?: string;
|
||||
real_name?: string;
|
||||
employee_id?: string;
|
||||
role?: string;
|
||||
feature_permissions?: {
|
||||
training_hr_manage?: boolean;
|
||||
[key: string]: boolean | undefined;
|
||||
};
|
||||
feature_permissions?: FeaturePermissions;
|
||||
token?: string;
|
||||
access_token?: string;
|
||||
refresh_token?: string;
|
||||
@@ -107,6 +110,27 @@ export const getStoredAuthUser = (): AuthUser | null => {
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 就地更新当前登录用户的若干字段,不改变 remember / expiry 所在存储。
|
||||
* 核心逻辑:按 sessionStorage → localStorage 找到现有 payload,合并 partial 后写回同一位置。
|
||||
* @param partial - 需要覆盖的用户字段(如首页刷新得到的 feature_permissions)
|
||||
* @returns 合并后的用户;当前没有登录态时返回 null
|
||||
*/
|
||||
export const patchStoredAuthUser = (partial: Partial<AuthUser>): AuthUser | null => {
|
||||
const candidates: Array<[Storage, string]> = [
|
||||
[sessionStorage, AUTH_USER_KEY],
|
||||
[localStorage, AUTH_USER_KEY],
|
||||
];
|
||||
for (const [storage, key] of candidates) {
|
||||
const payload = readStoredAuthPayload(storage, key);
|
||||
if (!payload?.user) continue;
|
||||
const nextUser = { ...payload.user, ...partial };
|
||||
storage.setItem(key, JSON.stringify({ ...payload, user: nextUser }));
|
||||
return nextUser;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
export const getAuthToken = (): string => {
|
||||
const user = getStoredAuthUser();
|
||||
const token = user?.access_token || user?.token;
|
||||
|
||||
@@ -31,3 +31,40 @@ export function formatLocalDateTime(iso?: string | null): string {
|
||||
const pad = (n: number) => String(n).padStart(2, '0');
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format an API timestamp as `YYYY-MM-DD HH:mm:ss`, preserving the source wall-clock time.
|
||||
* Use for OA-sourced naive timestamps (e.g. contract archive date) where the stored value is the
|
||||
* local time as shown on the source page and must NOT be shifted by the browser timezone.
|
||||
* Backend may serialize microseconds (e.g. `...26.660127`); they are trimmed for reliable parsing.
|
||||
* Empty values return `-`; invalid dates fall back to the original string for troubleshooting.
|
||||
*
|
||||
* @param iso - API timestamp string.
|
||||
* @returns Wall-clock display text.
|
||||
*/
|
||||
export function formatNaiveDateTime(iso?: string | null): string {
|
||||
if (!iso) return '-';
|
||||
const normalized = iso.replace(/(\.\d{3})\d+/, '$1');
|
||||
const d = new Date(normalized);
|
||||
if (Number.isNaN(d.getTime())) return iso;
|
||||
const pad = (n: number) => String(n).padStart(2, '0');
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format an API timestamp as `YYYY-MM-DD`, preserving the source wall-clock day.
|
||||
* Use for OA-sourced naive timestamps (e.g. contract archive date) where only the date is
|
||||
* meaningful and the trailing time part must not be shown. Parsing mirrors formatNaiveDateTime.
|
||||
* Empty values return `-`; invalid dates fall back to the original string for troubleshooting.
|
||||
*
|
||||
* @param iso - API timestamp string.
|
||||
* @returns Wall-clock date text (`YYYY-MM-DD`).
|
||||
*/
|
||||
export function formatNaiveDate(iso?: string | null): string {
|
||||
if (!iso) return '-';
|
||||
const normalized = iso.replace(/(\.\d{3})\d+/, '$1');
|
||||
const d = new Date(normalized);
|
||||
if (Number.isNaN(d.getTime())) return iso;
|
||||
const pad = (n: number) => String(n).padStart(2, '0');
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
||||
}
|
||||
Reference in new issue
Block a user