index.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <LeftPano>
  3. <List
  4. title="数据列表"
  5. key="id"
  6. :data="modelList"
  7. >
  8. <template #action>
  9. <ui-input
  10. type="file"
  11. width="20px"
  12. placeholder="上传模型"
  13. othPlaceholder="支持RAR,ZIP压缩包格式"
  14. accept=".rar, .zip"
  15. :disable="true"
  16. :multiple="false"
  17. @update:modelValue="addModel"
  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 modelChangeSelect = (model: Model) => {
  50. if (getModelShowVariable(model).value) {
  51. if (custom.currentModel !== model) {
  52. getSceneModel(model)?.changeSelect(true)
  53. custom.currentModel = model
  54. } else {
  55. getSceneModel(custom.currentModel)?.changeSelect(false)
  56. custom.currentModel = null
  57. }
  58. }
  59. }
  60. watchEffect(() => {
  61. if (custom.currentModel && !getModelShowVariable(custom.currentModel).value) {
  62. custom.currentModel = null
  63. }
  64. })
  65. const modelDelete = (model: Model) => {
  66. const index = models.value.indexOf(model)
  67. if (~index) {
  68. models.value.splice(index, 1)
  69. }
  70. }
  71. </script>