index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. if (custom.currentModel !== model) {
  60. getSceneModel(model)?.changeSelect(true)
  61. custom.currentModel = model
  62. } else {
  63. getSceneModel(custom.currentModel)?.changeSelect(false)
  64. custom.currentModel = null
  65. }
  66. }
  67. }
  68. watchEffect(() => {
  69. if (custom.currentModel && !getModelShowVariable(custom.currentModel).value) {
  70. custom.currentModel = null
  71. }
  72. })
  73. const modelDelete = (model: Model) => {
  74. const index = models.value.indexOf(model)
  75. if (~index) {
  76. models.value.splice(index, 1)
  77. }
  78. }
  79. </script>