499c511140
- 删除 opencode_search.py / mcp_search_server.py 及所有 MCP 引用 - 移除搜索缓存定时任务(scheduled_refresh_search_cache) - 清理前后端所有 opencode/MCP 代码和注释 - LLM 提供商量换:opencode-go→nvidia(默认)+sensenova(合规审查) - llm_configs 新增 is_default 字段,API 层互斥逻辑 - 所有定时任务支持独立 LLM 模型选择(LLM_TASK_PROVIDER env) - compliance_optimizer.py 修复:import os / 解硬编码 / 关键词过滤 - Scheduler 日志修复:始终 INSERT,避免僵尸 running 行 - Systemd 服务化:Restart=always / 单 worker / Type=exec - 搜索提供商:替换 opencode→360/搜狗/微信(免 Key) - 更新 AGENTS.md / PROGRESS.md
483 lines
30 KiB
HTML
483 lines
30 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>宇之然内容创作平台</title>
|
|
<link rel="stylesheet" href="element-plus.css">
|
|
<link rel="stylesheet" href="theme-modern.css">
|
|
<style>
|
|
.page { display: none; animation: fadeIn 0.5s ease-out; }
|
|
.page.active { display: block; }
|
|
@keyframes fadeIn {
|
|
from { opacity: 0; transform: translateY(20px); }
|
|
to { opacity: 1; transform: translateY(0); }
|
|
}
|
|
.module-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--spacing-lg); }
|
|
.module-card { background: var(--color-bg-raised); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--spacing-lg); transition: all 0.3s var(--ease-out); }
|
|
.module-card:hover { transform: translateY(-6px); border-color: var(--color-border-hover); box-shadow: var(--shadow-lg); }
|
|
.module-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--spacing-md); }
|
|
.module-title { font-size: var(--font-size-h3); font-weight: 600; color: var(--color-text-primary); display: flex; align-items: center; gap: var(--spacing-sm); }
|
|
.module-status { padding: 6px 12px; border-radius: var(--radius-xl); font-size: var(--font-size-caption); font-weight: 600; background: rgba(103,194,58,0.12); color: #67c23a; border: 1px solid rgba(103,194,58,0.25); }
|
|
.module-status.inactive { background: rgba(144,147,153,0.12); color: #909399; border: 1px solid rgba(144,147,153,0.25); }
|
|
.module-drawer .el-drawer__body { padding: 20px; overflow-y: auto; }
|
|
.module-content { font-size: var(--font-size-body); color: var(--color-text-regular); line-height: 1.8; }
|
|
.module-content div { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed var(--color-border); }
|
|
.module-content div:last-child { border-bottom: none; }
|
|
.stat-title { font-size: var(--font-size-small); color: var(--color-text-secondary); margin-bottom: var(--spacing-md); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 500; }
|
|
.plan-list { display: flex; flex-direction: column; gap: 8px; }
|
|
.plan-item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--color-bg-raised); border: 1px solid var(--color-border); border-radius: var(--radius-md); transition: all 0.2s; }
|
|
.plan-item:hover { border-color: var(--color-primary); }
|
|
.plan-date { font-size: var(--font-size-caption); color: var(--color-text-secondary); font-weight: 600; min-width: 36px; }
|
|
.plan-title { flex: 1; font-size: var(--font-size-body); color: var(--color-text-primary); }
|
|
@media (max-width: 768px) { .module-grid { grid-template-columns: 1fr; } }
|
|
</style>
|
|
|
|
<script src="uni-nav.js"></script>
|
|
</head>
|
|
<body>
|
|
<div id="app">
|
|
<uni-nav title="仪表盘" :username="currentUser.username" :is-admin="isAdmin" current-page="dashboard" @navigate="redirectToPage" @logout="handleLogout">
|
|
</uni-nav>
|
|
<div class="main-content" v-if="isLoggedIn">
|
|
<main class="content-area">
|
|
<!-- 系统概览页面 -->
|
|
<div id="page-overview" class="page" :class="{ active: currentPage === 'overview' }">
|
|
<h2 style="font-size: var(--font-size-h1); font-weight: 700; margin-bottom: var(--spacing-xl); color: var(--color-text-primary);">
|
|
<el-icon style="vertical-align:-2px;"><IconDashboard /></el-icon> 系统概览
|
|
</h2>
|
|
|
|
<!-- 加载状态 -->
|
|
<div v-if="loadingStats" style="text-align:center;padding:40px 0;color:#909399;">
|
|
<el-icon style="font-size:32px;margin-bottom:12px;" class="is-loading"><IconLoading /></el-icon>
|
|
<div>加载中...</div>
|
|
</div>
|
|
<!-- 空状态 -->
|
|
<div v-else-if="!stats.total && !loadingStats" class="empty-state">
|
|
<el-icon style="font-size:48px;color:#c0c4cc;"><IconDashboard /></el-icon>
|
|
<div class="empty-text">暂无数据</div>
|
|
</div>
|
|
<!-- 统计卡片 -->
|
|
<div v-else class="stats-grid">
|
|
<div class="stat-card primary" @click="goToTopics('')">
|
|
<div class="stat-title">选题总数</div>
|
|
<div class="stat-value">{{ stats.total }}</div>
|
|
</div>
|
|
<div class="stat-card warning" @click="goToTopics('pending')">
|
|
<div class="stat-title">待处理</div>
|
|
<div class="stat-value">{{ stats.pending }}</div>
|
|
</div>
|
|
<div class="stat-card danger" @click="goToTopics('review')">
|
|
<div class="stat-title">待审查</div>
|
|
<div class="stat-value">{{ stats.review }}</div>
|
|
</div>
|
|
<div class="stat-card success" @click="goToTopics('ready')">
|
|
<div class="stat-title">待发布</div>
|
|
<div class="stat-value">{{ stats.ready }}</div>
|
|
</div>
|
|
<div class="stat-card info" @click="goToTopics('published')">
|
|
<div class="stat-title">已发布</div>
|
|
<div class="stat-value">{{ stats.published }}</div>
|
|
</div>
|
|
<div class="stat-card primary" @click="goToTopics('today')">
|
|
<div class="stat-title">今日新增</div>
|
|
<div class="stat-value">{{ stats.today }}</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 模块状态 -->
|
|
<h3 style="font-size: var(--font-size-h2); font-weight: 600; margin-bottom: var(--spacing-lg); color: var(--color-text-primary);">
|
|
<el-icon style="vertical-align:-2px;"><IconSetting /></el-icon> 模块状态
|
|
<span style="font-size: var(--font-size-small); font-weight: 400; color: var(--color-text-secondary); margin-left: var(--spacing-sm);">
|
|
定时任务:
|
|
<el-icon v-if="schedulerRunning" style="color:#67C23A;vertical-align:-2px;"><IconCheck /></el-icon>
|
|
<el-icon v-else style="color:#F56C6C;vertical-align:-2px;"><IconClose /></el-icon>
|
|
{{ schedulerRunning ? '运行中' : '未启动' }}
|
|
</span>
|
|
</h3>
|
|
<div class="module-grid">
|
|
<div v-for="mod in modules" :key="mod.module_id" class="module-card">
|
|
<div class="module-header">
|
|
<span class="module-title">{{ mod.title }}</span>
|
|
<span :class="['module-status', mod.enabled ? '' : 'inactive']">
|
|
<el-icon v-if="mod.enabled" style="vertical-align:-2px;"><IconCheck /></el-icon>
|
|
<el-icon v-else style="vertical-align:-2px;"><IconClose /></el-icon>
|
|
{{ mod.enabled ? '已启用' : '已禁用' }}
|
|
</span>
|
|
</div>
|
|
<div class="module-content">
|
|
<div><span>执行时间</span><span>{{ mod.schedule || mod.cron_default }}</span></div>
|
|
<div><span>成功/失败</span><span style="color:#67c23a;">{{ mod.success_runs }}</span> / <span style="color:#f56c6c;">{{ mod.failed_runs }}</span></div>
|
|
<div><span>今日任务</span><span>{{ mod.total_runs }} 次</span></div>
|
|
<div><span>下次运行</span><span style="color:#409eff;">{{ mod.next_run || '—' }}</span></div>
|
|
<div v-if="mod.last_result && mod.last_result.topics_count" style="border-bottom:none;">
|
|
<span>最新产出</span>
|
|
<span style="color:#409eff;font-weight:600;">{{ mod.last_result.topics_count }} 个选题</span>
|
|
</div>
|
|
<div v-else-if="mod.last_result && mod.last_result.articles_synced" style="border-bottom:none;">
|
|
<span>最新产出</span>
|
|
<span style="color:#409eff;font-weight:600;">{{ mod.last_result.articles_synced }} 篇</span>
|
|
</div>
|
|
<div style="margin-top:10px; border-bottom:none;">
|
|
<el-button v-if="isAdmin" size="small" type="primary" @click="openModuleDetail(mod)">详情</el-button>
|
|
<el-button size="small" @click="triggerModule(mod.module_id || mod.id)" :loading="runningModule === (mod.module_id || mod.id)" :disabled="!mod.enabled">立即运行</el-button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 近期计划 -->
|
|
<h3 style="font-size: var(--font-size-h2); font-weight: 600; margin-bottom: var(--spacing-lg); color: var(--color-text-primary);">
|
|
<el-icon style="vertical-align:-2px;"><IconCalendar /></el-icon> 近期计划
|
|
</h3>
|
|
<div v-if="loadingPlan" style="text-align:center;padding:20px 0;color:#909399;">
|
|
<el-icon style="font-size:24px;" class="is-loading"><IconLoading /></el-icon>
|
|
<div style="margin-top:8px;">加载中...</div>
|
|
</div>
|
|
<div v-else-if="upcomingEntries.length === 0" class="empty-state" style="padding:20px;">
|
|
<el-icon style="font-size:36px;color:#c0c4cc;"><IconCalendar /></el-icon>
|
|
<div class="empty-text">近期暂无计划</div>
|
|
</div>
|
|
<div v-else class="plan-list">
|
|
<div v-for="entry in upcomingEntries" :key="entry.id || entry.date" class="plan-item">
|
|
<span class="plan-date">{{ entry.date.slice(5) }}</span>
|
|
<span class="plan-title">{{ entry.title }}</span>
|
|
<el-tag v-if="entry.status" :type="entry.status === 'published' ? 'success' : 'warning'" size="small">{{ entry.status === 'published' ? '已发布' : '计划' }}</el-tag>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 模块详情抽屉 -->
|
|
<el-drawer v-model="showModuleDrawer" :title="(moduleDetail ? moduleDetail.title : '') + ' 详情'" size="50%" direction="rtl" class="module-drawer">
|
|
<div v-if="moduleDetailLoading" style="text-align:center;padding:40px;color:#909399;">加载中...</div>
|
|
<div v-else-if="moduleDetail" style="padding:0 20px;">
|
|
<div style="margin-bottom:16px;display:flex;gap:16px;align-items:center;">
|
|
<el-tag :type="moduleDetail.enabled ? 'success' : 'info'" size="small">{{ moduleDetail.enabled ? '已启用' : '已禁用' }}</el-tag>
|
|
<span style="font-size:13px;color:#909399;">执行时间: {{ moduleDetail.schedule || moduleDetail.cron_default }}</span>
|
|
</div>
|
|
<el-tabs style="height:calc(100vh - 200px);">
|
|
<el-tab-pane label="📋 运行记录" name="history" style="overflow:auto;">
|
|
<div v-if="moduleDetailHistory && moduleDetailHistory.length > 0">
|
|
<el-timeline>
|
|
<el-timeline-item v-for="(h, i) in moduleDetailHistory" :key="h.id || i"
|
|
:timestamp="h.started_at ? new Date(h.started_at).toLocaleString('zh-CN', {timeZone:'Asia/Shanghai'}) : '—'"
|
|
:color="h.status === 'success' ? '#67c23a' : h.status === 'running' ? '#e6a23c' : '#f56c6c'">
|
|
<div style="font-size:13px;">
|
|
<el-tag :type="h.status === 'success' ? 'success' : h.status === 'running' ? 'warning' : 'danger'" size="small" style="margin-right:6px;">{{ h.status }}</el-tag>
|
|
<span v-if="h.message">{{ h.message }}</span>
|
|
<span v-else style="color:#909399;">—</span>
|
|
</div>
|
|
<div v-if="h.error_trace" style="margin-top:4px;padding:6px 8px;background:#fef0f0;border-radius:4px;font-size:12px;color:#f56c6c;max-height:60px;overflow:auto;">{{ h.error_trace }}</div>
|
|
<div style="font-size:12px;color:#c0c4cc;margin-top:2px;">耗时 {{ h.duration ? h.duration + 's' : '—' }} · {{ h.triggered_by }}</div>
|
|
</el-timeline-item>
|
|
</el-timeline>
|
|
</div>
|
|
<div v-else style="color:#909399;padding:20px;text-align:center;">暂无运行记录</div>
|
|
</el-tab-pane>
|
|
<el-tab-pane label="🤖 提示词" name="prompts" style="overflow:auto;">
|
|
<div v-if="moduleDetailPrompts && moduleDetailPrompts.length > 0">
|
|
<div v-for="p in moduleDetailPrompts" :key="p.id" style="margin-bottom:12px;border:1px solid #ebeef5;border-radius:10px;padding:12px;">
|
|
<div style="display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:6px;">
|
|
<div>
|
|
<el-tag size="small" type="info" style="margin-right:6px;">{{ p.category }}</el-tag>
|
|
<span style="font-weight:600;font-size:13px;">{{ p.key }}</span>
|
|
<div style="font-size:11px;color:#909399;margin-top:2px;">{{ p.description }}</div>
|
|
</div>
|
|
<el-switch v-model="p.enabled" @change="savePrompt(p)" size="small" :disabled="promptSaving === p.id"></el-switch>
|
|
</div>
|
|
<el-input type="textarea" v-model="p.content" :rows="5" style="font-family:monospace;font-size:12px;" @blur="savePrompt(p)"></el-input>
|
|
</div>
|
|
</div>
|
|
<div v-else style="color:#909399;padding:20px;text-align:center;">此模块暂无提示词配置</div>
|
|
</el-tab-pane>
|
|
</el-tabs>
|
|
<div style="padding-top:16px;border-top:1px solid #ebeef5;text-align:center;">
|
|
<el-button type="primary" @click="triggerModule(moduleDetail.module_id)" :loading="runningModule === moduleDetail.module_id" :disabled="!moduleDetail.enabled">立即运行此任务</el-button>
|
|
</div>
|
|
</div>
|
|
</el-drawer>
|
|
</main>
|
|
</div>
|
|
|
|
<!-- 移动端导航 -->
|
|
</div>
|
|
|
|
<script src="vue.global.prod.js"></script>
|
|
<script src="icon-components.js"></script>
|
|
<script src="element-plus.full.js"></script>
|
|
<script>
|
|
const App = {
|
|
data() {
|
|
return {
|
|
isLoggedIn: false,
|
|
isAdmin: false,
|
|
currentUser: { username: '' },
|
|
currentPage: 'overview',
|
|
loadingStats: false,
|
|
stats: {
|
|
total: 0,
|
|
pending: 0,
|
|
review: 0,
|
|
ready: 0,
|
|
published: 0,
|
|
today: 0
|
|
},
|
|
modules: [],
|
|
schedulerStatus: '',
|
|
schedulerRunning: false,
|
|
upcomingEntries: [],
|
|
loadingPlan: false,
|
|
runningModule: null,
|
|
showModuleDrawer: false,
|
|
moduleDetail: null,
|
|
moduleDetailLoading: false,
|
|
moduleDetailHistory: [],
|
|
moduleDetailPrompts: [],
|
|
promptSaving: null
|
|
};
|
|
},
|
|
methods: {
|
|
async handleLogin() {
|
|
this.loginLoading = true;
|
|
this.loginError = '';
|
|
try {
|
|
const response = await fetch('/api/auth/login', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(this.loginForm)
|
|
});
|
|
if (!response.ok) throw new Error('登录失败');
|
|
const data = await response.json();
|
|
localStorage.setItem('authToken', data.token);
|
|
this.currentUser = data.user;
|
|
this.isAdmin = data.user.role === 'admin';
|
|
this.isLoggedIn = true;
|
|
this.currentPage = 'overview';
|
|
this.fetchStats();
|
|
} catch (error) {
|
|
this.loginError = '用户名或密码错误';
|
|
} finally {
|
|
this.loginLoading = false;
|
|
}
|
|
},
|
|
handleLogout() {
|
|
localStorage.removeItem('authToken');
|
|
localStorage.removeItem('userRole');
|
|
localStorage.removeItem('currentUser');
|
|
this.isLoggedIn = false;
|
|
this.currentUser = { username: '' };
|
|
this.isAdmin = false;
|
|
window.location.href = '/login.html';
|
|
},
|
|
async fetchStats() {
|
|
this.loadingStats = true;
|
|
try {
|
|
const token = localStorage.getItem('authToken');
|
|
if (!token) {
|
|
window.location.href = '/login.html';
|
|
return;
|
|
}
|
|
const response = await fetch('/api/system/status', {
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
});
|
|
if (response.ok) {
|
|
const data = await response.json();
|
|
// API返回格式: { stats: { total, pending, review, ready, published, today } }
|
|
this.stats = {
|
|
total: data.stats?.total || 0,
|
|
pending: data.stats?.pending || 0,
|
|
review: data.stats?.review || 0,
|
|
ready: data.stats?.ready || 0,
|
|
published: data.stats?.published || 0,
|
|
today: data.stats?.today || 0
|
|
};
|
|
} else if (response.status === 401) {
|
|
// Token无效,清除并跳转登录
|
|
localStorage.removeItem('authToken');
|
|
window.location.href = '/login.html';
|
|
} else {
|
|
console.error('获取统计信息失败:', response.status, response.statusText);
|
|
this.stats = { total: 0, pending: 0, review: 0, ready: 0, published: 0, today: 0 };
|
|
}
|
|
} catch (error) {
|
|
console.error('获取统计信息失败:', error);
|
|
this.$message.error('获取统计信息失败: ' + error.message);
|
|
this.stats = { total: 0, pending: 0, review: 0, ready: 0, published: 0, today: 0 };
|
|
} finally { this.loadingStats = false; }
|
|
},
|
|
async fetchModules() {
|
|
try {
|
|
const token = localStorage.getItem('authToken');
|
|
const resp = await fetch('/api/system/modules/status', {
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
});
|
|
if (resp.ok) {
|
|
const data = await resp.json();
|
|
this.modules = data.modules || [];
|
|
const s = data.scheduler || {};
|
|
this.schedulerRunning = s.running;
|
|
this.schedulerStatus = (s.running ? `运行中 · ${s.jobs ? s.jobs.length : 0} 个任务` : '未启动');
|
|
}
|
|
} catch (e) {
|
|
console.error('获取模块状态失败:', e);
|
|
this.$message.error('获取模块状态失败: ' + e.message);
|
|
}
|
|
},
|
|
async fetchUpcomingPlan() {
|
|
this.loadingPlan = true;
|
|
try {
|
|
const token = localStorage.getItem('authToken');
|
|
const today = new Date();
|
|
today.setHours(0, 0, 0, 0);
|
|
const end = new Date(today);
|
|
end.setDate(end.getDate() + 7);
|
|
|
|
const [entries, topics] = await Promise.all([
|
|
fetch(`/api/calendar?year=${today.getFullYear()}&month=${today.getMonth() + 1}`, {
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
}).then(r => r.ok ? r.json() : []),
|
|
fetch('/api/topics?limit=200', {
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
}).then(r => r.ok ? r.json() : [])
|
|
]);
|
|
|
|
const events = [];
|
|
(entries || []).forEach(e => {
|
|
events.push({
|
|
id: 'cal_' + e.id,
|
|
date: e.planned_date,
|
|
title: e.title,
|
|
status: e.status === 'published' ? 'published' : 'planned'
|
|
});
|
|
});
|
|
(topics || []).forEach(t => {
|
|
const s = t.status;
|
|
if ((s === 'ready' || s === '待发布') && t.ready_at) {
|
|
events.push({
|
|
id: 'topic_ready_' + t.id,
|
|
date: t.ready_at,
|
|
title: t.title,
|
|
status: 'planned'
|
|
});
|
|
} else if ((s === 'published' || s === '已发布') && t.published_at) {
|
|
events.push({
|
|
id: 'topic_pub_' + t.id,
|
|
date: t.published_at,
|
|
title: t.title,
|
|
status: 'published'
|
|
});
|
|
}
|
|
});
|
|
|
|
this.upcomingEntries = events
|
|
.filter(e => { const d = new Date(e.date); return d >= today && d < end; })
|
|
.sort((a, b) => a.date.localeCompare(b.date));
|
|
} catch (e) {
|
|
console.error('获取近期计划失败:', e);
|
|
} finally { this.loadingPlan = false; }
|
|
},
|
|
goToTopics(filter) {
|
|
const url = filter ? '/topics.html?filter=' + encodeURIComponent(filter) : '/topics.html';
|
|
window.location.href = url;
|
|
},
|
|
async triggerModule(modId) {
|
|
this.runningModule = modId;
|
|
const endpoints = {
|
|
scheduled_collect: '/api/system/collect/run',
|
|
scheduled_fetch_trends: '/api/system/trends/run',
|
|
scheduled_generate: '/api/system/generate/run',
|
|
scheduled_optimize: '/api/system/review/run',
|
|
scheduled_optimize_sources: '/api/system/optimize-sources/run',
|
|
scheduled_metrics_sync: '/api/system/metrics-sync/run',
|
|
};
|
|
const endpoint = endpoints[modId];
|
|
if (!endpoint) { this.$message.error('未知模块'); this.runningModule = null; return; }
|
|
try {
|
|
const token = localStorage.getItem('authToken');
|
|
const resp = await fetch(endpoint, { method: 'POST', headers: { 'Authorization': 'Bearer ' + token } });
|
|
if (resp.ok) {
|
|
const data = await resp.json();
|
|
this.$message.success(data.message || '执行成功');
|
|
this.fetchModules();
|
|
} else {
|
|
const err = await resp.json().catch(() => ({}));
|
|
this.$message.error(err.detail || '执行失败');
|
|
}
|
|
} catch (e) {
|
|
this.$message.error('执行失败: ' + e.message);
|
|
} finally { this.runningModule = null; }
|
|
},
|
|
redirectToPage(page) {
|
|
window.location.href = page.startsWith('/') ? page : '/' + page;
|
|
},
|
|
async openModuleDetail(mod) {
|
|
this.showModuleDrawer = true;
|
|
this.moduleDetail = mod;
|
|
this.moduleDetailLoading = true;
|
|
this.moduleDetailHistory = [];
|
|
this.moduleDetailPrompts = [];
|
|
const token = localStorage.getItem('authToken');
|
|
try {
|
|
const [history, prompts] = await Promise.all([
|
|
fetch('/api/admin/task-configs/history/' + mod.module_id + '?limit=20', {
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
}).then(r => r.ok ? r.json() : []),
|
|
fetch('/api/admin/prompt-configs?module_id=' + mod.module_id, {
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
}).then(r => r.ok ? r.json() : [])
|
|
]);
|
|
this.moduleDetailHistory = history || [];
|
|
this.moduleDetailPrompts = prompts || [];
|
|
} catch (e) { this.$message.error('加载详情失败: ' + e.message); }
|
|
finally { this.moduleDetailLoading = false; }
|
|
},
|
|
async savePrompt(p) {
|
|
this.promptSaving = p.id;
|
|
const token = localStorage.getItem('authToken');
|
|
try {
|
|
await fetch('/api/admin/prompt-configs/' + p.id, {
|
|
method: 'PUT',
|
|
headers: { 'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ content: p.content, enabled: p.enabled, description: p.description, temperature: p.temperature, max_tokens: p.max_tokens })
|
|
});
|
|
this.$message.success('已保存');
|
|
} catch (e) { this.$message.error('保存失败: ' + e.message); }
|
|
finally { this.promptSaving = null; }
|
|
}
|
|
},
|
|
mounted() {
|
|
const token = localStorage.getItem('authToken');
|
|
if (!token) {
|
|
window.location.href = '/login.html';
|
|
return;
|
|
}
|
|
fetch('/api/auth/me', {
|
|
headers: { 'Authorization': 'Bearer ' + token }
|
|
})
|
|
.then(response => response.ok ? response.json() : Promise.reject())
|
|
.then(data => {
|
|
this.currentUser = data.user;
|
|
this.isAdmin = data.user.role === 'admin';
|
|
this.isLoggedIn = true;
|
|
this.currentPage = 'overview';
|
|
this.fetchStats();
|
|
this.fetchModules();
|
|
this.fetchUpcomingPlan();
|
|
})
|
|
.catch(() => {
|
|
localStorage.removeItem('authToken');
|
|
window.location.href = '/login.html';
|
|
});
|
|
}
|
|
};
|
|
|
|
const app = Vue.createApp(App);
|
|
app.use(ElementPlus);
|
|
if (window.installIcons) { window.installIcons(app); }
|
|
if (window.installUniNav) { window.installUniNav(app); }
|
|
app.mount('#app');
|
|
</script>
|
|
<script src="ai-assistant.js"></script>
|
|
</body>
|
|
</html>
|