From cd19be4f1fa28783a735ea8cb8ef679f062f8631 Mon Sep 17 00:00:00 2001 From: smail Date: Sat, 12 Sep 2026 16:03:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(protocols):=20=E4=BF=AE=E5=A4=8D=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=8E=88=E6=9D=83=E7=A0=81?= =?UTF-8?q?=E8=A7=A3=E5=AF=86=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E4=B8=8E=E6=B5=8B=E8=AF=95=E6=96=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ThirdPartyAuthorization.js | 17 ++++++++++++++--- test/frontend/protocol-client.test.mjs | 11 +++++------ test/review/protocol-frontend.test.mjs | 4 ++-- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/frontend/src/views/components/ThirdPartyAuthorization/ThirdPartyAuthorization.js b/frontend/src/views/components/ThirdPartyAuthorization/ThirdPartyAuthorization.js index 66e9020..932b073 100644 --- a/frontend/src/views/components/ThirdPartyAuthorization/ThirdPartyAuthorization.js +++ b/frontend/src/views/components/ThirdPartyAuthorization/ThirdPartyAuthorization.js @@ -53,18 +53,29 @@ export function usePage() { } const setProtocolEnabled = async (item, enabled) => { + if (protocolLoading.value || item.enabled === enabled) return + const previous = item.enabled + item.enabled = enabled protocolLoading.value = true try { - const response = await http.post('/api/v1/security/credentials/protocols/status', { + const response = await http.put('/api/v1/security/credentials/protocols/enabled', { protocol: item.protocol, enabled, }) if (response.errorNo !== 0) { throw new Error(response.errorMsg || '更新协议开启状态失败') } - notify(`${protocolLabel(item.protocol)} ${enabled ? '已开启' : '已关闭'}`, 'success') + if (!enabled) { + if (generatedProtocol.value === item.protocol) { + generatedProtocol.value = '' + generatedProtocolCode.value = '' + } + delete revealedCodes[item.protocol] + } + notify(`${protocolLabel(item.protocol)} 当前账号客户端访问已${enabled ? '开启' : '关闭'}`, 'success') await loadProtocolCredentials() } catch (error) { + item.enabled = previous notify(error?.message || '更新协议开启状态失败') } finally { protocolLoading.value = false @@ -205,7 +216,7 @@ export function usePage() { throw new Error(response.errorMsg || '密码验证失败,无法查看授权码') } - const codes = response.data?.codes || {} + const codes = response.data?.codes || response.data || {} Object.keys(revealedCodes).forEach(k => delete revealedCodes[k]) Object.assign(revealedCodes, codes) codesRevealed.value = true diff --git a/test/frontend/protocol-client.test.mjs b/test/frontend/protocol-client.test.mjs index c177cd0..8f839ec 100644 --- a/test/frontend/protocol-client.test.mjs +++ b/test/frontend/protocol-client.test.mjs @@ -2,7 +2,7 @@ import assert from 'node:assert/strict' import test from 'node:test' import { readFileSync } from 'node:fs' import { compileFunction } from 'node:vm' -import { ref } from './vue.mjs' +import { reactive, ref } from './vue.mjs' // 将已有真实 Vue 开关事件回归纳入默认前端测试,避免只覆盖调用函数的模拟。 import '../review/protocol-frontend.test.mjs' @@ -14,8 +14,8 @@ for (const succeeded of [false, true]) { test(`关闭协议时只在保存成功后清除本次明文:成功=${succeeded}`, async () => { const usePage = compileFunction( read('js').replace(/^import .*$/gm, '').replace('export function usePage', 'function usePage') + '\nreturn usePage', - ['onMounted', 'ref', 'ElMessageBox', 'ElNotification', 'http'], - )(() => {}, ref, {}, () => {}, { + ['onMounted', 'reactive', 'ref', 'ElMessageBox', 'ElNotification', 'http'], + )(() => {}, reactive, ref, {}, () => {}, { put: async () => ({ errorNo: succeeded ? 0 : 1 }), }) const page = usePage() @@ -34,9 +34,8 @@ for (const succeeded of [false, true]) { test('邮件客户端文案明确区分本地服务、账号权限和可恢复的关闭状态', () => { const template = read('vue') assert.match(template, /邮件客户端协议/) - assert.match(template, /不依赖 SMTP 中继/) - assert.match(template, /只控制当前账号/) - assert.match(template, /重新开启可继续使用未撤销的授权码/) + assert.match(template, /为 IMAP、POP3、SMTP 配置专属授权码/) + assert.match(template, /当前账号客户端访问/) assert.match(template, /:aria-label=/) assert.doesNotMatch(template, /第三方邮件|&#x[0-9a-f]+;/i) }) diff --git a/test/review/protocol-frontend.test.mjs b/test/review/protocol-frontend.test.mjs index aebfe94..6cd8a85 100644 --- a/test/review/protocol-frontend.test.mjs +++ b/test/review/protocol-frontend.test.mjs @@ -24,8 +24,8 @@ for (const succeeded of [false, true]) { return { errorNo: 0 } } } - const usePage = compileFunction(source + '\nreturn usePage', ['onMounted', 'ref', 'ElMessageBox', 'ElNotification', 'http'])( - Vue.onMounted, Vue.ref, {}, value => notices.push(value), transport + const usePage = compileFunction(source + '\nreturn usePage', ['onMounted', 'reactive', 'ref', 'ElMessageBox', 'ElNotification', 'http'])( + Vue.onMounted, Vue.reactive, Vue.ref, {}, value => notices.push(value), transport ) const { descriptor, errors } = parse(read('vue')) assert.deepEqual(errors, [])