From d8dd4e7317af1b1ab844b0bc5dd1c813c6ec13da Mon Sep 17 00:00:00 2001 From: wenyu Date: Wed, 18 Mar 2026 21:04:11 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=BB=9F=E4=B8=80=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=20generateId=20=E5=87=BD=E6=95=B0=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=94=AF=E4=B8=80=E6=A0=87=E8=AF=86=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 GMView、FleetView 中替换 Date.now() 生成 ID 的方式 - 在 DiplomacyView 中优化排序函数,避免重复过滤与排序 --- src/views/DiplomacyView.vue | 10 +++++----- src/views/FleetView.vue | 3 ++- src/views/GMView.vue | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/views/DiplomacyView.vue b/src/views/DiplomacyView.vue index 2e8c057..fb4dc33 100644 --- a/src/views/DiplomacyView.vue +++ b/src/views/DiplomacyView.vue @@ -427,7 +427,7 @@ import NpcRelationCard from '@/components/npc/NpcRelationCard.vue' import NpcRelationRow from '@/components/npc/NpcRelationRow.vue' import { RelationStatus } from '@/types/game' - import type { DiplomaticRelation } from '@/types/game' + import type { DiplomaticRelation, NPC } from '@/types/game' import * as npcBehaviorLogic from '@/logic/npcBehaviorLogic' import { Search, @@ -481,8 +481,8 @@ } // 排序函数 - const sortNpcs = (npcs: typeof npcStore.npcs) => { - return [...npcs].sort((a, b) => { + const sortNpcs = (npcs: NPC[], predicate: (npc: NPC) => boolean = () => true) => { + return npcs.filter(predicate).sort((a, b) => { let valA = 0 let valB = 0 @@ -707,7 +707,7 @@ } // 搜索过滤函数 - const matchesSearch = (npc: (typeof npcStore.npcs)[0]) => { + const matchesSearch = (npc: NPC) => { if (!searchQuery.value.trim()) return true const query = searchQuery.value.toLowerCase().trim() return npc.name.toLowerCase().includes(query) || npc.id.toLowerCase().includes(query) @@ -715,7 +715,7 @@ // 按关系状态分类NPC(同时应用搜索过滤) // 先统一排序一次,避免不同标签页在同一批数据上重复排序 - const sortedNpcs = computed(() => sortNpcs(npcStore.npcs.filter(matchesSearch))) + const sortedNpcs = computed(() => sortNpcs(npcStore.npcs, matchesSearch)) const allNpcs = computed(() => sortedNpcs.value) diff --git a/src/views/FleetView.vue b/src/views/FleetView.vue index b9c5dd5..ad20566 100644 --- a/src/views/FleetView.vue +++ b/src/views/FleetView.vue @@ -642,6 +642,7 @@ import * as diplomaticLogic from '@/logic/diplomaticLogic' import * as gameLogic from '@/logic/gameLogic' import * as moonLogic from '@/logic/moonLogic' + import { generateId } from '@/utils/id' const route = useRoute() const gameStore = useGameStore() @@ -934,7 +935,7 @@ // 生成唯一ID const generatePresetId = (): string => { - return `preset_${Date.now()}_${Math.random().toString(36).substr(2, 9)}` + return generateId('fleet_preset') } // 保存当前配置为预设 diff --git a/src/views/GMView.vue b/src/views/GMView.vue index 9e1a260..e738b3d 100644 --- a/src/views/GMView.vue +++ b/src/views/GMView.vue @@ -319,6 +319,7 @@ import * as publicLogic from '@/logic/publicLogic' import { calculateMaxFleetStorage } from '@/logic/fleetStorageLogic' import { calculateMissileSiloCapacity } from '@/logic/missileLogic' + import { generateId } from '@/utils/id' import { Home, Trash2 } from 'lucide-vue-next' // --- 预设系统 --- @@ -461,7 +462,7 @@ } const newPreset: GMPreset = { - id: Date.now().toString(), + id: generateId('gm_preset'), name, values }