Files
ClassHelper/packages/web-admin/src/components/UpdateCheckDialog.vue
T
LoveChengke 9a38f86cd3 feat(server,web,desktop,shared,deploy,docs): Linux 一键安装与 classhelper 运维命令、更新检查、图表去 echarts,版本统一 1.1.0
Linux 交付链(新增)
- deploy/install.sh:一键安装器(CLASSHELPER 大字 TUI、native/docker 双形态、向导选安装目录/
  端口/数据库/初始管理员密码);识别 apt/yum/dnf 只补缺的依赖、建独立系统用户、下载内置 Node
  运行时(glibc < 2.28 的 CentOS 7 自动改用 unofficial-builds 的 glibc-217 构建)、幂等覆盖安装
  (保留 config.env 与 data/,不重置密钥)、全程写 /var/log/classhelper/install.log;
  `--check` 只体检(不需要 root)、`--yes` 无人值守、`--package` 支持内网离线分发。
- deploy/classhelper:运维命令 —— status / doctor / password / backup(list,restore,schedule) /
  upgrade / rollback / start|stop|restart|reload / logs / config / port / key rotate / uninstall /
  completion / help。特权操作一律校验 EUID,关键动作写 /var/log/classhelper/audit.log。
- deploy/tools/admin-cli.mjs:离线账号工具(改密、列账号、VACUUM INTO 一致性快照、哈希回滚),
  直连数据库 —— 服务停机也能救急,不需要先有一个能登录的账号。
- deploy/{classhelper.service,profile.d,logrotate.d,systemd}/ 模板 + Dockerfile.linux-package。
- scripts/dist-server.mjs 增加 --platform linux(根脚本 `pnpm dist:server:linux`),产物
  classhelper-server-linux-x64-<版本>.tar.gz + 同名 .sha256;新增 GitHub Actions workflow 在
  ubuntu runner 上构建并挂 Release(@libsql/linux-* 这类平台相关依赖只能在 Linux 上装)。
- docs/linux-deploy.md:安装 / 运维命令 / 升级回滚 / 备份恢复 / 排障 / 安全清单 /
  Ubuntu 22.04 与 Rocky 9 的验收清单。deploy/install-linux.sh 改为转发壳,不留两份实现。

三处必须知道的取舍(已写进 AGENTS.md §5 第 59 条)
- 配置真身在 /etc/classhelper/config.env,安装目录里的 .env 是指向它的软链:Web 端
  「数据库管理 → 一键切换」改写的是 <安装目录>/.env,而 systemd 注入的是同一份配置 ——
  两处不是同一个文件时,切换会「看起来成功、重启后又连回旧库」。classhelper doctor 有专门断言。
- 升级/回滚替换程序文件用「改名 + 就位」而不是 rm+cp:升级时正在运行的就是 bin/classhelper
  自己,直接删掉同名文件会让 bash 读到半个脚本。
- 交叉构建(在非 Linux 机器上打 Linux 包)会在包内写 .cross-built 标记、doctor 据此提示:
  已核对 @libsql/linux-x64-gnu 与 -musl 就位且无 win32 残留,但 prisma CLI 的原生 schema engine
  是宿主平台的,Web 端「数据库一键切换」那一步存疑;正式产物一律走 CI。

更新检查(此前只在工作区,本次一并提交)
- 服务端 modules/update:由服务端转发 GitHub Releases(Web 端 CSP 不允许直连),离线/限流/超时
  一律收敛成 ok:false + 一句人话,失败结果同样进缓存;?force=1 只对管理员生效(避免刷爆匿名限流)。
- 版本比较放 @classhelper/shared(compareVersions / isNewerVersion),三端共用;服务端版本号
  改由 lib/version.ts 读 package.json,不再在 app.ts 里写字面量。
- Web 端顶栏「检查更新」弹窗、客户端「关于」页的检查更新与诊断信息。

Web 端 / 客户端
- 成绩图表改用自包含的轻量组件(ScoreBarChart / ScoreLineChart),不再全量引入 echarts
  (原先 echarts 占桌面端渲染产物 1.12MB、Web 端 1.13MB);柱状图是纯 HTML/CSS,折线图是
  viewBox SVG,均无 resize 监听。
- Element Plus 图标改为按需注册(两端各一份 icons.ts),新增 scripts/check-icons.mjs 静态门禁
  并挂进两端 build —— 漏注册的后果是界面静默渲染空白,只在控制台一条 warning。

版本号统一 1.1.0
- 5 份 package.json、deploy/package.runtime.json、.env.example 的 APP_VERSION、
  docker-compose 与两个 Dockerfile 的镜像标签、Linux 安装包名示例、README 首页版本;
- ClassIsland 插件 manifest.yml 与 BridgeService.PluginVersion 同步(verify:classisland-plugin
  有 manifest ↔ code 的一致性断言);
- 刻意保持不变的是**历史性表述与举例**:docs/mysql.md 的「自 v1.0.0 起内置 MySQL 适配器」、
  shared/utils.ts 讲版本比较用的 1.0.0 / 1.0.0-fix、README 验收表里的实测记录。
2026-10-05 16:39:38 +08:00

180 lines
5.5 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { formatDate, type UpdateInfo } from '@classhelper/shared';
import { updateApi } from '@/api';
/**
* 「检查更新」弹窗(Web 管理端顶栏用户菜单)。
*
* 数据来自**服务端**的 `GET /api/update/check` —— 浏览器受服务端下发的 CSP `connect-src`
* 限制,不能直连 `api.github.com`;走服务端转发还顺带让所有管理员共享同一份缓存
* (GitHub 匿名限流 60 次/小时/IP)。
*
* `ok:false` 是**正常结果**(机房没有外网 / GitHub 限流 / 超时),不是错误 ——
* 界面按"暂时查不到"呈现,并给出重试入口,而不是弹一句红字报错。
*/
const props = defineProps<{ modelValue: boolean }>();
const emit = defineEmits<{ (event: 'update:modelValue', value: boolean): void }>();
const visible = computed({
get: () => props.modelValue,
set: (value: boolean) => emit('update:modelValue', value),
});
const loading = ref(false);
const info = ref<UpdateInfo | null>(null);
/** 发布时间(本地格式),拿不到就不显示 */
const publishedText = computed(() => {
const at = info.value?.publishedAt;
return at ? formatDate(at, true) : '';
});
/**
* 用户点菜单里的「检查更新」是一次明确的手动检查,因此**绕过服务端缓存**(force=1,仅管理员生效);
* 打开弹窗时才查,而不是进页面就查 —— 没点菜单就不该产生任何外部请求。
*/
async function check(): Promise<void> {
loading.value = true;
try {
info.value = await updateApi.check(true);
} catch {
// 请求本身失败(如火并发的接口限流):http.ts 已经弹过提示,这里只保证弹窗里不留空白
info.value = null;
} finally {
loading.value = false;
}
}
function openRelease(): void {
const url = info.value?.releaseUrl;
if (!url) return;
window.open(url, '_blank', 'noopener');
}
function formatBytes(size: number): string {
if (!Number.isFinite(size) || size <= 0) return '';
const mb = size / 1024 / 1024;
return mb >= 1 ? `${mb.toFixed(1)} MB` : `${Math.round(size / 1024)} KB`;
}
// 打开时才查:关闭后清空结果,下次打开重新查一遍(避免显示上一次的陈旧结论)
watch(
() => props.modelValue,
(opened) => {
if (opened) void check();
else info.value = null;
},
);
</script>
<template>
<el-dialog v-model="visible" title="检查更新" width="520px" data-test="update-dialog">
<div v-loading="loading" class="update-body">
<template v-if="info && info.ok">
<el-alert
v-if="info.hasUpdate"
type="success"
:closable="false"
show-icon
data-test="update-found"
:title="`发现新版本 v${info.latestVersion}`"
:description="`当前版本 v${info.currentVersion}${publishedText ? ` · 发布于 ${publishedText}` : ''}`"
/>
<el-alert
v-else
type="info"
:closable="false"
show-icon
data-test="update-latest"
title="已是最新版本"
:description="`当前版本 v${info.currentVersion}(GitHub 最新为 v${info.latestVersion})`"
/>
<template v-if="info.hasUpdate">
<div v-if="info.releaseName" class="update-name">{{ info.releaseName }}</div>
<div v-if="info.notes" class="update-notes-label">更新说明</div>
<pre v-if="info.notes" class="update-notes">{{ info.notes }}</pre>
<template v-if="info.assets.length > 0">
<div class="update-notes-label">可下载文件</div>
<ul class="update-assets">
<li v-for="asset in info.assets" :key="asset.name">
<span class="update-asset-name">{{ asset.name }}</span>
<span v-if="formatBytes(asset.size)" class="update-asset-size">
{{ formatBytes(asset.size) }}
</span>
</li>
</ul>
</template>
</template>
</template>
<!-- 查不到不是错误:机房没有外网、GitHub 限流都会走到这里 -->
<el-alert
v-else-if="!loading"
type="warning"
:closable="false"
show-icon
data-test="update-unavailable"
title="暂时无法检查更新"
:description="info?.error ?? '请稍后重试;若服务器没有外网,可手动打开项目 Release 页面查看'"
/>
</div>
<template #footer>
<el-button @click="visible = false">关闭</el-button>
<el-button :loading="loading" @click="check()">重新检查</el-button>
<el-button v-if="info?.ok && info.hasUpdate" type="primary" @click="openRelease">前往下载</el-button>
</template>
</el-dialog>
</template>
<style scoped>
.update-body {
min-height: 72px;
}
.update-name {
margin-top: 12px;
font-size: 13px;
font-weight: 600;
color: var(--el-text-color-primary);
}
.update-notes-label {
margin: 12px 0 6px;
font-size: 12px;
color: var(--el-text-color-secondary);
}
.update-notes {
margin: 0;
padding: 10px 12px;
max-height: 200px;
overflow: auto;
background: var(--el-fill-color-light);
border-radius: var(--ch-radius-sm);
font-size: 12px;
line-height: 1.7;
white-space: pre-wrap;
word-break: break-word;
font-family: inherit;
color: var(--el-text-color-regular);
}
.update-assets {
margin: 0;
padding-left: 18px;
font-size: 12px;
line-height: 1.9;
color: var(--el-text-color-regular);
}
.update-asset-size {
margin-left: 6px;
color: var(--el-text-color-secondary);
}
</style>