|
@@ -1,14 +1,17 @@
|
|
|
import { defineStore } from 'pinia'
|
|
import { defineStore } from 'pinia'
|
|
|
import { computed, ref } from 'vue'
|
|
import { computed, ref } from 'vue'
|
|
|
|
|
|
|
|
|
|
+import { renamePart as apiRenamePart } from '../api/models'
|
|
|
import { getViewer } from '../three/instance'
|
|
import { getViewer } from '../three/instance'
|
|
|
import type { PartMeta, PartStatus } from '../types'
|
|
import type { PartMeta, PartStatus } from '../types'
|
|
|
|
|
+import { useModelStore } from './model'
|
|
|
|
|
|
|
|
export const usePartsStore = defineStore('parts', () => {
|
|
export const usePartsStore = defineStore('parts', () => {
|
|
|
const parts = ref<PartMeta[]>([])
|
|
const parts = ref<PartMeta[]>([])
|
|
|
const selected = ref<Set<string>>(new Set())
|
|
const selected = ref<Set<string>>(new Set())
|
|
|
const queryOpen = ref(false)
|
|
const queryOpen = ref(false)
|
|
|
const search = ref('')
|
|
const search = ref('')
|
|
|
|
|
+ const pendingSelectLabel = ref<string | null>(null)
|
|
|
|
|
|
|
|
const selectedParts = computed(() => parts.value.filter((p) => selected.value.has(p.id)))
|
|
const selectedParts = computed(() => parts.value.filter((p) => selected.value.has(p.id)))
|
|
|
const selectedCount = computed(() => selected.value.size)
|
|
const selectedCount = computed(() => selected.value.size)
|
|
@@ -75,10 +78,18 @@ export const usePartsStore = defineStore('parts', () => {
|
|
|
parts.value.forEach((p) => resetColor(p.id))
|
|
parts.value.forEach((p) => resetColor(p.id))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** 重命名部件(写回 .glb 并同步映射表),随后重载模型并按新名重新选中。 */
|
|
|
|
|
+ async function renamePart(label: string, newName: string): Promise<void> {
|
|
|
|
|
+ const modelStore = useModelStore()
|
|
|
|
|
+ const result = await apiRenamePart(modelStore.current, label, newName)
|
|
|
|
|
+ pendingSelectLabel.value = result.new_label
|
|
|
|
|
+ modelStore.requestReload()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return {
|
|
return {
|
|
|
- parts, selected, queryOpen, search,
|
|
|
|
|
|
|
+ parts, selected, queryOpen, search, pendingSelectLabel,
|
|
|
selectedParts, selectedCount,
|
|
selectedParts, selectedCount,
|
|
|
byId, setParts, selectOnly, toggle, clearSelection,
|
|
byId, setParts, selectOnly, toggle, clearSelection,
|
|
|
- setColor, resetColor, applyPreset, resetSelected, resetAll,
|
|
|
|
|
|
|
+ setColor, resetColor, applyPreset, resetSelected, resetAll, renamePart,
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|