轻提示铺开到全部页面;内核状态悬停变重启;GEO 支持单文件下载

侧栏动作排撤掉重启图标,内核状态(圆点加版本号)本身变成按钮:悬停
换层显示「重启内核」,不在线时只当状态看。行高压成 1 修掉圆点和等宽
字体不居中的问题。

四个页面的一次性反馈(保存、删除、更新订阅、断开连接、测延迟结论)
全部改走 toast,commit() 改返回成败给「失败不关对话框」用;持续状态
(连接页轮询失败、请求页日志流失败)留在页内,会自动消失的提示装不下
需要一直可见的信息。toast 加 info 类别给中性结论用。

GEO 每行的更新改成单独下载那一个文件:内核只有全量更新的口子,单文件
只能服务端自己下(POST /api/geo/sync),代价是只有形状校验(MaxMind
末尾标记、geodata 首字节,shared/geo.ts 带测试)且内核重启后才换用新
文件;「更新全部」文字按钮保留内核的全量口子,有完整校验和热加载。
上传两行的按钮改「选择或拖放文件」,投放区拖入高亮,恢复策略挪到
恢复行下方。
This commit is contained in:
2026-08-12 02:20:46 +08:00
parent f761d13579
commit b276c4a8fe
13 changed files with 366 additions and 304 deletions
+22 -82
View File
@@ -26,6 +26,7 @@ import {
import type { IniImportPlan, RuleIssue } from '@shared/rules.ts'
import type { ConfigObject } from '../../vendor/config-editor/index.ts'
import { ApiError, api } from '../api'
import { toast, toastError } from '../toast'
import type { RuleProviderInfo } from '../api'
import { kernel } from '../runtime'
import ConfirmDialog from '../components/ConfirmDialog.vue'
@@ -39,7 +40,6 @@ import IconEdit from '~icons/ri/edit-line'
import IconDelete from '~icons/ri/delete-bin-line'
import IconRefresh from '~icons/ri/refresh-line'
import IconLoad from '~icons/ri/loader-4-line'
import IconClose from '~icons/ri/close-line'
const props = defineProps<{ data: ConfigObject; revision: string }>()
@@ -93,24 +93,19 @@ const issuesByIndex = computed(() => {
const missingLan = computed(() => missingLanRules(rules.value))
const saving = ref(false)
const failure = ref<{ message: string; hint: string } | null>(null)
const done = ref('')
/** 所有改配置文件的动作都从这里走。 */
async function commit(raw: ConfigObject, success: string) {
/** 所有改配置文件的动作都从这里走。反馈走右上角轻提示,返回值告知成败。 */
async function commit(raw: ConfigObject, success: string): Promise<boolean> {
saving.value = true
failure.value = null
done.value = ''
try {
const result = await api.applyConfig(raw, props.revision)
// 没重载有两种情况(内容没有变化、内核不在线只写了文件),都要如实说
done.value = result.reloaded ? success : `${success}(${result.reloadMessage})`
toast(result.reloaded ? success : `${success}(${result.reloadMessage})`)
emit('saved')
return true
} catch (error) {
failure.value =
error instanceof ApiError
? { message: error.message, hint: error.hint }
: { message: String(error), hint: '' }
toastError(error)
return false
} finally {
saving.value = false
}
@@ -147,7 +142,7 @@ async function submitRule(ruleText: string) {
editing === null
? insertBeforeMatch([...seed, ...rules.value], [ruleText])
: rules.value.map((rule, i) => (i === editing ? ruleText : rule))
await commit(
const ok = await commit(
withRules(next),
editing === null
? seed.length > 0
@@ -156,7 +151,7 @@ async function submitRule(ruleText: string) {
: '已保存',
)
// 失败时不能关对话框——关了再打开就是空表单
if (!failure.value) ruleFormOpen.value = false
if (ok) ruleFormOpen.value = false
}
async function move(index: number, delta: -1 | 1) {
@@ -230,17 +225,17 @@ async function submitGroup(entry: {
try {
await api.uploadProviderFile(entry.declaration.path, entry.file.content)
} catch (error) {
failure.value = {
message: error instanceof ApiError ? error.message : String(error),
toast(error instanceof ApiError ? error.message : String(error), {
kind: 'error',
hint: '清单没有写入,配置文件也没有改动。',
}
})
return
}
}
const next = clone()
setRuleProviders(next, { ...ruleProvidersOf(next), [entry.name]: entry.declaration })
await commit(next, `已新增规则组 ${entry.name}`)
if (!failure.value) {
const ok = await commit(next, `已新增规则组 ${entry.name}`)
if (ok) {
groupFormOpen.value = false
void reloadProviderState()
}
@@ -251,11 +246,11 @@ async function submitImport(plan: IniImportPlan) {
setRuleProviders(next, { ...ruleProvidersOf(next), ...plan.providers })
setRules(next, [...insertBeforeMatch(rules.value, plan.rules), ...plan.finals])
const added = plan.rules.length + plan.finals.length
await commit(
const ok = await commit(
next,
`已导入 ${Object.keys(plan.providers).length} 个规则组、${String(added)} 条规则`,
)
if (!failure.value) {
if (ok) {
importOpen.value = false
void reloadProviderState()
}
@@ -293,8 +288,8 @@ async function removeProviderConfirmed() {
const rest = ruleProvidersOf(next)
delete rest[name]
setRuleProviders(next, rest)
await commit(next, `已删除规则组 ${name}`)
if (!failure.value) void reloadProviderState()
const ok = await commit(next, `已删除规则组 ${name}`)
if (ok) void reloadProviderState()
}
/** 正在等内核重新拉取的规则组名字。 */
@@ -304,16 +299,15 @@ const updating = ref<string | null>(null)
async function updateNow(name: string) {
if (updating.value !== null || saving.value) return
updating.value = name
failure.value = null
done.value = ''
try {
await api.updateRuleProvider(name)
await reloadProviderState()
toast(`已更新 ${name}`)
} catch (error) {
failure.value = {
message: error instanceof ApiError ? error.message : String(error),
toast(error instanceof ApiError ? error.message : String(error), {
kind: 'error',
hint: '该操作仅修改内核运行状态,配置文件未被修改。',
}
})
} finally {
updating.value = null
}
@@ -335,17 +329,6 @@ async function updateNow(name: string) {
</div>
</header>
<div v-if="failure" class="failure">
<div class="failure-text">
<strong>{{ failure.message }}</strong>
<span v-if="failure.hint">{{ failure.hint }}</span>
</div>
<button type="button" class="failure-x" title="关闭提示" @click="failure = null">
<IconClose />
</button>
</div>
<p v-else-if="done" class="done">{{ done }}</p>
<section class="sec">
<header class="sec-head">
<h2>分流规则</h2>
@@ -579,49 +562,6 @@ async function updateNow(name: string) {
font-size: var(--t-sm);
}
.failure {
display: flex;
align-items: flex-start;
gap: var(--s-3);
border: 1px solid color-mix(in srgb, var(--c-danger) 35%, var(--c-border));
border-radius: var(--r-md);
background: var(--c-danger-soft);
padding: var(--s-3) var(--s-4);
margin-bottom: var(--s-4);
font-size: var(--t-sm);
}
.failure-text {
display: flex;
flex-direction: column;
gap: var(--s-1);
flex: 1;
min-width: 0;
}
.failure-x {
flex: none;
display: flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
border: none;
border-radius: var(--r-sm);
background: none;
color: var(--c-danger);
cursor: pointer;
}
.failure-x:hover {
background: color-mix(in srgb, var(--c-danger) 12%, transparent);
}
.done {
color: var(--c-ok);
font-size: var(--t-sm);
margin-bottom: var(--s-4);
}
.sec + .sec {
margin-top: var(--s-7);
}