insert.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <a-modal
  3. v-model:visible="visible"
  4. :title="`${currentType === Type.bim ? '创建' : '选择'}场景`"
  5. :width="`${currentType === Type.bim ? 480 : 660}px`"
  6. :after-close="onCancel"
  7. @ok="saveHandler"
  8. >
  9. <template #footer>
  10. <div class="footer">
  11. <p>
  12. <template v-if="currentType === Type.scene">
  13. 已选择
  14. {{ Object.values(typeNums).reduce((t, c) => t + c.length, 0) }}
  15. 个场景
  16. </template>
  17. </p>
  18. <div>
  19. <a-button
  20. class="action-bottom"
  21. size="middle"
  22. @click="visible = false"
  23. >
  24. 取消
  25. </a-button>
  26. <a-button
  27. class="action-bottom"
  28. type="primary"
  29. size="middle"
  30. @click="saveHandler"
  31. >
  32. 保存
  33. </a-button>
  34. </div>
  35. </div>
  36. </template>
  37. <a-form name="basic" label-align="left" autocomplete="off">
  38. <a-form-item label="场景类型" required>
  39. <a-radio-group v-model:value="currentType" name="radioGroup">
  40. <a-radio :value="Type.bim">{{ Type.bim }}</a-radio>
  41. <a-radio :value="Type.scene">{{ Type.scene }}</a-radio>
  42. </a-radio-group>
  43. </a-form-item>
  44. <UploadBim v-if="currentType === Type.bim" v-model:data="bim" />
  45. </a-form>
  46. <SelectScenes
  47. v-if="currentType === Type.scene"
  48. v-model:type-nums="typeNums"
  49. />
  50. </a-modal>
  51. </template>
  52. <script lang="ts" setup>
  53. import { ref, defineProps, toRaw } from 'vue'
  54. import { message } from 'ant-design-vue'
  55. import { SceneType } from '@/store'
  56. import SelectScenes from './select-scenes.vue'
  57. import UploadBim from './upload-bim.vue'
  58. import type { UploadData } from './upload-bim.vue'
  59. import type { Project, BimUploadData, SelectTypeScenes } from '@/store'
  60. export type SaveData =
  61. | {
  62. type: 'bim'
  63. payload: BimUploadData
  64. }
  65. | {
  66. type: 'scene'
  67. payload: SelectTypeScenes
  68. }
  69. defineOptions<{ name: 'insert-project-scene' }>()
  70. const props = defineProps<{
  71. project: Project
  72. onSave: (data: SaveData) => void
  73. onCancel: () => void
  74. }>()
  75. enum Type {
  76. scene = '场景',
  77. bim = 'bim'
  78. }
  79. const currentType = ref(Type.bim)
  80. const bim = ref<UploadData>({ name: '', file: undefined })
  81. const typeNums = ref(
  82. props.project.sceneList.reduce(
  83. (t, scene) => {
  84. t[scene.type].push(scene.num)
  85. return t
  86. },
  87. {
  88. [SceneType.SWKJ]: [],
  89. [SceneType.SWKK]: [],
  90. [SceneType.SWSS]: []
  91. } as SelectTypeScenes
  92. )
  93. )
  94. const visible = ref(true)
  95. const saveHandler = async () => {
  96. let data: SaveData
  97. if (currentType.value === Type.bim) {
  98. if (!bim.value.name) {
  99. return message.error('请输入场景名称')
  100. } else if (!bim.value.file) {
  101. return message.error('请上传BIM文件')
  102. }
  103. data = { payload: toRaw(bim.value) as BimUploadData, type: 'bim' }
  104. } else {
  105. data = { payload: toRaw(typeNums.value), type: 'scene' }
  106. }
  107. await props.onSave(data)
  108. visible.value = false
  109. }
  110. </script>
  111. <style lang="scss" scoped>
  112. .footer {
  113. display: flex;
  114. justify-content: space-between;
  115. align-items: center;
  116. p {
  117. margin-bottom: 0;
  118. color: #646566;
  119. font-size: 14px;
  120. }
  121. }
  122. </style>