Skip to content

Commit e925757

Browse files
committed
feat: 优化历史记录加载时的凭据显示与处理逻辑
1 parent 4994da1 commit e925757

1 file changed

Lines changed: 41 additions & 11 deletions

File tree

frontend/src/views/QuickConnect.vue

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ const connecting = ref(false)
328328
const connectionError = ref('')
329329
const savePassword = ref(false)
330330
const historyList = ref([])
331+
const usingSavedCredential = ref(false) // 标记是否使用已保存的凭据
332+
const currentHistoryItem = ref(null) // 当前加载的历史记录项
331333
332334
const searchKeyword = ref('')
333335
const historyTreeRef = ref()
@@ -495,9 +497,19 @@ const saveToHistory = () => {
495497
496498
if (savePassword.value) {
497499
if (form.authType === 'password') {
498-
record.password = form.password
500+
// 如果是占位符,使用历史记录中的实际密码
501+
if (usingSavedCredential.value && form.password === '********' && currentHistoryItem.value) {
502+
record.password = currentHistoryItem.value.password
503+
} else {
504+
record.password = form.password
505+
}
499506
} else {
500-
record.privateKey = form.privateKey
507+
// 如果是占位符,使用历史记录中的实际私钥
508+
if (usingSavedCredential.value && form.privateKey.startsWith('********') && currentHistoryItem.value) {
509+
record.privateKey = currentHistoryItem.value.privateKey
510+
} else {
511+
record.privateKey = form.privateKey
512+
}
501513
}
502514
}
503515
@@ -523,15 +535,22 @@ const fillFromHistory = (item) => {
523535
524536
if (item.hasSavedCredential) {
525537
savePassword.value = true
538+
usingSavedCredential.value = true
539+
currentHistoryItem.value = item
540+
526541
if (item.authType === 'password') {
527-
form.password = item.password || ''
542+
// 密码认证:显示占位符
543+
form.password = '********'
528544
form.privateKey = ''
529545
} else {
530-
form.privateKey = item.privateKey || ''
546+
// 私钥认证:显示占位符
547+
form.privateKey = '******** (已保存的私钥,如需修改请清空后重新输入)'
531548
form.password = ''
532549
}
533550
} else {
534551
savePassword.value = false
552+
usingSavedCredential.value = false
553+
currentHistoryItem.value = null
535554
form.password = ''
536555
form.privateKey = ''
537556
}
@@ -757,27 +776,38 @@ const submitConnection = async (mode) => {
757776
const valid = await connectForm.value.validate()
758777
if (!valid) return
759778
760-
761-
762779
connecting.value = true
763780
connectionError.value = ''
764781
765-
saveToHistory()
766-
782+
// 准备连接信息
767783
const connectionInfo = {
768784
name: form.name || '',
769785
host: form.host,
770786
port: form.port,
771787
username: form.username,
772-
mode: mode // Add mode to connectionInfo
788+
mode: mode
773789
}
774790
791+
// 处理认证信息
775792
if (form.authType === 'password') {
776-
connectionInfo.password = form.password
793+
// 如果使用已保存的凭据且密码是占位符,从历史记录中获取实际密码
794+
if (usingSavedCredential.value && form.password === '********' && currentHistoryItem.value) {
795+
connectionInfo.password = currentHistoryItem.value.password
796+
} else {
797+
connectionInfo.password = form.password
798+
}
777799
} else {
778-
connectionInfo.privateKey = form.privateKey
800+
// 如果使用已保存的凭据且私钥是占位符,从历史记录中获取实际私钥
801+
if (usingSavedCredential.value && form.privateKey.startsWith('********') && currentHistoryItem.value) {
802+
connectionInfo.privateKey = currentHistoryItem.value.privateKey
803+
} else {
804+
connectionInfo.privateKey = form.privateKey
805+
}
779806
}
780807
808+
// 保存到历史记录(使用实际的凭据)
809+
saveToHistory()
810+
781811
emit('connect', connectionInfo)
782812
783813
} catch (error) {

0 commit comments

Comments
 (0)