feat: 账套模式全量接入 — 12个API entity_id统一走token解析链 + 前端登录选公司/切换器重签token
- 后端: kpis/bsc_layers/cash/predict/growth_quality/tax_compliance/data 的 entity_id 参数统一改为 Depends(get_entity_id) - 前端: 拦截器删除自动附加X-Entity-Id/entity_id; 登录页公司选择器(按用户名授权过滤); 切换器改POST /auth/switch-entity重新签发token+整页刷新; ReportCenter同步改造 - 修复前后端不匹配: login-entities路由→/auth/entities; login响应entity_id取user.entity_id
This commit is contained in:
@@ -587,7 +587,7 @@ function getEntityId() {
|
||||
|
||||
async function loadEntities() {
|
||||
try {
|
||||
const r: any = await api.get('/entities')
|
||||
const r: any = await api.get('/auth/my-entities')
|
||||
entities.value = r.data || r || []
|
||||
const e = entities.value.find((x: any) => x.id === currentEntityId.value)
|
||||
if (e) localStorage.setItem('cma_entity_name', e.short_name || e.name || '')
|
||||
@@ -596,13 +596,19 @@ async function loadEntities() {
|
||||
}
|
||||
}
|
||||
|
||||
function onEntityChange(id: number) {
|
||||
localStorage.setItem('cma_entity_id', String(id))
|
||||
const e = entities.value.find((x: any) => x.id === id)
|
||||
if (e) localStorage.setItem('cma_entity_name', e.short_name || e.name || '')
|
||||
ElMessage.success(`已切换企业:${e ? e.short_name + ' / ' + e.name : id}`)
|
||||
loadAll()
|
||||
loadStatutory()
|
||||
async function onEntityChange(id: number) {
|
||||
// 账套模式:切换走 switch-entity 重新签发token + 整页刷新
|
||||
if (id === Number(localStorage.getItem('cma_entity_id'))) return
|
||||
try {
|
||||
const r: any = await api.post('/auth/switch-entity', { entity_id: id })
|
||||
localStorage.setItem('cma_token', r.token)
|
||||
localStorage.setItem('cma_entity_id', String(r.entity_id))
|
||||
localStorage.setItem('cma_entity_name', r.entity_short_name || r.entity_name || '')
|
||||
ElMessage.success(`已切换企业:${r.entity_short_name || r.entity_name || id}`)
|
||||
location.reload()
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.response?.data?.detail || '切换失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 跨页面同步:其他页面切换企业时联动刷新
|
||||
|
||||
Reference in New Issue
Block a user