From 7b0e1610d5a3e8cf26164211eb148dd330b7c021 Mon Sep 17 00:00:00 2001 From: SunWuyuan Date: Wed, 8 Oct 2025 12:10:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=89=8B=E5=8A=A8=E8=BE=93=E5=85=A5UUID?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E8=AE=BE=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/DeviceRegisterDialog.vue | 203 +++++++++++++++++------- src/lib/deviceStore.js | 62 ++++++++ src/pages/index.vue | 13 ++ src/pages/password-manager.vue | 13 +- 4 files changed, 224 insertions(+), 67 deletions(-) diff --git a/src/components/DeviceRegisterDialog.vue b/src/components/DeviceRegisterDialog.vue index be9e136..0305fa5 100644 --- a/src/components/DeviceRegisterDialog.vue +++ b/src/components/DeviceRegisterDialog.vue @@ -33,8 +33,10 @@ const newUuid = ref('') const deviceName = ref('') const bindToAccount = ref(false) const accountDevices = ref([]) +const historyDevices = ref([]) +const manualUuid = ref('') const loadingDevices = ref(false) -const activeTab = ref('load') // 'load' 或 'register' +const activeTab = ref('load') // 'load' | 'history' | 'register' const showLoginDialog = ref(false) // 登录对话框状态 const isOpen = computed({ @@ -47,6 +49,9 @@ watch(isOpen, (newVal) => { if (newVal && accountStore.isAuthenticated && activeTab.value === 'load') { loadAccountDevices() } + if (newVal && activeTab.value === 'history') { + loadHistoryDevices() + } // 切换到注册选项卡时,自动生成UUID if (newVal && activeTab.value === 'register' && !newUuid.value) { generateRandomUuid() @@ -58,6 +63,9 @@ watch(activeTab, (newVal) => { if (newVal === 'load' && accountStore.isAuthenticated && isOpen.value) { loadAccountDevices() } + if (newVal === 'history' && isOpen.value) { + loadHistoryDevices() + } if (newVal === 'register' && !newUuid.value) { generateRandomUuid() } @@ -121,12 +129,35 @@ const loadAccountDevices = async () => { // 加载选中的设备 const loadDevice = (device) => { deviceStore.setDeviceUuid(device.uuid) + // 写入历史 + deviceStore.addDeviceToHistory({ uuid: device.uuid, name: device.name }) isOpen.value = false emit('confirm') resetForm() toast.success(`已切换到设备: ${device.name || device.uuid}`) } +// 手动输入UUID加载 +const loadByUuid = () => { + const id = manualUuid.value?.trim() + if (!id) { + toast.error('请输入设备 UUID') + return + } + // 可选:基本格式校验(宽松处理,避免误判合法UUID) + const ok = /^[0-9a-fA-F-]{8,}$/.test(id) + if (!ok) { + toast.error('UUID 格式不正确') + return + } + deviceStore.setDeviceUuid(id) + deviceStore.addDeviceToHistory({ uuid: id }) + isOpen.value = false + emit('confirm') + resetForm() + toast.success(`已切换到设备: ${id}`) +} + // 注册新设备 const registerDevice = async () => { if (!newUuid.value.trim()) { @@ -142,6 +173,8 @@ const registerDevice = async () => { try { // 1. 保存UUID到本地 deviceStore.setDeviceUuid(newUuid.value.trim()) + // 写入历史 + deviceStore.addDeviceToHistory({ uuid: newUuid.value.trim(), name: deviceName.value.trim() }) // 2. 调用设备注册接口(会自动在云端创建设备) await apiClient.registerDevice( @@ -181,6 +214,7 @@ const resetForm = () => { bindToAccount.value = accountStore.isAuthenticated accountDevices.value = [] activeTab.value = 'load' + manualUuid.value = '' } // 处理弹框关闭 @@ -211,6 +245,11 @@ onMounted(() => { onUnmounted(() => { document.removeEventListener('keydown', handleKeydown, true) }) + +// 加载本地历史设备 +const loadHistoryDevices = () => { + historyDevices.value = deviceStore.getDeviceHistory() +}