feat: 全局企业切换器(顶部导航栏+localStorage共享)
This commit is contained in:
@@ -28,6 +28,9 @@
|
||||
<span class="page-title">{{ pageTitle }}</span>
|
||||
</div>
|
||||
<div class="header-right">
|
||||
<el-select 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>
|
||||
<el-dropdown trigger="click">
|
||||
<span class="user-info"><el-icon><User /></el-icon>{{ userName }}</span>
|
||||
@@ -43,8 +46,9 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import api from '../api/index'
|
||||
import {
|
||||
User, Monitor, Document, TrendCharts, WarningFilled, Connection,
|
||||
Menu, Bell, Setting, Coin, DataAnalysis, Money, DataLine,
|
||||
@@ -57,6 +61,25 @@ const router = useRouter()
|
||||
const isCollapse = ref(false)
|
||||
const mobileMenuOpen = ref(false)
|
||||
|
||||
// ── 全局企业切换 ──
|
||||
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)
|
||||
location.reload()
|
||||
}
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const r: any = await api.get('/entities')
|
||||
entities.value = r.data || r || []
|
||||
} catch (_) {}
|
||||
})
|
||||
|
||||
// 图标名称 → 组件实例映射
|
||||
const iconMap: Record<string, any> = {
|
||||
Monitor, Document, TrendCharts, WarningFilled, Connection,
|
||||
|
||||
Reference in New Issue
Block a user