mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-11 23:45:11 +08:00
refactor: 统一使用 generateId 函数生成唯一标识符
- 在 GMView、FleetView 中替换 Date.now() 生成 ID 的方式 - 在 DiplomacyView 中优化排序函数,避免重复过滤与排序
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
|
||||
// 保存当前配置为预设
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user