index.vue 6.0 KB

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