feat(bx-mobile): add bxClient and retarget business APIs to shanxia2.0
Remove legacy bx user/role/menu/auth APIs. Wire auth store to portal temporarily so the app still typechecks; IAM admin pages use local stubs until Task 6 drops their routes. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
c7a8930ad6
commit
3f1faeae34
9 files changed
+340
-262
No files matched your search
@@ -1,64 +1 @@
|
||||
import axios from 'axios'
|
||||
import { showToast } from 'vant'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
const client = axios.create({
|
||||
baseURL: '/api',
|
||||
timeout: 0, // 0 = no timeout
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
|
||||
client.interceptors.request.use((config) => {
|
||||
const token = localStorage.getItem('token')
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
return config
|
||||
})
|
||||
|
||||
/**
|
||||
* Business error marker — page-level catch blocks should check this
|
||||
* to avoid double-toasting (interceptor already showed the toast).
|
||||
*/
|
||||
export class BizError extends Error {
|
||||
code?: number
|
||||
constructor(message: string, code?: number) {
|
||||
super(message)
|
||||
this.code = code
|
||||
this.name = 'BizError'
|
||||
}
|
||||
}
|
||||
|
||||
client.interceptors.response.use(
|
||||
(res) => {
|
||||
const body = res.data
|
||||
if (body.code !== 0 && body.code !== undefined) {
|
||||
showToast(body.msg || '请求失败')
|
||||
return Promise.reject(new BizError(body.msg || '请求失败', body.code))
|
||||
}
|
||||
return body
|
||||
},
|
||||
(err) => {
|
||||
if (err.response?.status === 401) {
|
||||
const auth = useAuthStore()
|
||||
auth.logout()
|
||||
showToast('登录已过期,请重新登录')
|
||||
if (window.location.pathname !== '/login') {
|
||||
window.location.href = '/login'
|
||||
}
|
||||
} else if (err.response?.status === 403 && err.response?.data?.detail === '用户已被禁用') {
|
||||
const auth = useAuthStore()
|
||||
auth.logout()
|
||||
showToast('账号已被禁用,请联系管理员')
|
||||
if (window.location.pathname !== '/login') {
|
||||
window.location.href = '/login'
|
||||
}
|
||||
} else {
|
||||
const msg = err.response?.data?.msg || err.response?.data?.detail || err.message || '网络异常'
|
||||
showToast(msg)
|
||||
}
|
||||
return Promise.reject(err)
|
||||
},
|
||||
)
|
||||
|
||||
export default client
|
||||
export { default, BizError } from './bxClient'
|
||||
Reference in new issue
Block a user