init: api-gateway v2.4.0(Agnes/b.ai/火山方舟 三家供应商网关)
This commit is contained in:
commit
6cc65ff76f
91 files changed
+24653
No files matched your search
@@ -0,0 +1,239 @@
|
||||
<template>
|
||||
<div class="app">
|
||||
<!-- 宽屏:侧栏常驻 -->
|
||||
<aside v-if="!isMobile" class="rail">
|
||||
<SideNav :groups="groups" />
|
||||
</aside>
|
||||
|
||||
<div class="main">
|
||||
<!-- 宽屏顶栏:页面标题 + 副标题 + 连接状态 + 主题 / 刷新 / 通知 / 账号 -->
|
||||
<header v-if="!isMobile" class="top">
|
||||
<div>
|
||||
<h2>{{ pageTitle }}</h2>
|
||||
<div class="crumb">{{ pageSub }}</div>
|
||||
</div>
|
||||
<div class="top-right">
|
||||
<div class="host">
|
||||
<i class="dot" :class="connOk ? 'ok' : 'bad'"></i>
|
||||
<span>{{ connOk ? t('nav.connected') : t('nav.disconnected') }}</span>
|
||||
</div>
|
||||
|
||||
<!-- 第二十一轮:tooltip 必须在 dropdown **外面**。反过来(tooltip 包着触发按钮)
|
||||
Element Plus 的 ElOnlyChild 会把点击挂到内层 tooltip 的包装节点上,
|
||||
真正被点的 <button> 收不到事件 → 菜单永远不开(老板报的「主题点了没反应」)。 -->
|
||||
<el-tooltip :content="t('theme.choose')" placement="bottom">
|
||||
<el-dropdown trigger="click" @command="onTheme">
|
||||
<button class="icon-btn" type="button"><Icon name="theme" :size="16" /></button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item v-for="id in THEME_IDS" :key="id" :command="id" :disabled="theme === id">
|
||||
<span class="t-row"><i class="t-dot" :style="{ background: THEME_META[id].accent }" />{{ t(THEME_META[id].nameKey) }}</span>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item divided command="follow">
|
||||
<span class="t-row">
|
||||
<Icon name="check" :size="14" :style="{ opacity: followSystem ? 1 : 0 }" />
|
||||
{{ t('theme.followSystem') }}
|
||||
</span>
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</el-tooltip>
|
||||
|
||||
<el-tooltip :content="t('top.refresh')" placement="bottom">
|
||||
<button class="icon-btn" type="button" @click="refresh"><Icon name="refresh" :size="16" /></button>
|
||||
</el-tooltip>
|
||||
|
||||
<el-dropdown trigger="click" @command="onCmd">
|
||||
<div class="user">
|
||||
<div class="avatar">{{ initial }}</div>
|
||||
<span>{{ store.user }}<template v-if="store.isAdmin"> · {{ t('common.admin') }}</template></span>
|
||||
</div>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item command="zh" :disabled="locale === 'zh'">中文</el-dropdown-item>
|
||||
<el-dropdown-item command="en" :disabled="locale === 'en'">English</el-dropdown-item>
|
||||
<el-dropdown-item divided command="logout">{{ t('common.logout') }}</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- 窄屏顶栏:汉堡唤出抽屉,右侧只留主题与账号 -->
|
||||
<header v-else class="m-top">
|
||||
<div class="ic" @click="drawerOpen = true"><Icon name="menu" :size="18" /></div>
|
||||
<h3>{{ pageTitle }}</h3>
|
||||
<div class="top-right">
|
||||
<div class="ic" @click="cycleTheme"><Icon name="theme" :size="18" /></div>
|
||||
<el-dropdown trigger="click" @command="onCmd">
|
||||
<div class="avatar">{{ initial }}</div>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item command="zh" :disabled="locale === 'zh'">中文</el-dropdown-item>
|
||||
<el-dropdown-item command="en" :disabled="locale === 'en'">English</el-dropdown-item>
|
||||
<el-dropdown-item divided command="logout">{{ t('common.logout') }}</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="gw-body">
|
||||
<!-- key 里带 refreshTick:点刷新时整页重挂载重新拉数据(页面内部状态清空是有意的) -->
|
||||
<router-view :key="route.fullPath + '-' + refreshTick" />
|
||||
</div>
|
||||
|
||||
<TabBar v-if="isMobile" @more="drawerOpen = true" />
|
||||
</div>
|
||||
|
||||
<!-- 抽屉:完整菜单 + 主题切换;选完菜单立即收起(否则看完页面还被挡着) -->
|
||||
<el-drawer v-model="drawerOpen" direction="ltr" :size="252" :with-header="false" class="nav-drawer">
|
||||
<div class="drawer-wrap">
|
||||
<SideNav :groups="groups" @navigate="drawerOpen = false" />
|
||||
<div class="drawer-themes">
|
||||
<div class="dt-title">{{ t('theme.choose') }}</div>
|
||||
<div class="dt-row">
|
||||
<button
|
||||
v-for="id in THEME_IDS"
|
||||
:key="id"
|
||||
type="button"
|
||||
class="dt-card"
|
||||
:class="{ on: theme === id }"
|
||||
@click="onTheme(id)"
|
||||
>
|
||||
<span class="dt-prev">
|
||||
<i class="l" :style="{ background: THEME_META[id].side }" />
|
||||
<i class="r" :style="{ background: THEME_META[id].canvas }">
|
||||
<b :style="{ background: THEME_META[id].accent }" />
|
||||
<b :style="{ background: THEME_META[id].accent, opacity: .4, width: '65%' }" />
|
||||
</i>
|
||||
</span>
|
||||
<span class="dt-name">{{ id }}</span>
|
||||
</button>
|
||||
<button type="button" class="dt-card" :class="{ on: followSystem }" @click="toggleFollow">
|
||||
<span class="dt-prev"><Icon name="theme" :size="18" /></span>
|
||||
<span class="dt-name">{{ t('theme.followShort') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useSessionStore } from '../store/session'
|
||||
import { api } from '../api'
|
||||
import { setLocale } from '../i18n'
|
||||
import SideNav from './SideNav.vue'
|
||||
import TabBar from './TabBar.vue'
|
||||
import Icon from '../components/Icon.vue'
|
||||
import { useIsMobile } from '../lib/ui'
|
||||
import { navGroups } from '../lib/nav'
|
||||
import { useTheme, THEME_IDS, THEME_META, type ThemeId } from '../lib/theme'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const store = useSessionStore()
|
||||
const { t, locale } = useI18n()
|
||||
const { isMobile } = useIsMobile()
|
||||
const { theme, followSystem, setTheme, setFollowSystem } = useTheme()
|
||||
|
||||
const connOk = ref(true)
|
||||
const drawerOpen = ref(false)
|
||||
const refreshTick = ref(0)
|
||||
|
||||
const groups = computed(() => navGroups(store.isAdmin))
|
||||
const initial = computed(() => (store.user || '?').slice(0, 1).toUpperCase())
|
||||
|
||||
// 抽屉里选完菜单 / 浏览器前进后退,都收起
|
||||
watch(() => route.fullPath, () => { drawerOpen.value = false })
|
||||
|
||||
const pageTitle = computed(() => {
|
||||
const key = String(route.name || '')
|
||||
return key ? t(`nav.menu${key}`) : t('nav.control')
|
||||
})
|
||||
const pageSub = computed(() => {
|
||||
const key = String(route.name || '')
|
||||
const sub = t(`nav.sub${key}`)
|
||||
// 没写副标题的页面,t() 会把 key 原样返回 —— 这时显示连接地址兜底
|
||||
return sub.startsWith('nav.') ? 'api.wangjinding.com' : sub
|
||||
})
|
||||
|
||||
function onTheme(cmd: string | number | object) {
|
||||
if (cmd === 'follow') { toggleFollow(); return }
|
||||
setTheme(cmd as ThemeId)
|
||||
}
|
||||
function toggleFollow() { setFollowSystem(!followSystem.value) }
|
||||
/** 手机端只有一个图标位:循环 B → A → C(设置页里可以做精细选择) */
|
||||
function cycleTheme() {
|
||||
const i = THEME_IDS.indexOf(theme.value)
|
||||
setTheme(THEME_IDS[(i + 1) % THEME_IDS.length])
|
||||
}
|
||||
function refresh() { refreshTick.value++ }
|
||||
|
||||
async function onCmd(cmd: string) {
|
||||
if (cmd === 'logout') {
|
||||
await store.logout()
|
||||
router.push('/login')
|
||||
return
|
||||
}
|
||||
setLocale(cmd as 'zh' | 'en')
|
||||
}
|
||||
|
||||
let timer: any = null
|
||||
async function probe() {
|
||||
try {
|
||||
// 探 /health 而不是 /healthz:后者只回 {"status":"ok"},不带 uptime,
|
||||
// /health 带 version/uptime,顺带把连接状态一起判了(顶栏「连接正常」小灯)。
|
||||
const j = await api('/health')
|
||||
connOk.value = !!j && j.status === 'ok'
|
||||
} catch {
|
||||
connOk.value = false
|
||||
}
|
||||
}
|
||||
onMounted(() => {
|
||||
probe()
|
||||
timer = setInterval(probe, 10000)
|
||||
window.addEventListener('gw-auth-expired', onAuthExpired)
|
||||
})
|
||||
onUnmounted(() => {
|
||||
clearInterval(timer)
|
||||
window.removeEventListener('gw-auth-expired', onAuthExpired)
|
||||
})
|
||||
|
||||
async function onAuthExpired() {
|
||||
await store.logout()
|
||||
router.push('/login')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.t-row { display: flex; align-items: center; gap: 8px; }
|
||||
.t-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
|
||||
.host span { white-space: nowrap; }
|
||||
/* 抽屉内容:菜单撑满,主题卡固定在底部 */
|
||||
.drawer-wrap { display: flex; flex-direction: column; height: 100%; background: var(--surface); }
|
||||
.drawer-themes { flex: none; border-top: 1px solid var(--line); padding: 12px; }
|
||||
.dt-title { font-size: 11.5px; color: var(--muted-2); margin-bottom: 8px; }
|
||||
.dt-row { display: flex; gap: 8px; }
|
||||
.dt-card {
|
||||
flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--surface);
|
||||
border-radius: 10px; padding: 7px 5px; cursor: pointer; display: flex;
|
||||
flex-direction: column; align-items: center; gap: 5px;
|
||||
}
|
||||
.dt-card.on { border-color: var(--primary); background: var(--primary-soft); }
|
||||
.dt-prev { width: 100%; height: 22px; border-radius: 6px; overflow: hidden; display: flex; border: 1px solid var(--line); }
|
||||
.dt-prev .l { width: 30%; display: block; }
|
||||
.dt-prev .r { flex: 1; padding: 3px; display: flex; flex-direction: column; gap: 3px; justify-content: center; }
|
||||
.dt-prev .r b { height: 3px; border-radius: 2px; display: block; }
|
||||
.dt-name { font-size: 11.5px; color: var(--muted); font-weight: 600; line-height: 22px; }
|
||||
.dt-card.on .dt-name { color: var(--primary); }
|
||||
@media (max-width: 768px) {
|
||||
.top-right { gap: 6px; }
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,78 @@
|
||||
<template>
|
||||
<!-- 侧栏:桌面常驻在左边,窄屏放进抽屉 —— 两处共用这一份,菜单项只维护一处 -->
|
||||
<div class="rail-inner">
|
||||
<div class="brand">
|
||||
<span class="logo"><Icon name="bolt" :size="17" /></span>
|
||||
<div>
|
||||
<b>{{ t('nav.title') }}</b>
|
||||
<span>api.wangjinding.com</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav class="nav">
|
||||
<template v-for="(g, gi) in groups" :key="g.id">
|
||||
<div v-if="gi > 0" class="nav-sep" />
|
||||
<router-link
|
||||
v-for="m in g.items"
|
||||
:key="m.path"
|
||||
:to="m.path"
|
||||
class="nav-i"
|
||||
:class="{ on: isActive(m.path) }"
|
||||
@click="emit('navigate')"
|
||||
>
|
||||
<Icon :name="m.icon" :size="18" />
|
||||
<span>{{ t(`nav.menu${m.key}`) }}</span>
|
||||
</router-link>
|
||||
</template>
|
||||
</nav>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import Icon from '../components/Icon.vue'
|
||||
import type { NavGroup } from '../lib/nav'
|
||||
|
||||
// 第二十二轮:删掉侧栏底部那两行(「B · 素白蓝紫」+「v2.4.0 · 控制台」)。
|
||||
// 皮肤名在设置页「外观与语言」和顶栏调色盘里都能看到,版本号也没必要常驻占位。
|
||||
const props = defineProps<{ groups: NavGroup[] }>()
|
||||
const emit = defineEmits<{ (e: 'navigate'): void }>()
|
||||
const { t } = useI18n()
|
||||
const route = useRoute()
|
||||
|
||||
// 用前缀匹配:/users 的子页(若有)也能让菜单高亮
|
||||
function isActive(path: string): boolean {
|
||||
return route.path === path || route.path.startsWith(path + '/')
|
||||
}
|
||||
void props
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.rail-inner {
|
||||
display: flex; flex-direction: column; height: 100%;
|
||||
background: var(--surface); padding: 14px 12px; overflow: hidden;
|
||||
}
|
||||
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 12px; }
|
||||
.logo {
|
||||
width: 32px; height: 32px; border-radius: 10px; background: var(--primary);
|
||||
color: var(--primary-ink); display: grid; place-items: center; flex: none;
|
||||
}
|
||||
.brand b { font-size: 15px; display: block; line-height: 1.25; color: var(--text); }
|
||||
.brand span { font-size: 11px; color: var(--muted-2); }
|
||||
.nav { display: flex; flex-direction: column; gap: 1px; overflow-y: auto; flex: 1; }
|
||||
.nav-i {
|
||||
display: flex; align-items: center; gap: 10px;
|
||||
/* 第二十三轮追加(老板先「缩短一点让滚动条不要出现」,再「上下间距可以大一点」):
|
||||
行距随窗口高度自适应 —— 窗口高就宽松、窗口矮就收紧,两边都满足:
|
||||
下限 7px(行高 32px,与上一版一致,矮窗口不会顶出滚动条)、上限 11px(行高 40px,比原来 9px/36px 更松)。
|
||||
换算:600px 视口 ≈ 35px 行高、720px ≈ 38px、1080px 及以上封顶 40px;
|
||||
不滚动的下限:窗口高约 505px(yaml 那份固定值 36px 时是 ~605px 就会滚)。 */
|
||||
padding: clamp(7px, 1.4vh, 11px) 10px;
|
||||
border-radius: 10px; color: var(--muted); font-size: 13.5px;
|
||||
cursor: pointer; text-decoration: none; transition: background .15s, color .15s;
|
||||
}
|
||||
.nav-i:hover { background: var(--chip); color: var(--text); }
|
||||
.nav-i.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
|
||||
.nav-sep { height: 1px; background: var(--line-2); margin: clamp(7px, 1.2vh, 13px) 8px; flex: none; }
|
||||
</style>
|
||||
@@ -0,0 +1,44 @@
|
||||
<template>
|
||||
<!-- 手机底部 Tab:4 个主功能 + 「更多」(打开抽屉里的完整菜单)。
|
||||
为什么要有「更多」:手机放不下 10 个菜单项,底部 Tab 只留高频入口,
|
||||
低频的(模型/指标/密钥/用户/日志/设置)走抽屉,不必牺牲可达性。 -->
|
||||
<nav class="tabbar">
|
||||
<div
|
||||
v-for="tb in tabs"
|
||||
:key="tb.path"
|
||||
:class="{ on: isActive(tb.path) }"
|
||||
@click="go(tb.path)"
|
||||
>
|
||||
<Icon :name="tb.icon" :size="18" />
|
||||
<span>{{ t(`nav.menu${tb.key}`) }}</span>
|
||||
</div>
|
||||
<div :class="{ on: moreActive }" @click="emit('more')">
|
||||
<Icon name="menu" :size="18" />
|
||||
<span>{{ t('nav.more') }}</span>
|
||||
</div>
|
||||
</nav>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import Icon from '../components/Icon.vue'
|
||||
import { MOBILE_TABS } from '../lib/nav'
|
||||
|
||||
const emit = defineEmits<{ (e: 'more'): void }>()
|
||||
const { t } = useI18n()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const tabs = MOBILE_TABS
|
||||
|
||||
function isActive(path: string): boolean {
|
||||
return route.path === path || route.path.startsWith(path + '/')
|
||||
}
|
||||
/** 当前页不在前 4 个 Tab 里时,「更多」高亮(否则用户不知道自己在哪) */
|
||||
const moreActive = computed(() => !tabs.some((tb) => isActive(tb.path)))
|
||||
|
||||
function go(path: string) {
|
||||
if (route.path !== path) router.push(path)
|
||||
}
|
||||
</script>
|
||||
Reference in new issue
Block a user