feat: 增加管理后台帮助页

This commit is contained in:
Nixevol
2026-10-21 17:42:28 +08:00
parent 1a39419449
commit 0f0bb206e9
5 changed files with 870 additions and 0 deletions
+584
View File
@@ -0,0 +1,584 @@
export type HelpBlock =
| { kind: "p"; text: string }
| { kind: "h3"; text: string }
| { kind: "list"; items: string[] }
| { kind: "table"; columns: string[]; rows: string[][] }
| { kind: "code"; text: string };
export interface HelpSection {
id: string;
title: string;
blocks: HelpBlock[];
}
export const helpSections: HelpSection[] = [
{
id: "about",
title: "这是什么",
blocks: [
{
kind: "p",
text: "NixMsg 是你自己的一台消息中转。设备、程序和 App 作为设备端连到这台服务器,互相发短消息,或在一个群组里发同一条。",
},
{
kind: "p",
text: "这个网页是管理后台。用它开通设备、管理群组、查看一条消息有没有送到。后台不显示消息正文,也不是聊天窗口。聊天或业务界面由接入方自己做。",
},
{
kind: "list",
items: [
"设备往往在路由器后面,不能互相直连。消息先到这台服务器,再转给对方。",
"同一编号同时只能有一处在线。",
"对方不在线时,可以由发送方决定留下一段时间,或直接丢掉。",
"可以定时发送、稍等再发、撤回,以及要求对方确认收到。",
"服务器不保存可翻看的聊天记录。",
],
},
],
},
{
id: "server",
title: "服务器做什么",
blocks: [
{
kind: "p",
text: "服务器负责身份、在线和投递。后台管的是这台服务器上的设备和群组;真正收发消息的是连上来的设备端。",
},
{
kind: "table",
columns: ["它负责", "你这边怎么用"],
rows: [
["给设备编号和登录密码", "在「设备端」开通,或打开自助注册让设备自己登记"],
["维持连接,并保证同一编号只有一处在线", "设备用编号和密码登录,之后改用会话令牌重连"],
["把消息转到一个设备或一个群组", "由设备端发送,后台只看送到没有"],
["按规则留下、丢弃、定时或撤回", "时限不能超过「设置」里看到的上限"],
["给程序一个管理令牌", "在「API 令牌」创建,用来代替网页登录调用管理接口"],
],
},
{
kind: "p",
text: "设备连接的地址和打开本网页的主机相同,路径是 /mqtt。网页是 https 时用 wss,否则用 ws。例如网页是 https://example.com,连接地址就是 wss://example.com/mqtt。",
},
],
},
{
id: "endpoints",
title: "设备端",
blocks: [
{
kind: "p",
text: "一台设备、一个程序或一个 App 安装,对应一个设备端。编号全局唯一。来源分为后台开通和自助注册,两边开出来的端没有区别。",
},
{
kind: "h3",
text: "查找",
},
{
kind: "table",
columns: ["控件", "怎么填", "作用"],
rows: [
["来源", "全部、后台开通或自助注册", "按开通方式筛选"],
["在线", "全部、在线或离线", "看现在有没有连着"],
["编号/名称", "编号开头,或名称里包含的字", "不区分大小写"],
["查询", "点按钮", "按上面的条件刷新列表"],
],
},
{
kind: "h3",
text: "开通",
},
{
kind: "p",
text: "点右上角「开通」。留空的编号和登录密码由服务器生成。生成的登录密码只在成功后出现一次,请马上复制或下载。",
},
{
kind: "table",
columns: ["项目", "怎么填", "作用"],
rows: [
["编号", "1–64 位,只能是小写字母、数字、_、.、-;可留空", "设备登录时用的身份。留空会生成类似 e_ 加 8 位的编号"],
["名称", "最多 64 个字,可留空", "方便你认出这台设备,不参与登录"],
["登录密码", "8–128 位,不能以 nst_ 开头;可留空", "第一次连接用。留空则生成,只显示这一次"],
["对话密码", "4–64 位,可留空", "给这台设备加一道口令。别人发消息给它之前要先对上。留空表示不设"],
["默认延迟(秒)", "0 到页面上写的上限", "这台设备发出的消息默认晚这么多秒再投递。0 表示马上发"],
["备注", "最多 200 字,可留空", "只给你自己看"],
["开通", "点按钮", "创建成功后,把编号和密码交给对应设备"],
["取消", "点按钮", "关闭窗口,不创建"],
],
},
{
kind: "h3",
text: "CSV 导入",
},
{
kind: "p",
text: "一次开通多台。文件用 UTF-8。表头必须是下面这一行,最多 1000 条。先全部检查,有一行不合格就一条都不开通,并指出行号和原因。密码留空会生成,只在导入结果里出现一次,请点「下载」保存。",
},
{
kind: "code",
text: "id,name,login_password,talk_password,default_delay_seconds,remark",
},
{
kind: "h3",
text: "批量停用、批量删除",
},
{
kind: "p",
text: "先勾选列表中的设备。停用会立刻断开,并作废还没送到的消息,不能恢复那些消息;重新启用后可以再登录。删除同样会断开并作废消息,还会让它退出所有群。它当群主时,群主交给最早加入的其他成员;群里没有别人就解散。编号可以以后重新开通,新端不继承旧数据。",
},
{
kind: "h3",
text: "每一行的操作",
},
{
kind: "p",
text: "点一行右侧的操作图标。",
},
{
kind: "table",
columns: ["菜单", "作用"],
rows: [
["编辑", "改名称、默认延迟、是否启用、备注。不能在这里改编号和登录密码"],
["重置密码", "换一个登录密码,旧的会话令牌立即失效。新密码只显示一次"],
["对话密码", "设置或清除。留空并确定就是清除。换密码后,以前对上过的授权失效"],
["解锁", "解除这台设备因密码输错而被锁住的登录。已经在线的连接不受影响"],
["踢下线", "只断开当前连接。令牌还在,设备会自己重连。要让它连不上,请停用"],
],
},
],
},
{
id: "groups",
title: "群组",
blocks: [
{
kind: "p",
text: "群组用来把同一条消息发给多名成员。群主是一名设备端。后台建群不需要对话密码。",
},
{
kind: "table",
columns: ["控件", "怎么填", "作用"],
rows: [
["搜索群组", "名称里的字,回车", "按名称筛选"],
["新建群组", "点按钮", "打开创建窗口"],
],
},
{
kind: "h3",
text: "新建群组",
},
{
kind: "table",
columns: ["项目", "怎么填", "作用"],
rows: [
["编号", "不用填", "创建后自动分配"],
["名称", "群的名字", "在列表里显示,也可以稍后改"],
["群主编号", "一个已经存在的设备编号", "这名设备是群主"],
["成员", "设备编号,用逗号或空格分开", "一并加入。某个编号不存在时,群仍会创建,失败的编号会列出来"],
["创建", "点按钮", "建群"],
["取消", "点按钮", "不创建"],
],
},
{
kind: "h3",
text: "列表上的操作",
},
{
kind: "table",
columns: ["菜单", "作用"],
rows: [
["详情", "看成员、改名、加人或调整群主"],
["解散", "删除这个群。确认后不能撤销"],
],
},
{
kind: "h3",
text: "群详情",
},
{
kind: "table",
columns: ["项目", "怎么填", "作用"],
rows: [
["名称 / 改名", "新名称后点改名", "只改显示名,编号不变"],
["加人", "成员编号,逗号分开,再点加人", "把已有设备加进群"],
["设为群主", "在成员行上操作并确认", "群主换成这名成员"],
["移除", "在成员行上操作并确认", "把这名成员移出群"],
["关闭", "点按钮", "关掉详情"],
],
},
],
},
{
id: "messages",
title: "投递记录",
blocks: [
{
kind: "p",
text: "这里看消息有没有送到,不看内容。记录保留一段时间后会清掉,具体天数在「设置」的运行参数里。",
},
{
kind: "table",
columns: ["控件", "怎么填", "作用"],
rows: [
["发送方", "设备编号", "谁发出的"],
["设备编号", "接收设备的编号", "发给这台设备的记录"],
["群组编号", "群编号", "发给这个群的记录"],
["状态", "全部、定时中、投递中、已完成", "整条消息现在处在哪一步"],
["时间", "选择起止时间,可清空", "按创建时间筛选"],
["查询", "点按钮", "按条件刷新"],
["详情", "一行上的操作", "看每个接收端是待投递、已收下、已撤回、已过期、已丢弃还是已拒绝"],
["关闭", "详情窗口里", "关掉详情"],
],
},
{
kind: "list",
items: [
"定时中:还没到设定的发送时刻。",
"投递中:已经开始送,还有接收端没结束。",
"已完成:各个接收端都有了结果。",
"待投递:还没被对方收下。已收下:对方确认拿到。已撤回:发送方撤回了。已过期:离线保留时间到了。已丢弃:对方当时不在线,且没有要求留下。已拒绝:例如设备已停用,或没有对话授权。",
],
},
],
},
{
id: "tokens",
title: "API 令牌",
blocks: [
{
kind: "p",
text: "程序调用管理接口时用令牌,不必拿管理员密码去登录。令牌权限等同管理员,但不能改管理员密码,也不能创建、停用或删除令牌。令牌不会过期;停用或删除后立刻失效。明文只在创建成功时出现一次。",
},
{
kind: "table",
columns: ["控件", "怎么填", "作用"],
rows: [
["创建令牌", "点按钮", "打开创建窗口"],
["名称", "好认的名字,例如「开通设备的程序」", "只用于辨认,调用时不用这个名字"],
["创建", "点按钮", "生成令牌。马上复制保存"],
["取消", "点按钮", "不创建"],
["停用 / 启用", "一行上的操作", "停用后这个令牌不能再调用;启用后恢复"],
["删除", "一行上的操作并确认", "永久作废,不能恢复成原来的明文"],
],
},
],
},
{
id: "settings",
title: "设置",
blocks: [
{
kind: "h3",
text: "自助注册",
},
{
kind: "p",
text: "打开后,设备可以自己登记,不必由你逐台开通。登记时必须带上安全码。安全码相当于邀请码,请只发给你允许接入的一方。",
},
{
kind: "table",
columns: ["项目", "怎么填", "作用"],
rows: [
["开放注册", "开关", "打开才接受自助登记;关掉后新的登记会被拒绝"],
["安全码", "8–64 个字符,或点「生成」", "设备登记时要提交的码。生成会换成一个新的 16 位码"],
["保存", "点按钮", "写入当前开关和安全码。开启时必须已有合法安全码"],
["更新时间", "不用填", "上次保存的时间"],
],
},
{
kind: "h3",
text: "管理员密码",
},
{
kind: "table",
columns: ["项目", "怎么填", "作用"],
rows: [
["原密码", "现在的管理员密码", "确认是你本人"],
["新密码", "至少 12 位", "之后登录用的密码"],
["确认新密码", "再输入一遍", "避免打错"],
["保存", "点按钮", "改成功后,请用新密码登录"],
],
},
{
kind: "h3",
text: "运行参数",
},
{
kind: "p",
text: "这里只展示服务器已经生效的上限,网页里不能改。发消息、定时、离线保留和建群时,不要超过这些数。",
},
{
kind: "list",
items: [
"单条消息最大字节、附加信息最大字节:一条消息能带多少内容。",
"离线保留最长时间、定时最远时间:对方不在线时最多留多久,以及定时最远能定到什么时候。",
"群组人数上限:一个群最多多少人。",
"短暂断线宽限:刚断开的一小段时间里,仍可按在线处理。",
"记录保留天数:投递记录留多久。",
],
},
],
},
{
id: "connect",
title: "设备怎么连",
blocks: [
{
kind: "p",
text: "设备不打开这个网页。它连到 /mqtt,用自己的编号登录。建议使用对应语言的 SDK,连接、断线重连和令牌都由 SDK 处理。",
},
{
kind: "list",
items: [
"第一次用编号加登录密码。成功后服务器发给会话令牌,请让程序保存令牌,以后重连不要再传密码。",
"同一编号只能一处在线。别处用密码登录后,原来的令牌失效。",
"换网络或服务器重启后,用原令牌重连即可。",
"管理员踢下线只断开当前连接,令牌还在,SDK 会重连。重置密码、停用或删除会让令牌失效。",
"发给一个设备时目标类型是 endpoint,发给一个群时是 group。",
"可以设置延迟、发送时刻、离线保留时长,以及是否要回执。延迟和发送时刻不要同时填。",
"不要求留下时,对方当时不在线,这条会被丢掉。",
"对方设了对话密码时,要先用正确的对话密码取得授权,才能把消息发给它。",
],
},
{
kind: "h3",
text: "自助登记",
},
{
kind: "p",
text: "「设置」里开放注册之后,设备也可以自己登记,不必先在后台开通。",
},
{
kind: "code",
text: "POST /api/client/register\nContent-Type: application/json\n\n{\n \"registration_code\": \"安全码\",\n \"id\": \"\",\n \"login_password\": \"\",\n \"name\": \"门口\"\n}",
},
{
kind: "p",
text: "编号和登录密码可以留空,由服务器生成。成功时返回编号;密码是生成的才会在结果里出现。注册没打开、安全码不对,都会被拒绝。",
},
],
},
{
id: "sdk",
title: "SDK",
blocks: [
{
kind: "p",
text: "四种 SDK 的用法一致:连上、保存令牌、收消息、发送、关闭。下面是安装位置。版本以仓库里已发布的为准,示例使用 0.1.0。连接地址换成你这台服务器的 /mqtt。",
},
{
kind: "h3",
text: "Go",
},
{
kind: "code",
text: "go get git.asio.asia/nixevol/NixMsg/sdk/go@v0.1.0",
},
{
kind: "p",
text: "公共代理访问不到 git.asio.asia 时,先执行 go env -w GOPRIVATE=git.asio.asia。",
},
{
kind: "h3",
text: "JavaScript / TypeScript",
},
{
kind: "p",
text: "支持 Node.js 20 及以上,也支持浏览器。在项目的 .npmrc 里写上仓库,再安装。",
},
{
kind: "code",
text: "@nixevol:registry=https://git.asio.asia/api/packages/nixevol/npm/\n\nnpm install @nixevol/nixmsg",
},
{
kind: "h3",
text: "Python",
},
{
kind: "p",
text: "需要 Python 3.10 及以上。",
},
{
kind: "code",
text: "pip install nixmsg --index-url https://git.asio.asia/api/packages/nixevol/pypi/simple/",
},
{
kind: "h3",
text: "Java / Android",
},
{
kind: "p",
text: "Maven 仓库是 https://git.asio.asia/api/packages/nixevol/maven 。Android 最低为 API 24。长连接要放在应用自己的前台服务里,SDK 不替你建服务。",
},
{
kind: "code",
text: "asia.asio.nixmsg:nixmsg-sdk:0.1.0",
},
],
},
{
id: "rules",
title: "调用约定",
blocks: [
{
kind: "p",
text: "管理接口的地址是本网页同一台主机下的 /api/admin/。请求和响应都是 JSON,字段名用下划线。时间是 Unix 毫秒。任何管理接口都不会返回消息正文。",
},
{
kind: "h3",
text: "两种登录方式",
},
{
kind: "list",
items: [
"网页登录后,浏览器带上 Cookie。除登录以外,凡是会改数据的请求都要加请求头 X-Nixmsg-Request: 1。缺了会返回 403。读取用的 GET 不用加。",
"程序调用时加请求头 Authorization: Bearer 加上令牌。这种方式不再看 Cookie,也不用加 X-Nixmsg-Request。",
],
},
{
kind: "h3",
text: "响应",
},
{
kind: "code",
text: "{\"ok\": true, \"data\": {}}\n\n{\"ok\": false, \"error\": {\"code\": \"unauthorized\", \"message\": \"未登录\"}}",
},
{
kind: "p",
text: "列表的 data 里有 items、next_cursor 和 total。next_cursor 为空表示没有下一页。默认每页 50 条,最多 200 条,用查询参数 cursor 和 limit 翻页。",
},
{
kind: "table",
columns: ["状态", "code", "含义"],
rows: [
["400", "bad_request", "字段不合法"],
["401", "unauthorized", "未登录、密码错误或令牌无效"],
["403", "forbidden", "缺少 X-Nixmsg-Request,或令牌不能访问这个地址"],
["404", "not_found", "没有这个设备、群或记录"],
["409", "id_taken", "编号已被占用"],
["429", "rate_limited", "试错太多,暂时锁定"],
["503", "busy", "服务器暂时不可用,可以稍后再试"],
],
},
],
},
{
id: "api",
title: "接口说明",
blocks: [
{
kind: "p",
text: "下表是全部管理接口。会改数据的请求,用 Cookie 时必须带 X-Nixmsg-Request: 1。标成「不可」的,令牌调用会被拒绝。",
},
{
kind: "table",
columns: ["方法", "路径", "作用", "令牌"],
rows: [
["POST", "/api/admin/login", "登录", "不用"],
["POST", "/api/admin/logout", "结束当前网页会话", "可以"],
["GET", "/api/admin/me", "当前是谁在登录", "可以"],
["POST", "/api/admin/password", "修改管理员密码", "不可"],
["GET", "/api/admin/endpoints", "设备列表", "可以"],
["POST", "/api/admin/endpoints", "开通一台设备", "可以"],
["POST", "/api/admin/endpoints/import", "用 CSV 批量开通", "可以"],
["POST", "/api/admin/endpoints/batch", "批量停用、启用或删除", "可以"],
["GET", "/api/admin/endpoints/{id}", "一台设备的详情", "可以"],
["PATCH", "/api/admin/endpoints/{id}", "修改名称、备注、延迟或启停", "可以"],
["DELETE", "/api/admin/endpoints/{id}", "删除设备", "可以"],
["POST", "/api/admin/endpoints/{id}/kick", "踢下线", "可以"],
["POST", "/api/admin/endpoints/{id}/reset-login-password", "重置登录密码", "可以"],
["PUT", "/api/admin/endpoints/{id}/talk-password", "设置或清除对话密码", "可以"],
["POST", "/api/admin/endpoints/{id}/unlock", "解除登录锁定", "可以"],
["GET", "/api/admin/groups", "群组列表", "可以"],
["POST", "/api/admin/groups", "新建群组", "可以"],
["GET", "/api/admin/groups/{id}", "群详情和成员", "可以"],
["PATCH", "/api/admin/groups/{id}", "改名", "可以"],
["DELETE", "/api/admin/groups/{id}", "解散", "可以"],
["POST", "/api/admin/groups/{id}/members", "加人", "可以"],
["DELETE", "/api/admin/groups/{id}/members/{endpointId}", "移除成员", "可以"],
["POST", "/api/admin/groups/{id}/transfer", "转让群主", "可以"],
["GET", "/api/admin/messages", "投递记录列表", "可以"],
["GET", "/api/admin/messages/{seq}", "一条记录的各接收端", "可以"],
["GET", "/api/admin/tokens", "令牌列表", "不可"],
["POST", "/api/admin/tokens", "创建令牌", "不可"],
["PATCH", "/api/admin/tokens/{id}", "改名或启停", "不可"],
["DELETE", "/api/admin/tokens/{id}", "删除令牌", "不可"],
["GET", "/api/admin/registration", "读取自助注册", "可以"],
["PUT", "/api/admin/registration", "保存自助注册", "可以"],
["GET", "/api/admin/settings", "读取运行参数", "可以"],
],
},
{
kind: "h3",
text: "登录与密码",
},
{
kind: "p",
text: "登录不需要事先有 Cookie,也不用加 X-Nixmsg-Request。用户名固定为 admin。",
},
{
kind: "code",
text: "POST /api/admin/login\n{\"username\": \"admin\", \"password\": \"当前密码\"}",
},
{
kind: "p",
text: "修改密码要提交原密码和新密码。新密码至少 12 位。这个地址不能用令牌调用。",
},
{
kind: "code",
text: "POST /api/admin/password\n{\"old_password\": \"原密码\", \"new_password\": \"新密码\"}",
},
{
kind: "h3",
text: "设备",
},
{
kind: "p",
text: "列表可用查询参数 source(admin 或 self)、online(true 或 false)、enabled、query、cursor、limit。开通时编号和登录密码留空字符串就会生成。编号冲突返回 409。",
},
{
kind: "code",
text: "POST /api/admin/endpoints\n{\n \"id\": \"\",\n \"name\": \"门口\",\n \"remark\": \"\",\n \"login_password\": \"\",\n \"talk_password\": \"\",\n \"default_delay_seconds\": 0\n}",
},
{
kind: "p",
text: "导入的内容类型是 text/csv,或表单字段 file。批量操作的 action 是 disable、enable 或 delete。重置密码的请求体可以是空对象,或 login_password 留空以生成。对话密码传空字符串表示清除。踢下线的结果里 kicked 为 false 表示当时本来就不在线。",
},
{
kind: "h3",
text: "群组",
},
{
kind: "p",
text: "列表可用 query 按名称筛选。创建时 id 留空会生成。member_ids 里有不存在的编号时,群仍然创建,失败项在 failed 里。加人同样返回 failed。转让群主要求 endpoint_id 是已在群里的成员。",
},
{
kind: "code",
text: "POST /api/admin/groups\n{\n \"id\": \"\",\n \"name\": \"一组\",\n \"owner_id\": \"设备编号\",\n \"member_ids\": [\"另一台\"]\n}",
},
{
kind: "h3",
text: "投递记录",
},
{
kind: "p",
text: "列表查询参数有 sender_id、endpoint_id、group_id、state、from_ms、to_ms,以及 cursor、limit。state 取 scheduled、dispatched 或 completed。详情地址里的 seq 是列表中的序号。两边都没有正文。",
},
{
kind: "h3",
text: "令牌、注册和运行参数",
},
{
kind: "p",
text: "创建令牌只提交 name,返回的 token 只此一次。修改时可以只提交 name 或 enabled。令牌相关地址都不能用令牌自己调用。",
},
{
kind: "p",
text: "保存注册时,enabled、code、generate 至少给一项。generate 为 true 时由服务器生成 16 位安全码,并忽略你提交的 code。要打开注册,最终必须有 8–64 位的安全码。运行参数只有读取,没有修改接口。",
},
{
kind: "code",
text: "PUT /api/admin/registration\n{\"enabled\": true, \"generate\": true}",
},
],
},
];
+2
View File
@@ -6,6 +6,7 @@ import type { MenuOption } from "naive-ui";
import {
DesktopOutline,
GridOutline,
HelpCircleOutline,
KeyOutline,
LogOutOutline,
MoonOutline,
@@ -36,6 +37,7 @@ const menuOptions: MenuOption[] = [
{ label: "投递记录", key: "/messages", icon: renderIcon(PaperPlaneOutline) },
{ label: "API 令牌", key: "/tokens", icon: renderIcon(KeyOutline) },
{ label: "设置", key: "/settings", icon: renderIcon(SettingsOutline) },
{ label: "帮助", key: "/help", icon: renderIcon(HelpCircleOutline) },
];
const activeKey = computed(() => route.path);
+1
View File
@@ -22,6 +22,7 @@ export const router = createRouter({
{ path: "messages", name: "messages", component: () => import("../views/MessagesView.vue") },
{ path: "tokens", name: "tokens", component: () => import("../views/TokensView.vue") },
{ path: "settings", name: "settings", component: () => import("../views/SettingsView.vue") },
{ path: "help", name: "help", component: () => import("../views/HelpView.vue") },
],
},
],
+18
View File
@@ -0,0 +1,18 @@
import { mount } from "@vue/test-utils";
import { describe, expect, it } from "vitest";
import HelpView from "./HelpView.vue";
describe("HelpView", () => {
it("介绍功能和接口,不写概览和导航栏底部按钮", () => {
const wrapper = mount(HelpView);
const text = wrapper.text();
expect(text).toContain("这是什么");
expect(text).toContain("设备端");
expect(text).toContain("SDK");
expect(text).toContain("POST");
expect(text).toContain("/api/admin/login");
expect(text).not.toContain("概览");
expect(text).not.toContain("跟随系统");
expect(text).not.toContain("退出登录");
});
});
+265
View File
@@ -0,0 +1,265 @@
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from "vue";
import PageHeader from "@/components/PageHeader.vue";
import { helpSections, type HelpBlock } from "@/help/guide";
const active = ref(helpSections[0].id);
const article = ref<HTMLElement | null>(null);
let observer: IntersectionObserver | null = null;
function go(id: string) {
active.value = id;
document.getElementById(id)?.scrollIntoView({ block: "start" });
}
function isTable(block: HelpBlock): block is Extract<HelpBlock, { kind: "table" }> {
return block.kind === "table";
}
onMounted(() => {
const root = article.value;
if (!root || typeof IntersectionObserver === "undefined") return;
observer = new IntersectionObserver(
(entries) => {
const visible = entries
.filter((entry) => entry.isIntersecting)
.sort((a, b) => b.intersectionRatio - a.intersectionRatio)[0];
const id = visible?.target.id;
if (id) active.value = id;
},
{ root, rootMargin: "0px 0px -65% 0px", threshold: [0, 0.25, 0.6] },
);
for (const section of helpSections) {
const node = document.getElementById(section.id);
if (node) observer.observe(node);
}
});
onBeforeUnmount(() => observer?.disconnect());
</script>
<template>
<div class="page">
<PageHeader title="帮助" />
<div class="body">
<nav class="toc" aria-label="帮助目录">
<a
v-for="section in helpSections"
:key="section.id"
:href="`#${section.id}`"
:class="{ on: active === section.id }"
:aria-current="active === section.id ? 'true' : undefined"
@click.prevent="go(section.id)"
>
{{ section.title }}
</a>
</nav>
<article ref="article" class="article">
<section v-for="section in helpSections" :id="section.id" :key="section.id" class="chapter">
<h2>{{ section.title }}</h2>
<template v-for="(block, index) in section.blocks" :key="`${section.id}-${index}`">
<p v-if="block.kind === 'p'">{{ block.text }}</p>
<h3 v-else-if="block.kind === 'h3'">{{ block.text }}</h3>
<ul v-else-if="block.kind === 'list'">
<li v-for="item in block.items" :key="item">{{ item }}</li>
</ul>
<pre v-else-if="block.kind === 'code'"><code>{{ block.text }}</code></pre>
<div v-else-if="isTable(block)" class="table-wrap">
<table>
<thead>
<tr>
<th v-for="column in block.columns" :key="column">{{ column }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(row, rowIndex) in block.rows" :key="rowIndex">
<td v-for="(cell, cellIndex) in row" :key="cellIndex">{{ cell }}</td>
</tr>
</tbody>
</table>
</div>
</template>
</section>
</article>
</div>
</div>
</template>
<style scoped>
.page {
display: flex;
flex-direction: column;
height: 100%;
min-height: 0;
}
.body {
flex: 1;
min-height: 0;
display: flex;
}
.toc {
width: 168px;
flex-shrink: 0;
overflow: auto;
padding: 12px 8px 24px;
border-right: 1px solid #d0d7de;
}
.toc a {
display: block;
margin: 1px 4px;
padding: 6px 10px;
border-radius: 6px;
color: #1f2328;
font-size: 13px;
line-height: 1.4;
text-decoration: none;
}
.toc a:hover {
background: rgba(9, 105, 218, 0.08);
}
.toc a.on {
color: #0969da;
background: rgba(9, 105, 218, 0.12);
font-weight: 600;
}
.toc a:focus-visible {
outline: 2px solid #0969da;
outline-offset: 1px;
}
.article {
flex: 1;
min-width: 0;
overflow: auto;
padding: 8px 28px 48px;
}
.chapter {
max-width: 920px;
padding-top: 20px;
scroll-margin-top: 8px;
}
.chapter h2 {
margin: 0 0 12px;
font-size: 20px;
font-weight: 650;
letter-spacing: -0.02em;
line-height: 1.3;
}
.chapter h3 {
margin: 22px 0 8px;
font-size: 15px;
font-weight: 650;
line-height: 1.4;
}
.chapter p,
.chapter ul {
max-width: 72ch;
}
.chapter p,
.chapter li {
margin: 0;
font-size: 14px;
line-height: 1.7;
color: #1f2328;
}
.chapter p + p,
.chapter p + ul,
.chapter ul + p,
.chapter h3 + p {
margin-top: 8px;
}
.chapter ul {
margin: 8px 0 0;
padding-left: 1.2em;
}
.chapter li + li {
margin-top: 4px;
}
.table-wrap {
margin-top: 12px;
overflow-x: auto;
border: 1px solid #d0d7de;
border-radius: 6px;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 13px;
line-height: 1.55;
}
th,
td {
padding: 8px 10px;
text-align: left;
vertical-align: top;
border-bottom: 1px solid #d0d7de;
}
tr:last-child td {
border-bottom: 0;
}
th {
background: #f6f8fa;
font-weight: 650;
white-space: nowrap;
}
td:first-child {
white-space: nowrap;
}
pre {
margin: 12px 0 0;
padding: 12px 14px;
overflow: auto;
border: 1px solid #d0d7de;
border-radius: 6px;
background: #f6f8fa;
font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
font-size: 12.5px;
line-height: 1.55;
}
code {
font-family: inherit;
}
:global(html.dark) .toc {
border-right-color: #30363d;
}
:global(html.dark) .toc a {
color: #e6edf3;
}
:global(html.dark) .toc a.on {
color: #4493f8;
background: rgba(68, 147, 248, 0.16);
}
:global(html.dark) .chapter p,
:global(html.dark) .chapter li {
color: #e6edf3;
}
:global(html.dark) .table-wrap,
:global(html.dark) th,
:global(html.dark) td,
:global(html.dark) pre {
border-color: #30363d;
}
:global(html.dark) th,
:global(html.dark) pre {
background: #161b22;
}
@media (max-width: 760px) {
.body {
flex-direction: column;
}
.toc {
width: auto;
display: flex;
gap: 4px;
overflow-x: auto;
border-right: 0;
border-bottom: 1px solid #d0d7de;
padding: 8px;
}
.toc a {
white-space: nowrap;
}
.article {
padding: 4px 16px 32px;
}
}
</style>