index.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <RightFillPano>
  3. <div class="btns header-btns">
  4. <ui-button class="start" @click="getView">
  5. <ui-icon type="add" />
  6. 视图提取
  7. </ui-button>
  8. </div>
  9. <ui-group title="全部视图" class="tree" >
  10. <Draggable :list="views" draggable=".sign" itemKey="id">
  11. <template #item="{ element: view }">
  12. <Sign
  13. :view="view"
  14. :key="view.id"
  15. @delete="() => deleteView(view)"
  16. @updateTitle="title => view.title = title"
  17. @updateCover="cover => view.cover = cover"
  18. />
  19. </template>
  20. </Draggable>
  21. </ui-group>
  22. </RightFillPano>
  23. </template>
  24. <script lang="ts" setup>
  25. import { views, createView, autoSaveViews, initialViews } from '@/store'
  26. import { RightFillPano } from '@/layout'
  27. import { useViewStack } from '@/hook'
  28. import Draggable from 'vuedraggable'
  29. import Sign from './sign.vue'
  30. import { loadModel, currentModel, fuseModel } from '@/model'
  31. import { loadPack, togetherCallback } from '@/utils'
  32. import { Message } from 'bill/index'
  33. import { showLeftPanoStack } from '@/env'
  34. import { ref, watch } from 'vue'
  35. import type { View } from '@/store'
  36. initialViews()
  37. const getView = async () => {
  38. try {
  39. const { image, flyData } = await loadPack(async () => {
  40. const modelSDK = await loadModel(currentModel.value)
  41. return await modelSDK.getView()
  42. })
  43. const type = currentModel.value !== fuseModel
  44. ? { numType: currentModel.value.type, num: currentModel.value.num }
  45. : {}
  46. views.value.push(createView({
  47. flyData,
  48. cover: {
  49. blob: image,
  50. url: URL.createObjectURL(image)
  51. },
  52. ...type
  53. }))
  54. } catch (e: any) {
  55. console.error(e)
  56. Message.error(e.message)
  57. }
  58. }
  59. const deleteView = (record: View) => {
  60. const index = views.value.indexOf(record)
  61. if (~index) {
  62. views.value.splice(index, 1)
  63. }
  64. }
  65. const showLeftPano = ref(false)
  66. watch(currentModel, () => {
  67. if (currentModel.value) {
  68. showLeftPano.value = false
  69. }
  70. })
  71. useViewStack(autoSaveViews)
  72. useViewStack(() => togetherCallback([
  73. showLeftPanoStack.push(showLeftPano)
  74. ]))
  75. </script>
  76. <style lang="scss" src="./style.scss" scoped>
  77. </style>