feat: 新增 AI 用量统计页与头部入口
- 新增 /ai-usage 页面:统计卡、按任务类型/模型明细、内联 SVG 趋势图、上游余额 - 入口按钮放在「退出登录」左侧,显隐读登录响应写入的 aiAdmin - token 为 null 时显示「未上报」,与 0 区分
This commit is contained in:
@@ -15,6 +15,14 @@
|
||||
<p class="brand-title">学习进度跟踪系统</p>
|
||||
<p class="brand-subtitle">把学习变成可记录、可回顾、可持续的日常流程</p>
|
||||
</div>
|
||||
<el-button
|
||||
v-if="showAiUsageEntry"
|
||||
plain
|
||||
class="ai-usage-btn"
|
||||
@click="openAiUsage"
|
||||
>
|
||||
AI 用量统计
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="!isLoginRoute"
|
||||
type="success"
|
||||
@@ -29,7 +37,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { ElMessage } from "element-plus";
|
||||
import router from "@/router";
|
||||
@@ -46,6 +54,22 @@ const backLabel = computed(() => (route.meta?.backLabel as string | undefined) |
|
||||
const backUseHistory = computed(() => route.meta?.backUseHistory === true);
|
||||
const loggingOut = ref(false);
|
||||
|
||||
// 白名单来自登录响应写入的 localStorage;头部组件只挂载一次,
|
||||
// 因此换账号登录后要按路由变化重新读取,避免残留上一个账号的入口。
|
||||
const aiAdmin = ref(localStorage.getItem("aiAdmin") === "true");
|
||||
const showAiUsageEntry = computed(() => !isLoginRoute.value && aiAdmin.value);
|
||||
|
||||
watch(
|
||||
() => route.path,
|
||||
() => {
|
||||
aiAdmin.value = localStorage.getItem("aiAdmin") === "true";
|
||||
},
|
||||
);
|
||||
|
||||
const openAiUsage = () => {
|
||||
router.push("/ai-usage");
|
||||
};
|
||||
|
||||
const goBack = () => {
|
||||
if (backUseHistory.value && window.history.state?.back) {
|
||||
router.back();
|
||||
@@ -64,6 +88,7 @@ const handleLogout = async () => {
|
||||
// 后端退出失败时,仍然清理前端登录态,避免用户被卡住。
|
||||
}
|
||||
localStorage.removeItem("isLoggedIn");
|
||||
localStorage.removeItem("aiAdmin");
|
||||
ElMessage.success("已退出登录");
|
||||
await router.push("/login");
|
||||
} finally {
|
||||
@@ -71,7 +96,7 @@ const handleLogout = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
defineExpose({ isLoginRoute, showBackButton, pageTitle, backTo, backLabel, loggingOut, goBack, handleLogout });
|
||||
defineExpose({ isLoginRoute, showBackButton, pageTitle, backTo, backLabel, loggingOut, goBack, handleLogout, showAiUsageEntry, openAiUsage });
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -121,13 +146,25 @@ defineExpose({ isLoginRoute, showBackButton, pageTitle, backTo, backLabel, loggi
|
||||
color: var(--green-700);
|
||||
}
|
||||
|
||||
/* 次级入口:中性描边,不与主按钮「退出登录」抢视觉 */
|
||||
.ai-usage-btn {
|
||||
border-color: var(--border-soft);
|
||||
color: var(--green-700);
|
||||
}
|
||||
|
||||
.ai-usage-btn:hover {
|
||||
border-color: var(--green-600);
|
||||
color: var(--green-800);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.head {
|
||||
align-items: flex-start;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.logout-btn {
|
||||
.logout-btn,
|
||||
.ai-usage-btn {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user