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:
@@ -3,7 +3,7 @@
|
||||
<el-aside :width="isCollapse ? '64px' : '220px'" :class="{ 'mobile-show': mobileMenuOpen }">
|
||||
<div class="aside-mask" v-if="mobileMenuOpen" @click="mobileMenuOpen = false"></div>
|
||||
<div class="logo">
|
||||
<span v-show="!isCollapse">管理会计OS</span>
|
||||
<span v-show="!isCollapse">{{ logoText }}</span>
|
||||
</div>
|
||||
<el-menu :default-active="activeMenu" :collapse="isCollapse" router background-color="#304156" text-color="#bfcbd9" active-text-color="#409EFF" @select="onMenuSelect">
|
||||
<template v-for="group in menuGroups" :key="group.label">
|
||||
@@ -28,8 +28,10 @@
|
||||
<span class="page-title">{{ pageTitle }}</span>
|
||||
</div>
|
||||
<div class="header-right">
|
||||
<!-- 企业切换器:仅多企业用户显示(授权企业≥2时),单企业用户隐藏避免UI噪音 -->
|
||||
<el-select v-if="entities.length >= 2" v-model="currentEntityId" @change="onEntityChange" size="small" style="width:120px;margin-right:8px;">
|
||||
<!-- 固定企业版(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="roleTagType">{{ roleLabel }}</el-tag>
|
||||
@@ -57,12 +59,19 @@ import {
|
||||
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」),切换版保持原名
|
||||
const logoText = computed(() => {
|
||||
if (isFixedEntity() && 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))
|
||||
@@ -89,7 +98,8 @@ async function onEntityChange(id: number) {
|
||||
}
|
||||
}
|
||||
onMounted(async () => {
|
||||
// 账套模式:切换器只显示当前用户被授权的企业
|
||||
// 账套模式:切换器只显示当前用户被授权的企业;固定企业版无切换需求,跳过列表加载
|
||||
if (isFixedEntity()) return
|
||||
try {
|
||||
const r: any = await api.get('/auth/my-entities')
|
||||
entities.value = r.data || r || []
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// ── 固定企业模式(Phase C 2026-09-08)──
|
||||
// VITE_FIXED_ENTITY_ID:构建期锁定单一企业(供 Phase A 子域名独立版 hanke/bohai.cma.sxbh.ltd 使用)。
|
||||
// 设置(如 VITE_FIXED_ENTITY_ID=1)=固定企业独立版:登录页隐藏企业下拉、MainLayout/ReportCenter 隐藏切换器,
|
||||
// 登录直接携带该 entity_id;数据天然为该企业,无需内部切换。
|
||||
// 未设置 = 超管/多企业切换版(默认,行为与旧版完全一致)。
|
||||
const fixedRaw: string = (import.meta.env.VITE_FIXED_ENTITY_ID as string | undefined) || ''
|
||||
const fixedId: number | undefined = fixedRaw.trim() === '' ? undefined : Number(fixedRaw)
|
||||
|
||||
/** 是否固定企业独立版(构建期由 VITE_FIXED_ENTITY_ID 决定,运行时不变) */
|
||||
export function isFixedEntity(): boolean {
|
||||
return fixedId !== undefined && !Number.isNaN(fixedId)
|
||||
}
|
||||
|
||||
/** 固定企业 ID;非固定版返回 undefined */
|
||||
export function getFixedEntityId(): number | undefined {
|
||||
return isFixedEntity() ? fixedId : undefined
|
||||
}
|
||||
|
||||
/** 当前生效 entity_id:固定企业版取构建锁定值;切换版取 localStorage(登录/切换时写入) */
|
||||
export function effectiveEntityId(): number {
|
||||
const f = getFixedEntityId()
|
||||
if (f !== undefined) return f
|
||||
const stored = Number(localStorage.getItem('cma_entity_id'))
|
||||
return Number.isNaN(stored) ? 1 : stored
|
||||
}
|
||||
@@ -7,7 +7,8 @@
|
||||
<el-form-item>
|
||||
<el-input v-model="form.username" placeholder="用户名" size="large" @input="onUsernameChange" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<!-- 固定企业版(VITE_FIXED_ENTITY_ID):隐藏企业下拉,显示只读企业徽标 -->
|
||||
<el-form-item v-if="!isFixedEntity()">
|
||||
<el-select v-model="form.entity_id" placeholder="选择登录公司" size="large" style="width:100%" :disabled="entities.length === 0">
|
||||
<el-option v-for="e in entities" :key="e.id" :label="e.short_name || e.name" :value="e.id">
|
||||
<span>{{ e.short_name || e.name }}</span>
|
||||
@@ -15,6 +16,12 @@
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item v-else>
|
||||
<div class="fixed-entity-badge">
|
||||
<span class="fe-label">登录企业</span>
|
||||
<span class="fe-name">{{ fixedEntityLabel }}</span>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item><el-input v-model="form.password" type="password" placeholder="密码" size="large" show-password /></el-form-item>
|
||||
<el-form-item><el-button type="primary" size="large" style="width:100%" :loading="loading" @click="handleLogin">登 录</el-button></el-form-item>
|
||||
</el-form>
|
||||
@@ -23,22 +30,34 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ref, reactive, computed, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { authApi } from '../api/index'
|
||||
import { isFixedEntity, getFixedEntityId } from '../utils/entity'
|
||||
|
||||
const router = useRouter()
|
||||
const loading = ref(false)
|
||||
const entities = ref<any[]>([])
|
||||
const form = reactive({ username: 'admin', password: 'admin123', entity_id: undefined as number | undefined })
|
||||
|
||||
// ── 固定企业模式(Phase C):构建期锁定单一企业,隐藏下拉、登录直接带固定 entity_id ──
|
||||
const fixedMode = isFixedEntity()
|
||||
const fixedEntityId = getFixedEntityId()
|
||||
|
||||
const fixedEntityLabel = computed(() => {
|
||||
if (fixedEntityId === undefined) return ''
|
||||
const e = entities.value.find((x: any) => x.id === fixedEntityId)
|
||||
if (e) return e.short_name || e.name
|
||||
return `企业 #${fixedEntityId}`
|
||||
})
|
||||
|
||||
async function loadEntities(username: string) {
|
||||
try {
|
||||
const r: any = await authApi.loginEntities(username)
|
||||
entities.value = r.data || []
|
||||
// 默认选中第一个授权企业
|
||||
if (entities.value.length > 0 && (form.entity_id === undefined || !entities.value.some((e: any) => e.id === form.entity_id))) {
|
||||
// 切换版:默认选中第一个授权企业;固定企业版:登录时带构建锁定值,不自动改选
|
||||
if (!fixedMode && entities.value.length > 0 && (form.entity_id === undefined || !entities.value.some((e: any) => e.id === form.entity_id))) {
|
||||
form.entity_id = entities.value[0].id
|
||||
}
|
||||
} catch (_) {
|
||||
@@ -51,13 +70,14 @@ function onUsernameChange(val: string) {
|
||||
}
|
||||
|
||||
async function handleLogin() {
|
||||
if (form.entity_id === undefined) {
|
||||
const entityId = fixedMode ? fixedEntityId : form.entity_id
|
||||
if (entityId === undefined) {
|
||||
ElMessage.warning('请选择登录公司')
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
const res: any = await authApi.login({ ...form, entity_id: Number(form.entity_id) })
|
||||
const res: any = await authApi.login({ ...form, entity_id: Number(entityId) })
|
||||
localStorage.setItem('cma_token', res.token)
|
||||
localStorage.setItem('cma_user', JSON.stringify(res.user))
|
||||
localStorage.setItem('cma_entity_id', String(res.entity_id ?? res.user?.entity_id ?? 1))
|
||||
@@ -77,6 +97,10 @@ onMounted(() => loadEntities(form.username))
|
||||
.login-card { background: #fff; padding: 40px; border-radius: 12px; width: 380px; text-align: center; }
|
||||
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
|
||||
.subtitle { color: #999; margin-bottom: 24px; }
|
||||
/* 固定企业版登录徽标 */
|
||||
.fixed-entity-badge { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; height: 40px; border: 1px dashed #c0c4cc; border-radius: 6px; background: #f8f9fc; padding: 0 12px; }
|
||||
.fe-label { color: #909399; font-size: 13px; }
|
||||
.fe-name { color: #303133; font-size: 14px; font-weight: 600; }
|
||||
@media screen and (max-width: 768px) {
|
||||
.login-page { padding: 20px; }
|
||||
.login-card { width: 100%; max-width: 380px; padding: 30px 24px; }
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user