feat: 多租户实时切换 — 前端拦截器统一entity_id + 后端get_entity_id依赖 + dashboard 6端点支持租户过滤
- 前端: api/index.ts拦截器自动附加X-Entity-Id header + entity_id query参数 - 后端: 新增app/deps.py的get_entity_id公共依赖(query→header→默认1) - dashboard.py: summary/kpis/finance-analysis/predict/my-kpis/my-dashboard全部支持entity_id - 解决: 42个页面仅13个传entity_id导致切换企业后数据混乱
This commit is contained in:
@@ -8,6 +8,12 @@ const api = axios.create({
|
||||
api.interceptors.request.use((config) => {
|
||||
const token = localStorage.getItem('cma_token')
|
||||
if (token) config.headers.Authorization = `Bearer ${token}`
|
||||
// 多租户实时切换:统一附加当前企业ID(解决29个页面未传entity_id的问题)
|
||||
const entityId = Number(localStorage.getItem('cma_entity_id') || 1)
|
||||
config.headers['X-Entity-Id'] = String(entityId)
|
||||
if (config.method === 'get' || config.method === 'GET') {
|
||||
config.params = { ...(config.params || {}), entity_id: entityId }
|
||||
}
|
||||
return config
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user