feat(frontend): Phase C 固定企业模式 - VITE_FIXED_ENTITY_ID 支持登录无下拉/隐藏切换器

- 新增 src/utils/entity.ts: isFixedEntity/getFixedEntityId/effectiveEntityId
- Login.vue: 固定企业版隐藏企业下拉显示只读徽标, 登录直接带固定 entity_id
- MainLayout.vue: 切换器加 !isFixedEntity() 守卫, 固定版顶部显示企业 tag, logo 带企业名
- ReportCenter.vue: 页内企业切换下拉加守卫, getEntityId 固定版恒取构建锁定值
- .env.example: VITE_FIXED_ENTITY_ID 示例与说明
- 验证脚本 backend/scripts/verify_phase_c_fixed_entity_e2e.py (22项, 双build E2E全过)
This commit is contained in:
Hermes CI Fix
2026-09-08 11:27:01 +08:00
parent 193061cf4d
commit ebe0962c09
6 changed files with 388 additions and 13 deletions
+18 -3
View File
@@ -4,7 +4,10 @@
<div class="report-header">
<h3 class="page-title">📊 CMA管理报表</h3>
<div class="header-right">
<!-- 固定企业版(Phase C):页内切换下拉隐藏,显示当前企业 tag -->
<el-tag v-if="isFixedEntity()" size="small" type="primary" effect="plain">{{ currentEntityNameTag }}</el-tag>
<el-select
v-else
v-model="currentEntityId"
size="small"
style="width:180px"
@@ -624,9 +627,10 @@
</template>
<script setup lang="ts">
import { ref, reactive, onMounted, nextTick } from 'vue'
import { ref, reactive, computed, onMounted, nextTick } from 'vue'
import { ElMessage } from 'element-plus'
import axios from 'axios'
import { isFixedEntity, getFixedEntityId } from '../utils/entity'
// ── 状态 ──
const loading = ref(false)
@@ -637,7 +641,17 @@ const reportPeriod = ref('2026-06')
const entities = ref<any[]>([])
const currentEntityId = ref(Number(localStorage.getItem('cma_entity_id') || 1))
// 固定企业版:页内切换下拉隐藏,右上角显示当前企业 tag
const currentEntityNameTag = computed(() => {
const f = getFixedEntityId()
const n = localStorage.getItem('cma_entity_name')
return n || (f !== undefined ? `企业 #${f}` : '')
})
function getEntityId() {
// 固定企业版恒取构建锁定值(防 localStorage 残留串账套);切换版取登录/切换写入值
const f = getFixedEntityId()
if (f !== undefined) return f
return Number(localStorage.getItem('cma_entity_id') || currentEntityId.value || 1)
}
@@ -667,9 +681,10 @@ async function onEntityChange(id: number) {
}
}
// 跨页面同步:其他页面切换企业时联动刷新
// 跨页面同步:其他页面切换企业时联动刷新(固定企业版忽略——该版本不存在切换)
if (typeof window !== 'undefined') {
window.addEventListener('storage', (ev: StorageEvent) => {
if (isFixedEntity()) return
if (ev.key === 'cma_entity_id' && ev.newValue) {
currentEntityId.value = Number(ev.newValue)
loadAll()
@@ -1063,7 +1078,7 @@ function onBudgetSort(sort: any) {
}
onMounted(() => {
loadEntities()
if (!isFixedEntity()) loadEntities()
loadKpiOptions()
loadAll()
loadStatutory()