chore: initial baseline with P0-safety .gitignore
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
// =============================================================================
|
||||
// IT智能服务台 — Portal API 层
|
||||
// =============================================================================
|
||||
// 说明:封装所有与后端 API 的交互
|
||||
// =============================================================================
|
||||
|
||||
import axios from 'axios'
|
||||
|
||||
// 创建 axios 实例
|
||||
const apiClient = axios.create({
|
||||
baseURL: '/api',
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
})
|
||||
|
||||
// 请求拦截器:添加 Token
|
||||
apiClient.interceptors.request.use(
|
||||
(config) => {
|
||||
// 从 localStorage 获取 Token
|
||||
const token = localStorage.getItem('portal_token')
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
return config
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
// 响应拦截器:处理错误
|
||||
apiClient.interceptors.response.use(
|
||||
(response) => {
|
||||
return response
|
||||
},
|
||||
(error) => {
|
||||
// 401 错误:Token 过期或无效
|
||||
if (error.response?.status === 401) {
|
||||
// 清除本地存储的 Token
|
||||
localStorage.removeItem('portal_token')
|
||||
localStorage.removeItem('portal_user')
|
||||
// 跳转到选择页
|
||||
window.location.href = '/itportal/select'
|
||||
}
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
export default apiClient
|
||||
@@ -0,0 +1,67 @@
|
||||
// =============================================================================
|
||||
// IT智能服务台 — Portal API 接口
|
||||
// =============================================================================
|
||||
// 说明:Portal 统一入口相关的 API 接口
|
||||
// =============================================================================
|
||||
|
||||
import apiClient from './index'
|
||||
|
||||
// 角色信息接口
|
||||
export interface Role {
|
||||
id: string
|
||||
name: string
|
||||
display_name: string
|
||||
description: string | null
|
||||
permissions: string[]
|
||||
is_default: boolean
|
||||
user_count: number | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
// 用户信息接口
|
||||
export interface UserInfo {
|
||||
employee_id: string
|
||||
name: string
|
||||
department: string | null
|
||||
avatar: string | null
|
||||
roles: Role[]
|
||||
current_role: string
|
||||
}
|
||||
|
||||
// 角色切换响应接口
|
||||
export interface SwitchRoleResponse {
|
||||
current_role: string
|
||||
redirect_url: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户角色信息
|
||||
* @returns 用户信息(包含角色列表)
|
||||
*/
|
||||
export async function getUserRoles(): Promise<UserInfo> {
|
||||
const response = await apiClient.get('/portal/roles')
|
||||
return response.data.data
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换当前角色
|
||||
* @param newRole 目标角色标识
|
||||
* @returns 切换结果(包含重定向URL)
|
||||
*/
|
||||
export async function switchRole(newRole: string): Promise<SwitchRoleResponse> {
|
||||
const response = await apiClient.post('/portal/switch-role', {
|
||||
new_role: newRole,
|
||||
})
|
||||
return response.data.data
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色对应的入口 URL
|
||||
* @param roleName 角色标识
|
||||
* @returns 入口 URL 信息
|
||||
*/
|
||||
export async function getRoleEntry(roleName: string): Promise<{ role: string; url: string; display_name: string }> {
|
||||
const response = await apiClient.get(`/portal/entry/${roleName}`)
|
||||
return response.data.data
|
||||
}
|
||||
Reference in New Issue
Block a user