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:
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user