index.vue 2.2 KB

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