index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <div class="go-content-charts-item-box" :class="{ double: chartMode === ChartModeEnum.DOUBLE }">
  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. @dblclick="dblclickHandle(item)"
  12. >
  13. <div class="list-header">
  14. <mac-os-control-btn class="list-header-control-btn" :mini="true" :disabled="true"></mac-os-control-btn>
  15. <n-text class="list-header-text" depth="3">
  16. <n-ellipsis>{{ item.title }}</n-ellipsis>
  17. </n-text>
  18. </div>
  19. <div class="list-center go-flex-center">
  20. <img class="list-img" v-lazy="item.image" alt="图表图片" />
  21. </div>
  22. <div class="list-bottom">
  23. <n-text class="list-bottom-text" depth="3">
  24. <n-ellipsis style="max-width: 90%">{{ item.title }}</n-ellipsis>
  25. </n-text>
  26. </div>
  27. </div>
  28. </div>
  29. </template>
  30. <script setup lang="ts">
  31. import { PropType, ref, Ref, computed } from 'vue'
  32. import { MacOsControlBtn } from '@/components/Tips/MacOsControlBtn/index'
  33. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  34. import { EditCanvasTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
  35. import { ChartModeEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d'
  36. import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore'
  37. import { componentInstall, loadingStart, loadingFinish, loadingError } from '@/utils'
  38. import { DragKeyEnum } from '@/enums/editPageEnum'
  39. import { createComponent } from '@/packages'
  40. import { ConfigType, CreateComponentType } from '@/packages/index.d'
  41. import { fetchConfigComponent, fetchChartComponent } from '@/packages/index'
  42. import omit from 'lodash/omit'
  43. const chartEditStore = useChartEditStore()
  44. defineProps({
  45. menuOptions: {
  46. type: Array as PropType<ConfigType[]>,
  47. default: () => []
  48. }
  49. })
  50. const chartLayoutStore = useChartLayoutStore()
  51. // 组件展示状态
  52. const chartMode: Ref<ChartModeEnum> = computed(() => {
  53. return chartLayoutStore.getChartType
  54. })
  55. // 拖拽处理
  56. const dragStartHandle = (e: DragEvent, item: ConfigType) => {
  57. // 动态注册图表组件
  58. componentInstall(item.chartKey, fetchChartComponent(item))
  59. componentInstall(item.conKey, fetchConfigComponent(item))
  60. // 将配置项绑定到拖拽属性上
  61. e!.dataTransfer!.setData(DragKeyEnum.DRAG_KEY, JSON.stringify(omit(item, ['image'])))
  62. // 修改状态
  63. chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_CREATE, true)
  64. }
  65. // 拖拽结束
  66. const dragendHandle = () => {
  67. chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_CREATE, false)
  68. }
  69. // 双击添加
  70. const dblclickHandle = async (item: ConfigType) => {
  71. try {
  72. loadingStart()
  73. // 动态注册图表组件
  74. componentInstall(item.chartKey, fetchChartComponent(item))
  75. componentInstall(item.conKey, fetchConfigComponent(item))
  76. // 创建新图表组件
  77. let newComponent: CreateComponentType = await createComponent(item)
  78. // 添加
  79. chartEditStore.addComponentList(newComponent, false, true)
  80. // 选中
  81. chartEditStore.setTargetSelectChart(newComponent.id)
  82. loadingFinish()
  83. } catch (error) {
  84. loadingError()
  85. window['$message'].warning(`图表正在研发中, 敬请期待...`)
  86. }
  87. }
  88. </script>
  89. <style lang="scss" scoped>
  90. /* 列表项宽度 */
  91. $itemWidth: 100%;
  92. $halfItemWidth: 46%;
  93. /* 内容高度 */
  94. $centerHeight: 100px;
  95. $halfCenterHeight: 50px;
  96. @include go('content-charts-item-box') {
  97. display: flex;
  98. flex-wrap: wrap;
  99. justify-content: space-between;
  100. gap: 9px;
  101. padding: 10px;
  102. .item-box {
  103. margin: 0;
  104. width: $itemWidth;
  105. overflow: hidden;
  106. border-radius: 6px;
  107. cursor: pointer;
  108. border: 1px solid rgba(0, 0, 0, 0);
  109. @include fetch-bg-color('background-color2');
  110. @extend .go-transition;
  111. &:hover {
  112. @include hover-border-color('background-color4');
  113. .list-img {
  114. transform: scale(1.1);
  115. }
  116. }
  117. .list-header {
  118. display: flex;
  119. align-items: center;
  120. justify-content: space-between;
  121. padding: 2px 15px;
  122. @include fetch-bg-color('background-color3');
  123. &-text {
  124. font-size: 12px;
  125. margin-left: 8px;
  126. }
  127. }
  128. .list-center {
  129. padding: 6px 0;
  130. height: $centerHeight;
  131. overflow: hidden;
  132. .list-img {
  133. height: 100px;
  134. width: 140px;
  135. border-radius: 6px;
  136. @extend .go-transition;
  137. }
  138. }
  139. .list-bottom {
  140. display: none;
  141. .list-bottom-text {
  142. font-size: 12px;
  143. padding-left: 5px;
  144. }
  145. }
  146. }
  147. /* 缩小展示 */
  148. &.double {
  149. .list-header {
  150. padding: 2px 5px;
  151. .list-header-text {
  152. display: none;
  153. }
  154. .list-header-control-btn {
  155. transform: scale(0.7);
  156. }
  157. }
  158. .item-box {
  159. width: $halfItemWidth;
  160. }
  161. .list-center {
  162. height: $halfCenterHeight;
  163. padding-bottom: 0px;
  164. .list-img {
  165. height: $halfCenterHeight;
  166. width: auto;
  167. }
  168. }
  169. .list-bottom {
  170. display: block;
  171. }
  172. }
  173. }
  174. </style>