chore: 初始化 monorepo 脚手架与代码骨架
- Bun workspaces:apps/web(Vue 3.5 + Vite 8 + naive-ui)· apps/server(Hono 4.13 + Drizzle)· packages/shared(契约类型) - 代码骨架:四表 Drizzle schema · 11 个端点占位(501)· 管理面口令中间件 · 同步引擎占位(5 分钟 tick + 防重入) - 命令链:dev / build / test / lint / type-check / db:*(见 AGENTS.md)
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 管理面布局(交互设计 §2 #7 + 口令门帘细节):
|
||||
* - 未验证:全屏居中卡片(口令 + 「进入」)——校验直接用管理面请求,401 即口令错
|
||||
* - 已验证:侧边栏菜单(三页)+ 内容区;底部「← 查看面」
|
||||
* - 口令存 sessionStorage(关标签即忘);401 时自动退回门帘
|
||||
*/
|
||||
import { onMounted, onUnmounted, ref } from 'vue'
|
||||
import { RouterView, useRoute, useRouter } from 'vue-router'
|
||||
|
||||
import {
|
||||
ApiError,
|
||||
api,
|
||||
clearManageToken,
|
||||
getManageToken,
|
||||
onManageUnauthorized,
|
||||
setManageToken,
|
||||
} from '@/api/client'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
const unlocked = ref(false)
|
||||
const checking = ref(false)
|
||||
const tokenInput = ref('')
|
||||
const errorText = ref('')
|
||||
|
||||
async function verifyAndUnlock(): Promise<void> {
|
||||
checking.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await api.apiKeysList()
|
||||
unlocked.value = true
|
||||
} catch (err) {
|
||||
clearManageToken()
|
||||
errorText.value =
|
||||
err instanceof ApiError && err.code === 'manage_unauthorized'
|
||||
? '口令不正确'
|
||||
: '校验失败,请稍后重试'
|
||||
unlocked.value = false
|
||||
} finally {
|
||||
checking.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function tryUnlock(): Promise<void> {
|
||||
if (!tokenInput.value) {
|
||||
errorText.value = '请输入口令'
|
||||
return
|
||||
}
|
||||
setManageToken(tokenInput.value)
|
||||
await verifyAndUnlock()
|
||||
}
|
||||
|
||||
let off: (() => void) | null = null
|
||||
|
||||
onMounted(() => {
|
||||
off = onManageUnauthorized(() => {
|
||||
unlocked.value = false
|
||||
errorText.value = '口令已失效,请重新输入'
|
||||
})
|
||||
if (getManageToken()) {
|
||||
void verifyAndUnlock()
|
||||
}
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
off?.()
|
||||
})
|
||||
|
||||
const menuOptions = [
|
||||
{ label: 'key 管理', key: 'manage-api-keys' },
|
||||
{ label: '购买记录', key: 'manage-purchases' },
|
||||
{ label: '换算参数', key: 'manage-qpu' },
|
||||
]
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="!unlocked" class="gate">
|
||||
<n-card class="gate-card" title="管理通道">
|
||||
<n-space vertical :size="16">
|
||||
<n-input
|
||||
v-model:value="tokenInput"
|
||||
type="password"
|
||||
show-password-on="click"
|
||||
placeholder="部署口令"
|
||||
@keyup.enter="tryUnlock"
|
||||
/>
|
||||
<n-text v-if="errorText" type="error">{{ errorText }}</n-text>
|
||||
<n-button type="primary" block :loading="checking" @click="tryUnlock">进入</n-button>
|
||||
</n-space>
|
||||
</n-card>
|
||||
</div>
|
||||
|
||||
<n-layout v-else has-sider class="manage">
|
||||
<n-layout-sider bordered :width="200">
|
||||
<div class="sider">
|
||||
<n-menu
|
||||
:value="String(route.name ?? '')"
|
||||
:options="menuOptions"
|
||||
@update:value="(key: string) => router.push({ name: key })"
|
||||
/>
|
||||
<n-button text class="back" @click="router.push('/usage-log')">← 查看面</n-button>
|
||||
</div>
|
||||
</n-layout-sider>
|
||||
<n-layout-content class="content">
|
||||
<RouterView />
|
||||
</n-layout-content>
|
||||
</n-layout>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.gate {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
}
|
||||
.gate-card {
|
||||
width: 360px;
|
||||
}
|
||||
.manage {
|
||||
height: 100vh;
|
||||
}
|
||||
.sider {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
height: 100%;
|
||||
padding: 16px 0;
|
||||
}
|
||||
.back {
|
||||
margin-left: 24px;
|
||||
align-self: flex-start;
|
||||
}
|
||||
.content {
|
||||
padding: 24px;
|
||||
overflow: auto;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user