This commit is contained in:
macbook_max
2026-10-15 20:36:59 +08:00
commit 6bf949949c
7923 changed files with 1369582 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
/**
* 管理员登录态本地存储(token + 管理员信息)
* 统一管理 localStorage key,供 axios 拦截器与 Pinia store 共用,避免循环依赖
*/
const TOKEN_KEY = 'admin_token'
const ADMIN_KEY = 'admin_info'
/** 读取管理员 Token */
export function getToken() {
return localStorage.getItem(TOKEN_KEY) || ''
}
/** 写入管理员 Token */
export function setToken(token) {
localStorage.setItem(TOKEN_KEY, token)
}
/** 读取管理员信息 { id, name, role } */
export function getAdminInfo() {
const raw = localStorage.getItem(ADMIN_KEY)
if (!raw) return null
try {
return JSON.parse(raw)
} catch {
return null
}
}
/** 写入管理员信息 */
export function setAdminInfo(info) {
localStorage.setItem(ADMIN_KEY, JSON.stringify(info || {}))
}
/** 清空登录态 */
export function clearAuth() {
localStorage.removeItem(TOKEN_KEY)
localStorage.removeItem(ADMIN_KEY)
}
+10
View File
@@ -0,0 +1,10 @@
/** 请求参数清理:剔除空字符串/空值,避免后端收到无效筛选参数 */
export function cleanParams(obj) {
const out = {}
Object.entries(obj || {}).forEach(([key, value]) => {
if (value !== '' && value !== null && value !== undefined) {
out[key] = value
}
})
return out
}
+26
View File
@@ -0,0 +1,26 @@
/**
* 敏感操作原因输入框(标注【敏感】的接口要求 reason 必填,缺失返回 4002)
* 用户取消时 reject,调用方直接 return 即可
*/
import { ElMessageBox } from 'element-plus'
export async function askReason({
title = '敏感操作确认',
message = '该操作会记录操作日志,请填写操作原因',
required = true,
maxlength = 200,
} = {}) {
const { value } = await ElMessageBox.prompt(message, title, {
confirmButtonText: '确定',
cancelButtonText: '取消',
inputType: 'textarea',
inputPlaceholder: '请填写原因(必填)',
inputValidator: (val) => {
const text = (val || '').trim()
if (required && !text) return '请填写原因'
if (text.length > maxlength) return `原因不能超过 ${maxlength} 字`
return true
},
})
return value.trim()
}