优化: 修复安全隐患、路由权限、环境变量、CSS问题,新增组件,清理无用文件
This commit is contained in:
@@ -2,8 +2,7 @@ import axios from 'axios'
|
||||
|
||||
// 创建大乐透专用的axios实例
|
||||
const dltApi = axios.create({
|
||||
// baseURL: 'http://localhost:8123/api',
|
||||
baseURL: 'https://www.yicaishuzhi.com/api',
|
||||
baseURL: import.meta.env.VITE_API_BASE_URL,
|
||||
timeout: 300000, // 5分钟超时时间
|
||||
withCredentials: true, // 关键:支持跨域携带cookie和session
|
||||
headers: {
|
||||
@@ -19,10 +18,28 @@ dltApi.interceptors.response.use(
|
||||
// 检查是否是session过期的响应
|
||||
if (data && data.success === false) {
|
||||
const message = data.message || ''
|
||||
|
||||
// 专门处理账号在其他设备登录的情况
|
||||
if (message.includes('其他设备登录') || message.includes('当前会话已失效')) {
|
||||
console.log('检测到账号在其他设备登录,正在踢出当前会话...')
|
||||
|
||||
import('element-plus').then(({ ElMessage }) => {
|
||||
ElMessage.warning({
|
||||
message: '您的账号已在其他设备登录,请重新登录',
|
||||
duration: 3000,
|
||||
showClose: true
|
||||
})
|
||||
})
|
||||
|
||||
import('../../store/user.js').then(({ userStore }) => {
|
||||
userStore.logout(true)
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
if (message.includes('未登录') || message.includes('登录过期') || message.includes('无权限') || message.includes('Invalid session')) {
|
||||
console.log('检测到session过期,清除本地登录状态')
|
||||
|
||||
// 动态导入userStore避免循环依赖
|
||||
import('../../store/user.js').then(({ userStore }) => {
|
||||
userStore.logout()
|
||||
})
|
||||
|
||||
@@ -2,8 +2,7 @@ import axios from 'axios'
|
||||
|
||||
// 创建axios实例
|
||||
const api = axios.create({
|
||||
// baseURL: 'http://localhost:8123/api',
|
||||
baseURL: 'https://www.yicaishuzhi.com/api',
|
||||
baseURL: import.meta.env.VITE_API_BASE_URL,
|
||||
timeout: 300000, // 5分钟超时时间(300秒)
|
||||
withCredentials: true, // 关键:支持跨域携带cookie和session
|
||||
headers: {
|
||||
@@ -142,6 +141,32 @@ export const lotteryApi = {
|
||||
return api.get('/user/get/login')
|
||||
},
|
||||
|
||||
// 获取用户信息(用于编辑)
|
||||
getUserInfo() {
|
||||
return api.get('/user/get/login')
|
||||
},
|
||||
|
||||
// 更新用户信息
|
||||
updateUserInfo(userInfo) {
|
||||
console.log('调用更新用户信息接口:', userInfo)
|
||||
return api.post('/user/update', userInfo, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 上传文件
|
||||
uploadFile(file) {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
return api.post('/file/upload', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 获取用户统计信息(总用户数和VIP用户数)
|
||||
getUserCount() {
|
||||
return api.get('/user/count')
|
||||
@@ -489,33 +514,11 @@ export const lotteryApi = {
|
||||
return api.get(`/operation-history/user/${userId}/module/${operationModule}`)
|
||||
},
|
||||
|
||||
// 管理员登录
|
||||
// 管理员登录(复用用户登录接口,后台会根据角色判断权限)
|
||||
adminLogin(username, password) {
|
||||
// 模拟API请求,实际项目中应该调用真实的后端API
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
// 模拟验证管理员账号密码
|
||||
if (username === 'admin' && password === '123456') {
|
||||
resolve({
|
||||
success: true,
|
||||
data: {
|
||||
id: 1,
|
||||
userName: '系统管理员',
|
||||
userAccount: 'admin',
|
||||
userRole: 'admin',
|
||||
avatar: null,
|
||||
createTime: new Date().toISOString()
|
||||
},
|
||||
message: '登录成功'
|
||||
})
|
||||
} else {
|
||||
resolve({
|
||||
success: false,
|
||||
data: null,
|
||||
message: '账号或密码错误'
|
||||
})
|
||||
}
|
||||
}, 1000) // 模拟网络延迟
|
||||
return api.post('/user/login', {
|
||||
userAccount: username,
|
||||
userPassword: password
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user