index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <div class="go-content-charts-item-box">
  3. <!-- 每一项组件的渲染 -->
  4. <div
  5. class="item-box"
  6. v-for="(item, index) in menuOptions"
  7. :key="index"
  8. draggable
  9. @dragstart="dragStartHandle($event, item)"
  10. @dragend="dragendHandle"
  11. >
  12. <div class="list-header">
  13. <mac-os-control-btn :mini="true" :disabled="true"></mac-os-control-btn>
  14. <n-text class="list-header-text" depth="3">{{ item.title }}</n-text>
  15. </div>
  16. <div class="list-center go-flex-center">
  17. <img class="list-img" v-lazy="item.image" alt="图表图片" />
  18. </div>
  19. </div>
  20. </div>
  21. </template>
  22. <script setup lang="ts">
  23. import { PropType } from 'vue'
  24. import { MacOsControlBtn } from '@/components/MacOsControlBtn/index'
  25. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  26. import { EditCanvasTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
  27. import { componentInstall } from '@/utils'
  28. import { DragKeyEnum } from '@/enums/editPageEnum'
  29. import { ConfigType } from '@/packages/index.d'
  30. import { fetchConfigComponent, fetchChartComponent } from '@/packages/index'
  31. import omit from 'lodash/omit'
  32. const chartEditStore = useChartEditStore()
  33. defineProps({
  34. menuOptions: {
  35. type: Array as PropType<ConfigType[]>,
  36. default: () => []
  37. }
  38. })
  39. // 拖拽处理
  40. const dragStartHandle = (e: DragEvent, item: ConfigType) => {
  41. // 动态注册图表组件
  42. componentInstall(item.chartKey, fetchChartComponent(item))
  43. componentInstall(item.conKey, fetchConfigComponent(item))
  44. // 将配置项绑定到拖拽属性上
  45. e!.dataTransfer!.setData(DragKeyEnum.DROG_KEY, JSON.stringify(omit(item, ['image'])))
  46. // 修改状态
  47. chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_CREATE, true)
  48. }
  49. // 拖拽结束
  50. const dragendHandle = () => {
  51. chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_CREATE, false)
  52. }
  53. </script>
  54. <style lang="scss" scoped>
  55. /* 列表项宽度 */
  56. $itemWidth: 86%;
  57. /* 内容高度 */
  58. $centerHeight: 100px;
  59. @include go('content-charts-item-box') {
  60. .item-box {
  61. margin: 0 7%;
  62. margin-bottom: 15px;
  63. width: $itemWidth;
  64. overflow: hidden;
  65. border-radius: 6px;
  66. cursor: pointer;
  67. border: 1px solid rgba(0, 0, 0, 0);
  68. @include filter-bg-color('background-color2');
  69. @extend .go-transition;
  70. &:hover {
  71. @include hover-border-color('background-color4');
  72. .list-img {
  73. transform: scale(1.1);
  74. }
  75. }
  76. .list-header {
  77. display: flex;
  78. align-items: center;
  79. justify-content: space-between;
  80. padding: 2px 15px;
  81. @include filter-bg-color('background-color3');
  82. &-text {
  83. font-size: 12px;
  84. margin-left: 8px;
  85. }
  86. }
  87. .list-center {
  88. padding: 6px 0;
  89. height: $centerHeight;
  90. overflow: hidden;
  91. .list-img {
  92. height: 100%;
  93. border-radius: 6px;
  94. @extend .go-transition;
  95. }
  96. }
  97. }
  98. }
  99. </style>