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:
Hermes CI Fix
2026-08-11 11:29:39 +08:00
parent 12f9ae520b
commit 9986f38faa
11 changed files with 116 additions and 58 deletions
+23 -12
View File
@@ -48,6 +48,7 @@
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import api from '../api/index'
import {
User, Monitor, Document, TrendCharts, WarningFilled, Connection,
@@ -61,25 +62,35 @@ const router = useRouter()
const isCollapse = ref(false)
const mobileMenuOpen = ref(false)
// ── 全局企业切换 ──
// ── 全局企业切换(账套模式:switch-entity 重新签发token + 整页刷新) ──
const entities = ref<any[]>([])
const currentEntityId = ref(Number(localStorage.getItem('cma_entity_id') || 1))
const currentEntityName = ref(localStorage.getItem('cma_entity_name') || '酣客')
function onEntityChange(id: number) {
currentEntityId.value = id
const e = entities.value.find((x: any) => x.id === id)
currentEntityName.value = e?.short_name || e?.name || ''
localStorage.setItem('cma_entity_id', String(id))
localStorage.setItem('cma_entity_name', currentEntityName.value)
// 多租户联动:通知后端记录当前tenant(供项目Bot A2A分发)
async function onEntityChange(id: number) {
if (id === Number(localStorage.getItem('cma_entity_id'))) return
try {
api.post('/tenant/switch', { entity_id: id, source: 'cma-frontend' })
} catch (_) {}
location.reload()
const r: any = await api.post('/auth/switch-entity', {
entity_id: id,
from_entity_id: Number(localStorage.getItem('cma_entity_id') || 1),
})
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 || '')
// 多租户联动:通知后端记录当前tenant(供项目Bot A2A分发)
try {
api.post('/tenant/switch', { entity_id: r.entity_id, source: 'cma-frontend' })
} catch (_) {}
location.reload()
} catch (e: any) {
currentEntityId.value = Number(localStorage.getItem('cma_entity_id') || 1)
const msg = e?.response?.data?.detail || '切换失败'
ElMessage.error(msg)
}
}
onMounted(async () => {
// 账套模式:切换器只显示当前用户被授权的企业
try {
const r: any = await api.get('/entities')
const r: any = await api.get('/auth/my-entities')
entities.value = r.data || r || []
} catch (_) {}
})