fix: 修复后台登录后被401误踢出及配置页账号字段
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -34,9 +34,15 @@ service.interceptors.response.use(
|
||||
if (error.response) {
|
||||
const status = error.response.status
|
||||
if (status === 401) {
|
||||
localStorage.removeItem('token')
|
||||
router.push('/login')
|
||||
ElMessage.error('登录已过期,请重新登录')
|
||||
const data = error.response.data || {}
|
||||
const detail = typeof data.detail === 'string' ? data.detail : ''
|
||||
// 业务层 401(如 phone 校验失败)不踢登录,仅 JWT 失效才跳转
|
||||
const isBiz401 = data.code !== undefined || detail === '认证失败'
|
||||
if (!isBiz401) {
|
||||
localStorage.removeItem('token')
|
||||
router.push('/login')
|
||||
ElMessage.error('登录已过期,请重新登录')
|
||||
}
|
||||
} else if (status === 403) {
|
||||
ElMessage.error('没有权限')
|
||||
} else {
|
||||
|
||||
@@ -215,7 +215,7 @@ const toggleCollapse = () => {
|
||||
}
|
||||
|
||||
const currentTitle = computed(() => route.meta?.title || '客服终端')
|
||||
const userPhone = ref(localStorage.getItem('username') || '未知账号')
|
||||
const userPhone = ref((localStorage.getItem('username') || '未知账号').trim())
|
||||
|
||||
const stats = ref({
|
||||
jinrichuli: 0,
|
||||
|
||||
@@ -83,6 +83,7 @@ onMounted(() => {
|
||||
})
|
||||
|
||||
const handleLogin = async () => {
|
||||
form.username = form.username.trim()
|
||||
if (!form.username || !form.password || !form.ip) {
|
||||
ElMessage.warning('请填写完整信息')
|
||||
return
|
||||
|
||||
@@ -101,7 +101,7 @@ import { ref, reactive, onMounted } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import request from '@/utils/request'
|
||||
|
||||
const zhanghao = ref(localStorage.getItem('username') || '')
|
||||
const username = ref(localStorage.getItem('username') || '')
|
||||
const hasPermission = ref(true)
|
||||
const activeTab = ref('sys')
|
||||
const ossBaseUrl = ref(window.$ossURL || '')
|
||||
@@ -137,7 +137,7 @@ const fullUrl = (path) => {
|
||||
const loadSysConfig = async () => {
|
||||
sysLoading.value = true
|
||||
try {
|
||||
const res = await request.post('/peizhi/xcxsyshq', { zhanghao: zhanghao.value })
|
||||
const res = await request.post('/peizhi/xcxsyshq', { username: username.value })
|
||||
if (res.code === 403 || res.code === 1 && res.msg?.includes('权限')) {
|
||||
hasPermission.value = false
|
||||
return
|
||||
@@ -174,7 +174,7 @@ const saveSysConfig = async () => {
|
||||
if (!payload.weixin_official_secret) delete payload.weixin_official_secret
|
||||
if (!payload.weixin_shanghu_miyao) delete payload.weixin_shanghu_miyao
|
||||
const res = await request.post('/peizhi/xcxsysgx', {
|
||||
zhanghao: zhanghao.value,
|
||||
username: username.value,
|
||||
config: payload,
|
||||
})
|
||||
if (res.code === 0) {
|
||||
@@ -194,7 +194,7 @@ const loadAssets = async () => {
|
||||
assetLoading.value = true
|
||||
try {
|
||||
const res = await request.post('/peizhi/xcxyzycx', {
|
||||
zhanghao: zhanghao.value,
|
||||
username: username.value,
|
||||
ziyuan_zu: assetGroup.value,
|
||||
})
|
||||
if (res.code === 403) {
|
||||
@@ -228,7 +228,7 @@ const saveAssets = async () => {
|
||||
ziyuan_path: row.ziyuan_path,
|
||||
}))
|
||||
const res = await request.post('/peizhi/xcxyzgx', {
|
||||
zhanghao: zhanghao.value,
|
||||
username: username.value,
|
||||
items,
|
||||
})
|
||||
if (res.code === 0) {
|
||||
@@ -246,7 +246,7 @@ const saveAssets = async () => {
|
||||
|
||||
const uploadAsset = async ({ file }, row) => {
|
||||
const formData = new FormData()
|
||||
formData.append('zhanghao', zhanghao.value)
|
||||
formData.append('username', username.value)
|
||||
formData.append('ziyuan_zu', row.ziyuan_zu)
|
||||
formData.append('ziyuan_key', row.ziyuan_key)
|
||||
formData.append('image', file)
|
||||
|
||||
Reference in New Issue
Block a user