- Spring Boot 后端服务 (hss-home-service) - delivery-miniapp 配送小程序 - website 官网 (Nuxt) - docs 架构设计文档 - Docker 容器化部署配置 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
91 lines
2.9 KiB
TypeScript
91 lines
2.9 KiB
TypeScript
import { ref, computed } from 'vue'
|
|
|
|
export interface PlatformUser {
|
|
userId: string
|
|
userName: string
|
|
userRole: string
|
|
tenantId: string
|
|
orgId: string
|
|
}
|
|
|
|
const ROLES = [
|
|
{ key: 'ADMIN', label: '系统管理员' },
|
|
{ key: 'RECEPTIONIST', label: '受理员' },
|
|
{ key: 'ASSESSOR', label: '评估员' },
|
|
{ key: 'PLANNER', label: '方案制定员' },
|
|
{ key: 'DISPATCHER', label: '调度员' },
|
|
{ key: 'STAFF', label: '服务人员' },
|
|
{ key: 'SETTLER', label: '结算员' },
|
|
{ key: 'SUPERVISOR', label: '监管员' },
|
|
{ key: 'REVIEWER', label: '复核员' },
|
|
]
|
|
|
|
const PRESET_USERS: Record<string, PlatformUser> = {
|
|
admin: { userId: '1', userName: '系统管理员', userRole: 'ADMIN', tenantId: '1', orgId: '1' },
|
|
receptionist: { userId: '2', userName: '受理员小王', userRole: 'RECEPTIONIST', tenantId: '1', orgId: '1' },
|
|
assessor: { userId: '3', userName: '评估员老张', userRole: 'ASSESSOR', tenantId: '1', orgId: '1' },
|
|
planner: { userId: '4', userName: '方案员小李', userRole: 'PLANNER', tenantId: '1', orgId: '1' },
|
|
dispatcher: { userId: '5', userName: '调度员老赵', userRole: 'DISPATCHER', tenantId: '1', orgId: '1' },
|
|
staff: { userId: '6', userName: '护理员老陈', userRole: 'STAFF', tenantId: '1', orgId: '1' },
|
|
settler: { userId: '7', userName: '结算员小周', userRole: 'SETTLER', tenantId: '1', orgId: '1' },
|
|
supervisor: { userId: '8', userName: '监管员老刘', userRole: 'SUPERVISOR', tenantId: '1', orgId: '1' },
|
|
}
|
|
|
|
const STORAGE_KEY = 'hss_platform_user'
|
|
|
|
const currentUser = ref<PlatformUser | null>(null)
|
|
|
|
function loadUser(): PlatformUser | null {
|
|
try {
|
|
const stored = localStorage.getItem(STORAGE_KEY)
|
|
return stored ? JSON.parse(stored) : null
|
|
} catch { return null }
|
|
}
|
|
|
|
function saveUser(user: PlatformUser) {
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(user))
|
|
currentUser.value = user
|
|
}
|
|
|
|
function clearUser() {
|
|
localStorage.removeItem(STORAGE_KEY)
|
|
currentUser.value = null
|
|
}
|
|
|
|
export function usePlatformAuth() {
|
|
if (!currentUser.value) {
|
|
currentUser.value = loadUser()
|
|
}
|
|
|
|
const isLoggedIn = computed(() => !!currentUser.value)
|
|
const user = computed(() => currentUser.value)
|
|
|
|
function login(username: string): PlatformUser | null {
|
|
const u = PRESET_USERS[username.toLowerCase()]
|
|
if (u) { saveUser(u); return u }
|
|
return null
|
|
}
|
|
|
|
function logout() { clearUser() }
|
|
|
|
function switchRole(roleKey: string) {
|
|
if (!currentUser.value) return
|
|
const updated = { ...currentUser.value, userRole: roleKey }
|
|
saveUser(updated)
|
|
}
|
|
|
|
function getAuthHeaders(): Record<string, string> {
|
|
const u = currentUser.value
|
|
if (!u) return {}
|
|
return {
|
|
'X-User-Id': u.userId,
|
|
'X-User-Role': u.userRole,
|
|
'X-Tenant-Id': u.tenantId,
|
|
'X-Org-Id': u.orgId,
|
|
'Content-Type': 'application/json',
|
|
}
|
|
}
|
|
|
|
return { isLoggedIn, user, login, logout, switchRole, getAuthHeaders, ROLES, PRESET_USERS }
|
|
}
|