去掉转换入口,加测延迟,改掉刷新时丢状态的毛病

最要紧的是第三条:之前每次改完都会先切到「读取中」,页面被拆掉重建,
选中的那一路入站随之丢失,改个设置还得重新找回原来的位置。现在只有首次加载显示占位,
之后都是原地更新。切换策略组还做成了乐观更新——那一步不写配置文件,
没必要让点击等一个往返,真失败了随后的刷新会纠正回来。

测延迟按钮让内核并发测整个策略组。测不通是关于线路的结论而不是 Patchbay 出了问题,
所以全部超时用中性提示,不弹红框。
This commit is contained in:
im0o
2026-08-10 12:53:56 +08:00
parent 0062a261f7
commit 5cdc183190
5 changed files with 114 additions and 77 deletions
+25 -4
View File
@@ -15,11 +15,19 @@ const providerLines = ref<string[]>([])
const runtime = ref<Record<string, ProxyInfo>>({})
const needsToken = ref(!getToken())
const loadError = ref('')
const loading = ref(false)
const booted = ref(false)
const refreshing = ref(false)
const active = ref('router')
/**
* 重新读一遍状态。
*
* 关键在于**不能把页面拆掉重建**:之前每次刷新都会先切到「读取中」,
* 于是路由页被卸载、选中的那一路入站丢失,改完一个设置还要重新找回原来的位置。
* 所以只有首次加载显示占位,之后都是原地更新。
*/
async function load() {
loading.value = true
refreshing.value = true
loadError.value = ''
try {
const [config, status] = await Promise.all([api.readConfig(), api.kernel()])
@@ -37,7 +45,8 @@ async function load() {
loadError.value = error instanceof Error ? error.message : String(error)
}
} finally {
loading.value = false
refreshing.value = false
booted.value = true
}
}
@@ -62,6 +71,17 @@ async function readRuntime(): Promise<Record<string, ProxyInfo>> {
}
}
/**
* 切换策略组时先在本地改掉,不等内核回话。
*
* 这一步不写配置文件,失败率极低;而等一个往返再更新会让点击感觉发木。
* 真失败了随后的刷新会把状态纠正回来。
*/
function optimisticSelect(group: string, member: string) {
const info = runtime.value[group]
if (info) info.now = member
}
function submitToken(value: string) {
setToken(value)
void load()
@@ -119,7 +139,7 @@ const current = computed(() => NAV.find((n) => n.key === active.value))
</nav>
<main class="main">
<p v-if="loading" class="note">读取中</p>
<p v-if="!booted && refreshing" class="note">读取中</p>
<div v-else-if="loadError" class="alert">
<h2>读不到配置</h2>
@@ -144,6 +164,7 @@ const current = computed(() => NAV.find((n) => n.key === active.value))
:provider-lines="providerLines"
:runtime="runtime"
@changed="load"
@optimistic-select="optimisticSelect"
/>
<div v-else class="note">