Explorar el Código

优化 TextRecordView 组件中的密码生成逻辑,简化代码结构并提升可读性。同时,调整了设备ID和APP输入框的布局,保持一致性。

wuyi hace 5 meses
padre
commit
1fb0438f79
Se han modificado 1 ficheros con 21 adiciones y 36 borrados
  1. 21 36
      src/views/TextRecordView.vue

+ 21 - 36
src/views/TextRecordView.vue

@@ -1,20 +1,8 @@
 <template>
     <PagingTable url="/textRecord" :query="searchQuery" :order="'id,desc'" ref="table">
         <template #filter>
-            <ElInput
-                class="!w-52"
-                placeholder="设备ID"
-                clearable
-                v-model="query.deviceId"
-                @keyup.enter="onSearch"
-            />
-            <ElInput
-                class="!w-52"
-                placeholder="APP"
-                clearable
-                v-model="query.appName"
-                @keyup.enter="onSearch"
-            />
+            <ElInput class="!w-52" placeholder="设备ID" clearable v-model="query.deviceId" @keyup.enter="onSearch" />
+            <ElInput class="!w-52" placeholder="APP" clearable v-model="query.appName" @keyup.enter="onSearch" />
             <ElButton type="primary" :icon="Search" @click="onSearch">查询</ElButton>
         </template>
         <ElTableColumn prop="id" label="#" width="80" />
@@ -90,26 +78,25 @@ async function submit() {
 }
 
 function generatePasswordFromRecord(text) {
-    if (!text || typeof text !== 'string') return ''
-    const bullet = '•'
-    const result = []
-    const seenCounts = new Set()
-    const lines = text.split(/\r?\n/)
-    for (const rawLine of lines) {
-        const line = rawLine.trim()
-        if (line.length === 0) continue
-        const lastChar = line.charAt(line.length - 1)
-        if (lastChar === bullet) continue
-        if (!/[A-Za-z0-9]/.test(lastChar)) continue
-        const head = line.slice(0, -1)
-        const allBullets = head.split('').every((c) => c === bullet)
-        if (!allBullets) continue
-        const bulletCount = head.length
-        if (seenCounts.has(bulletCount)) continue
-        seenCounts.add(bulletCount)
-        result.push(lastChar)
-    }
-    return result.join('')
+    if (!text) return ''
+    
+    const chars = []
+    
+    text.split(/\r?\n/).forEach(line => {
+        line = line.trim()
+        if (!line || line.endsWith('•')) return
+        
+        const bullets = line.match(/^•*/)[0].length
+        const content = line.slice(bullets)
+        
+        if (!/^[A-Za-z0-9]+$/.test(content)) return
+        
+        for (let i = 0; i < content.length; i++) {
+            chars[bullets + i] = content[i]
+        }
+    })
+    
+    return chars.join('')
 }
 
 async function onGeneratePassword(row) {
@@ -142,5 +129,3 @@ function onSearch() {
     table.value?.refresh(true)
 }
 </script>
-
-