38 lines
1.2 KiB
Vue
38 lines
1.2 KiB
Vue
<template>
|
||||
|
|
<el-radio-group v-model="current" size="small" @change="onChange">
|
|||
|
|
<el-radio-button label="Platform">管理员</el-radio-button>
|
|||
|
|
<el-radio-button label="RCSMonitor">运营</el-radio-button>
|
|||
|
|
</el-radio-group>
|
|||
|
|
</template>
|
|||
|
|
|
|||
|
|
<script setup lang="ts">
|
|||
|
|
import { computed } from 'vue'
|
|||
|
|
import { useRouter } from 'vue-router'
|
|||
|
|
import { ElMessage } from 'element-plus'
|
|||
|
|
import { useAuthStore } from '@/stores/auth'
|
|||
|
|
import type { Scope } from '@/types/auth'
|
|||
|
|
|
|||
|
|
const auth = useAuthStore()
|
|||
|
|
const router = useRouter()
|
|||
|
|
|
|||
|
|
// 会话 45 AR-6:switchScope 已变成异步(调后端 /auth/switch-scope)。
|
|||
|
|
// computed.set 不能 await,只能 fire-and-forget 并在 catch 里弹错。
|
|||
|
|
const current = computed<Scope>({
|
|||
|
|
get: () => auth.scope ?? 'Platform',
|
|||
|
|
set: (v) => { void switchAndNavigate(v) }
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
async function onChange(v: string | number | boolean | undefined) {
|
|||
|
|
await switchAndNavigate(v as Scope)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
async function switchAndNavigate(scope: Scope) {
|
|||
|
|
try {
|
|||
|
|
await auth.switchScope(scope)
|
|||
|
|
router.push(scope === 'Platform' ? '/admin/map-monitor' : '/monitor/map')
|
|||
|
|
} catch (err) {
|
|||
|
|
ElMessage.error((err as Error)?.message ?? `切换到 ${scope} 失败`)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
</script>
|