仓库初始化+岗位相关页面

This commit is contained in:
2026-03-24 21:06:00 +08:00
commit 0468339d23
113 changed files with 18644 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
/**
* 从 document.cookie 中提取指定 name 的值
*/
export function getCookie(name: string): string | null {
const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`))
return match ? decodeURIComponent(match[1]) : null
}
/**
* 判断是否已登录 — 通过 Cookie 中是否存在 Token 来判断
*/
export function isLoggedIn(): boolean {
return !!getCookie('Token')
}
+25
View File
@@ -0,0 +1,25 @@
import store from '@/stores/index'
import type { RegionItem } from '@/api/common'
/**
* 根据城市编码从 store 地区树中查找对应的城市名称
* 遍历省→市→区三级,匹配到即返回名称,未匹配返回编码本身
* @param code 地区编码(如 '130300'
* @returns 匹配到的城市名称,未匹配则返回原编码
*/
export function resolveRegionName(code: string): string {
if (!code) return ''
const regions: RegionItem[] = store.state.regions
for (const province of regions) {
if (province.code === code) return province.name
for (const city of province.children) {
if (city.code === code) return city.name
if (city.children) {
for (const district of city.children) {
if (district.code === code) return district.name
}
}
}
}
return code
}
+32
View File
@@ -0,0 +1,32 @@
import axios from 'axios'
import type { AxiosResponse } from 'axios'
/**
* 创建 axios 实例
* withCredentials: true — 浏览器自动携带 Cookie(包括 HttpOnly 的 Token
*/
const service = axios.create({
baseURL: import.meta.env.VITE_API_BASE_URL,
timeout: 15000,
withCredentials: true,
})
/**
* 响应拦截器 — 统一处理错误
*/
service.interceptors.response.use(
(response: AxiosResponse) => {
return response.data
},
(error) => {
const status = error.response?.status
if (status === 401) {
ElMessage.error('登录已过期,请重新登录')
} else {
ElMessage.error(error.response?.data?.msg || '请求失败')
}
return Promise.reject(error)
},
)
export default service