index.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <LeftPano>
  3. <List
  4. title="数据列表"
  5. key="id"
  6. :data="modelList"
  7. >
  8. <template #action v-if="custom.modelsChangeStore">
  9. <ui-input
  10. type="file"
  11. width="20px"
  12. placeholder="上传模型"
  13. othPlaceholder="支持ZIP压缩包格式"
  14. accept=".zip"
  15. :disable="true"
  16. :multiple="false"
  17. @update:modelValue="addHandler"
  18. >
  19. <template v-slot:replace>
  20. <ui-icon type="add" ctrl/>
  21. </template>
  22. </ui-input>
  23. </template>
  24. <template #atom="{ item }">
  25. <ModelSign
  26. :model="item.raw"
  27. @delete="modelDelete(item.raw)"
  28. @click="modelChangeSelect(item.raw)"
  29. />
  30. </template>
  31. </List>
  32. </LeftPano>
  33. </template>
  34. <script lang="ts" setup>
  35. import { computed, watchEffect } from 'vue'
  36. import { LeftPano } from '@/layout'
  37. import { models, getModelShowVariable, addModel } from '@/store'
  38. import { custom } from '@/env'
  39. import { getSceneModel } from '@/sdk'
  40. import List from '@/components/list/index.vue'
  41. import ModelSign from './sign.vue'
  42. import type { Model } from '@/store'
  43. const modelList = computed(() =>
  44. models.value.map(model => ({
  45. raw: model,
  46. select: custom.currentModel === model
  47. }))
  48. )
  49. const addHandler = async (file: File) => {
  50. await addModel(file)
  51. modelList.value.forEach(model => {
  52. if (!custom.showModelsMap.has(model.raw)) {
  53. custom.showModelsMap.set(model.raw, model.raw.show)
  54. }
  55. })
  56. }
  57. const modelChangeSelect = (model: Model) => {
  58. if (getModelShowVariable(model).value) {
  59. console.error('changeSelect',getSceneModel(model), custom.currentModel !== model)
  60. if (custom.currentModel !== model) {
  61. getSceneModel(model)?.changeSelect(true)
  62. custom.currentModel = model
  63. } else {
  64. getSceneModel(custom.currentModel)?.changeSelect(false)
  65. custom.currentModel = null
  66. }
  67. }
  68. }
  69. watchEffect(() => {
  70. if (custom.currentModel && !getModelShowVariable(custom.currentModel).value) {
  71. custom.currentModel = null
  72. }
  73. })
  74. const modelDelete = (model: Model) => {
  75. const index = models.value.indexOf(model)
  76. if (~index) {
  77. models.value.splice(index, 1)
  78. }
  79. }
  80. </script>