feat(contract-payment): 采购合同付款预警

This commit is contained in:
sophie committed 2026-09-02 11:27:10 +08:00
1 parent 5aa431cc8e
commit 03e5e88e27
113 files changed
+11381 -2991

No files matched your search

+24 -16
View File
@@ -1,6 +1,8 @@
/**
* features/auth/stores/auth.store.ts
* 认证全局状态;Phase 0 仍委托 utils/auth 读写 storage。
* 依赖:shared/utils/auth、contract-payment 权限常量。
* 逻辑:登录态同步到 Pinia;hasFeaturePermission 供路由守卫与侧栏判断专项权限。
*/
import { defineStore } from 'pinia';
import { computed, ref } from 'vue';
@@ -11,24 +13,12 @@ import {
saveAuthUser,
logoutAuth as logoutAuthStorage,
refreshAccessToken as refreshAccessTokenStorage,
type AuthUser,
type FeaturePermissions,
} from '@/shared/utils/auth';
import { CONTRACT_PAYMENT_ACCESS_PERMISSION } from '@/features/contract-payment/constants';
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;
};
token?: string;
access_token?: string;
refresh_token?: string;
expires_in?: number;
token_expires_at?: number;
}
export type { AuthUser, FeaturePermissions };
let _syncBound = false;
@@ -44,6 +34,23 @@ export const useAuthStore = defineStore('auth', () => {
const isGuest = computed(() => user.value?.role === 'guest');
const token = computed(() => getAuthToken());
/**
* 判断当前登录用户是否具备指定功能权限。
* 核心逻辑:读取登录态 feature_permissions 的显式布尔值;键缺失时,合同付款访问与后端角色默认对齐(admin 为 true),避免权限键新增前写入的旧会话被误拦。
* @param permissionKey - 后端 User.get_feature_permissions 下发的键
* @returns 显式为 true,或键缺失且命中角色默认时返回 true
*/
const hasFeaturePermission = (permissionKey: string): boolean => {
const bag = user.value?.feature_permissions;
if (bag && Object.prototype.hasOwnProperty.call(bag, permissionKey)) {
return Boolean(bag[permissionKey]);
}
if (permissionKey === CONTRACT_PAYMENT_ACCESS_PERMISSION) {
return user.value?.role === 'admin';
}
return false;
};
const login = (nextUser: AuthUser, remember = false): void => {
saveAuthUser(nextUser, remember);
syncFromStorage();
@@ -68,6 +75,7 @@ export const useAuthStore = defineStore('auth', () => {
isAdmin,
isGuest,
token,
hasFeaturePermission,
syncFromStorage,
login,
logout,