feat(ui): remove in-app entity switcher, entity fixed at login
- MainLayout/ReportCenter: drop switch-entity switcher, keep read-only entity tag - KPIList/PredictDashboard/GrowthQuality: entity selectors locked to session entity - api/index.ts: drop switchEntity/myEntities wrappers (endpoint kept for compat) - sidebar brand now shows logged-in entity name (cma-remove-inapp-entity-switcher-20260914)
This commit is contained in:
@@ -28,12 +28,8 @@
|
||||
<span class="page-title">{{ pageTitle }}</span>
|
||||
</div>
|
||||
<div class="header-right">
|
||||
<!-- 固定企业版(Phase C):显示当前企业 tag 代替切换器 -->
|
||||
<el-tag v-if="isFixedEntity()" size="small" type="primary" effect="plain" class="entity-tag">{{ currentEntityName }}</el-tag>
|
||||
<!-- 企业切换器:仅非固定版且授权企业≥2时显示(多企业用户),固定版/单企业用户隐藏避免UI噪音 -->
|
||||
<el-select v-else-if="entities.length >= 2" v-model="currentEntityId" @change="onEntityChange" size="small" style="width:120px;margin-right:8px;">
|
||||
<el-option v-for="e in entities" :key="e.id" :label="e.short_name || e.name" :value="e.id" />
|
||||
</el-select>
|
||||
<!-- 企业只读标识(不可点):账套由登录窗口选定,应用内无切换入口(换企业须退出重登) -->
|
||||
<el-tag size="small" type="primary" effect="plain" class="entity-tag">{{ currentEntityName }}</el-tag>
|
||||
<el-tag size="small" :type="roleTagType">{{ roleLabel }}</el-tag>
|
||||
<el-dropdown trigger="click">
|
||||
<span class="user-info"><el-icon><User /></el-icon>{{ userName }}</span>
|
||||
@@ -49,62 +45,29 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { ref, computed } 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,
|
||||
Menu, Bell, Setting, Coin, DataAnalysis, Money, DataLine,
|
||||
DataBoard, Tools, Collection, Edit, Reading, Opportunity, PieChart,
|
||||
} from '@element-plus/icons-vue'
|
||||
import { MENU_ITEMS, ROLE_LABELS } from '../permission'
|
||||
import { isFixedEntity } from '../utils/entity'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const isCollapse = ref(false)
|
||||
const mobileMenuOpen = ref(false)
|
||||
|
||||
// 侧边栏品牌:固定企业版带企业名(如「陕西酣客 · 管理会计OS」),切换版保持原名
|
||||
// 侧边栏品牌:带当前登录企业名(如「陕西酣客 · 管理会计OS」),账套由登录窗口选定
|
||||
const logoText = computed(() => {
|
||||
if (isFixedEntity() && currentEntityName.value) return `${currentEntityName.value} · 管理会计OS`
|
||||
if (currentEntityName.value) return `${currentEntityName.value} · 管理会计OS`
|
||||
return '管理会计OS'
|
||||
})
|
||||
|
||||
// ── 全局企业切换(账套模式:switch-entity 重新签发token + 整页刷新) ──
|
||||
const entities = ref<any[]>([])
|
||||
const currentEntityId = ref(Number(localStorage.getItem('cma_entity_id') || 1))
|
||||
// ── 当前企业(只读标识):2026-09-14 需求——取消应用内企业切换,
|
||||
// 账套由登录窗口选定(localStorage.cma_entity_id 登录时写入),本页不再加载授权企业列表、不再调 switch-entity。
|
||||
const currentEntityName = ref(localStorage.getItem('cma_entity_name') || '酣客')
|
||||
async function onEntityChange(id: number) {
|
||||
if (id === Number(localStorage.getItem('cma_entity_id'))) return
|
||||
try {
|
||||
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 () => {
|
||||
// 账套模式:切换器只显示当前用户被授权的企业;固定企业版无切换需求,跳过列表加载
|
||||
if (isFixedEntity()) return
|
||||
try {
|
||||
const r: any = await api.get('/auth/my-entities')
|
||||
entities.value = r.data || r || []
|
||||
} catch (_) {}
|
||||
})
|
||||
|
||||
// 图标名称 → 组件实例映射
|
||||
const iconMap: Record<string, any> = {
|
||||
|
||||
Reference in New Issue
Block a user