fix(cr2-frontend): 代理归属回退、换号继承确认与请求竞态收口
- CR-04:全局代理加 proxy_uid 归属,跨账号不再静默回退/补报 - CR-12:取消静默继承,设置页显式确认;同 OS 作用域、locked 代理排除、无效快照清除、uid+epoch 双校验、登出 capture 超时 - CR-26/27:关键词分页初始值与档位一致;两页面请求序号闸丢弃旧响应 vue-tsc 两前端 rc=0;定向 35 + 8 + 2 例全绿。
This commit is contained in:
@@ -102,8 +102,8 @@
|
||||
<span>自动登录</span>
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit" class="btn-login" id="btnLogin" :disabled="loggingIn">
|
||||
{{ loggingIn ? '登录中...' : '登录' }}
|
||||
<button type="submit" class="btn-login" id="btnLogin" :disabled="loggingIn || logoutCleanupPending">
|
||||
{{ loggingIn ? '登录中...' : logoutCleanupPending ? '正在退出...' : '登录' }}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
@@ -136,6 +136,11 @@ const username = ref('')
|
||||
const password = ref('')
|
||||
const passwordVisible = ref(false)
|
||||
const loggingIn = ref(false)
|
||||
/**
|
||||
* 登出清理进行中(CR-12):继承快照 capture 有超时,但等它返回前不能允许再提交登录,
|
||||
* 否则新账号 B 的 token/uid 会被上一轮 clearSignedOutState 删掉。
|
||||
*/
|
||||
const logoutCleanupPending = ref(false)
|
||||
const errorMessage = ref('')
|
||||
const kickedNotice = ref(false)
|
||||
const expiredNotice = ref(false)
|
||||
@@ -407,7 +412,8 @@ function toggleUpdate() {
|
||||
}
|
||||
|
||||
async function submitLogin() {
|
||||
if (loggingIn.value) return
|
||||
// 登出清理未完成时禁止提交:清理函数会删 token/uid,晚到的登录会被它清掉(CR-12)
|
||||
if (loggingIn.value || logoutCleanupPending.value) return
|
||||
const account = username.value.trim()
|
||||
if (!account || !password.value) {
|
||||
errorMessage.value = '请输入账号和密码'
|
||||
@@ -480,7 +486,9 @@ async function submitLogin() {
|
||||
onMounted(() => {
|
||||
const params = new URLSearchParams(window.location.search || '')
|
||||
if (params.get('logout') === '1' || params.get('switch') === '1') {
|
||||
logoutCleanupPending.value = true
|
||||
const clearSignedOutState = () => {
|
||||
logoutCleanupPending.value = false
|
||||
// 清缓存必须在移除 uid 之前:镜像键带 uid,反序会按 uid=0 删错位置,
|
||||
// 把本账号的明文镜像留在磁盘上给下一个账号(或网页脚本)读到。
|
||||
clearApiSecretCache()
|
||||
|
||||
@@ -33,14 +33,18 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import ApiSecretSettingsPanel from '@/shared/components/ApiSecretSettingsPanel.vue'
|
||||
import NotificationBell from '@/shared/components/NotificationBell.vue'
|
||||
import {
|
||||
confirmApiSecretInheritance,
|
||||
declineApiSecretInheritance,
|
||||
getPendingApiSecretInheritance,
|
||||
getStoredApiSecretSnapshot,
|
||||
listApiSecretModules,
|
||||
loadApiSecrets,
|
||||
takeApiSecretInheritanceNotice,
|
||||
type ApiSecretInheritanceNotice,
|
||||
type ApiSecretModuleKey,
|
||||
} from '@/shared/utils/api-secret-store'
|
||||
|
||||
@@ -51,22 +55,71 @@ const submitting = ref(false)
|
||||
const username = ref('')
|
||||
const hint = ref('填写密钥后请先点「检测」确认可用再保存(检测通过的输入值保存时会沿用同一结果),全部检测通过后即可进入工具台。')
|
||||
|
||||
function inheritanceLabels(moduleKeys: string[], proxy: boolean): string[] {
|
||||
const labels = listApiSecretModules()
|
||||
.filter((module) => moduleKeys.includes(module.moduleKey))
|
||||
.map((module) => module.moduleLabel)
|
||||
if (proxy) labels.push('代理设置')
|
||||
return labels
|
||||
}
|
||||
|
||||
function showInheritanceNotice(inherited: ApiSecretInheritanceNotice | null): void {
|
||||
if (!inherited) return
|
||||
const labels = inheritanceLabels(inherited.moduleKeys, inherited.proxy)
|
||||
// 共享电脑上不把上一个账号的用户名展示给新账号(CR-12)
|
||||
hint.value = labels.length
|
||||
? `已继承本机上一个账号的${labels.join('、')},请点击上方对应模块的「检测」确认后保存进入。`
|
||||
: '已继承本机上一个账号的密钥配置,请点击上方「检测」逐项确认后保存进入。'
|
||||
}
|
||||
|
||||
/**
|
||||
* 继承确认(CR-12):同机换号不再静默继承上一个账号的密钥/代理。
|
||||
* 只在本机确实有快照、且当前账号服务端还有空缺时弹一次确认;取消即清快照。
|
||||
*/
|
||||
async function promptPendingInheritance(): Promise<void> {
|
||||
const pending = getPendingApiSecretInheritance()
|
||||
if (!pending) {
|
||||
showInheritanceNotice(takeApiSecretInheritanceNotice())
|
||||
return
|
||||
}
|
||||
const labels = inheritanceLabels(pending.moduleKeys, pending.proxy)
|
||||
const detail = labels.length ? `留下的${labels.join('、')}` : '留下的密钥配置'
|
||||
const confirmed = () => {
|
||||
void confirmApiSecretInheritance().then((notice) => {
|
||||
if (!notice) {
|
||||
hint.value = '未继承:服务端已有的项不会被覆盖,请手动填写并检测本账号密钥。'
|
||||
return
|
||||
}
|
||||
showInheritanceNotice(notice)
|
||||
})
|
||||
}
|
||||
const declined = () => {
|
||||
void declineApiSecretInheritance().then(() => {
|
||||
hint.value = '已跳过本机配置继承,请填写当前账号自己的密钥并检测后保存进入。'
|
||||
})
|
||||
}
|
||||
// 两参 then:取消/关闭只走拒绝分支,不会把「确认过程中的网络失败」误当成用户拒绝而清快照
|
||||
void ElMessageBox.confirm(
|
||||
`检测到本机上一个账号${detail}。是否导入到当前账号?`
|
||||
+ '仅在同一台电脑、同一 Windows 用户下、且确认这是你自己的配置时才选择「继承」;'
|
||||
+ '服务端已有的密钥/代理不会被覆盖,后台锁定的代理也不会继承。',
|
||||
'本机配置继承确认',
|
||||
{
|
||||
type: 'warning',
|
||||
confirmButtonText: '继承',
|
||||
cancelButtonText: '不继承',
|
||||
distinguishCancelAndClose: true,
|
||||
},
|
||||
).then(confirmed, declined)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
try {
|
||||
username.value = window.localStorage.getItem('username') || ''
|
||||
} catch {
|
||||
/* 忽略存储异常 */
|
||||
}
|
||||
const inherited = takeApiSecretInheritanceNotice()
|
||||
if (inherited) {
|
||||
const labels = listApiSecretModules()
|
||||
.filter((module) => inherited.moduleKeys.includes(module.moduleKey))
|
||||
.map((module) => module.moduleLabel)
|
||||
if (inherited.proxy) labels.push('代理设置')
|
||||
hint.value = labels.length
|
||||
? `已继承本机账号「${inherited.fromUsername || inherited.fromUid}」的${labels.join('、')},请点击上方对应模块的「检测」确认后保存进入。`
|
||||
: `已继承本机账号「${inherited.fromUsername || inherited.fromUid}」的密钥配置,请点击上方「检测」逐项确认后保存进入。`
|
||||
}
|
||||
void promptPendingInheritance()
|
||||
})
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user