index.vue 5.9 KB

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