226 lines
6.0 KiB
Vue
Raw Normal View History

2022-01-14 22:07:02 +08:00
<template>
2022-11-22 21:25:52 +08:00
<div class="go-content-charts-item-animation-patch">
2022-01-19 09:19:17 +08:00
<div
2022-11-22 21:25:52 +08:00
ref="contentChartsItemBoxRef"
class="go-content-charts-item-box"
:class="[chartMode === ChartModeEnum.DOUBLE ? 'double' : 'single']"
2022-01-19 09:19:17 +08:00
>
2022-11-22 21:25:52 +08:00
<!-- 每一项组件的渲染 -->
<div
class="item-box"
v-for="(item, index) in menuOptions"
:key="index"
draggable
@dragstart="dragStartHandle($event, item)"
@dragend="dragendHandle"
@dblclick="dblclickHandle(item)"
>
<div class="list-header">
<mac-os-control-btn class="list-header-control-btn" :mini="true" :disabled="true"></mac-os-control-btn>
<n-text class="list-header-text" depth="3">
<n-ellipsis>{{ item.title }}</n-ellipsis>
</n-text>
</div>
2022-11-24 11:48:13 +08:00
<div class="list-center go-flex-center go-transition">
<charts-item-image class="list-img" :chartConfig="item"></charts-item-image>
2022-11-22 21:25:52 +08:00
</div>
<div class="list-bottom">
<n-text class="list-bottom-text" depth="3">
<n-ellipsis style="max-width: 90%">{{ item.title }}</n-ellipsis>
</n-text>
</div>
2022-11-13 21:28:38 +08:00
</div>
2022-01-14 22:07:02 +08:00
</div>
</div>
</template>
<script setup lang="ts">
2022-11-22 21:25:52 +08:00
import { PropType, watch, ref, Ref, computed, nextTick } from 'vue'
2022-04-14 10:05:57 +08:00
import { MacOsControlBtn } from '@/components/Tips/MacOsControlBtn/index'
import { ChartsItemImage } from '../ChartsItemImage'
2022-04-11 18:17:09 +08:00
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { EditCanvasTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
2022-11-13 21:28:38 +08:00
import { ChartModeEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d'
import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore'
import { componentInstall, loadingStart, loadingFinish, loadingError, JSONStringify } from '@/utils'
2022-01-24 21:12:18 +08:00
import { DragKeyEnum } from '@/enums/editPageEnum'
import { createComponent } from '@/packages'
import { ConfigType, CreateComponentType } from '@/packages/index.d'
import { fetchConfigComponent, fetchChartComponent } from '@/packages/index'
2022-01-24 21:12:18 +08:00
import omit from 'lodash/omit'
2022-04-11 18:17:09 +08:00
const chartEditStore = useChartEditStore()
2022-01-24 21:12:18 +08:00
2022-01-14 22:07:02 +08:00
defineProps({
menuOptions: {
2022-02-26 17:38:24 +08:00
type: Array as PropType<ConfigType[]>,
2022-01-14 22:07:02 +08:00
default: () => []
}
})
2022-01-19 09:19:17 +08:00
2022-11-13 21:28:38 +08:00
const chartLayoutStore = useChartLayoutStore()
2022-11-22 21:25:52 +08:00
const contentChartsItemBoxRef = ref()
2022-11-13 21:28:38 +08:00
// 组件展示状态
const chartMode: Ref<ChartModeEnum> = computed(() => {
return chartLayoutStore.getChartType
})
2022-01-19 09:19:17 +08:00
// 拖拽处理
2022-04-11 18:17:09 +08:00
const dragStartHandle = (e: DragEvent, item: ConfigType) => {
2022-02-26 17:38:24 +08:00
// 动态注册图表组件
componentInstall(item.chartKey, fetchChartComponent(item))
componentInstall(item.conKey, fetchConfigComponent(item))
2022-01-24 21:12:18 +08:00
// 将配置项绑定到拖拽属性上
e!.dataTransfer!.setData(DragKeyEnum.DRAG_KEY, JSONStringify(omit(item, ['image'])))
2022-04-11 18:17:09 +08:00
// 修改状态
chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_CREATE, true)
}
// 拖拽结束
const dragendHandle = () => {
chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_CREATE, false)
2022-01-19 09:19:17 +08:00
}
// 双击添加
const dblclickHandle = async (item: ConfigType) => {
try {
loadingStart()
// 动态注册图表组件
componentInstall(item.chartKey, fetchChartComponent(item))
componentInstall(item.conKey, fetchConfigComponent(item))
// 创建新图表组件
let newComponent: CreateComponentType = await createComponent(item)
// 添加
chartEditStore.addComponentList(newComponent, false, true)
// 选中
chartEditStore.setTargetSelectChart(newComponent.id)
loadingFinish()
} catch (error) {
loadingError()
window['$message'].warning(`图表正在研发中, 敬请期待...`)
}
}
2022-11-22 21:25:52 +08:00
watch(
() => chartMode.value,
(newValue: ChartModeEnum) => {
if (newValue === ChartModeEnum.DOUBLE) {
nextTick(() => {
contentChartsItemBoxRef.value.classList.add('miniAnimation')
})
}
}
)
2022-01-14 22:07:02 +08:00
</script>
<style lang="scss" scoped>
/* 列表项宽度 */
2022-11-13 21:28:38 +08:00
$itemWidth: 100%;
2022-11-22 21:25:52 +08:00
$maxItemWidth: 180px;
2022-11-13 21:28:38 +08:00
$halfItemWidth: 46%;
2022-01-14 22:07:02 +08:00
/* 内容高度 */
2022-01-15 22:35:32 +08:00
$centerHeight: 100px;
2022-11-13 21:28:38 +08:00
$halfCenterHeight: 50px;
2022-11-22 21:25:52 +08:00
@include go('content-charts-item-animation-patch') {
padding: 10px;
}
2022-01-19 09:19:17 +08:00
@include go('content-charts-item-box') {
2022-11-13 21:28:38 +08:00
display: flex;
flex-wrap: wrap;
2022-11-13 21:38:46 +08:00
justify-content: space-between;
2022-11-13 21:28:38 +08:00
gap: 9px;
2022-11-22 21:25:52 +08:00
transition: all 0.7s linear;
2022-01-19 09:19:17 +08:00
.item-box {
2022-11-13 21:28:38 +08:00
margin: 0;
2022-01-19 09:19:17 +08:00
width: $itemWidth;
overflow: hidden;
border-radius: 6px;
cursor: pointer;
border: 1px solid rgba(0, 0, 0, 0);
2022-05-02 17:18:18 +08:00
@include fetch-bg-color('background-color2');
2022-01-19 09:19:17 +08:00
&:hover {
@include hover-border-color('background-color4');
.list-img {
transform: scale(1.1);
}
2022-01-15 21:05:11 +08:00
}
2022-01-19 09:19:17 +08:00
.list-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 2px 15px;
2022-05-02 17:18:18 +08:00
@include fetch-bg-color('background-color3');
2022-01-19 09:19:17 +08:00
&-text {
font-size: 12px;
margin-left: 8px;
}
2022-01-14 22:07:02 +08:00
}
2022-01-19 09:19:17 +08:00
.list-center {
padding: 6px 0;
height: $centerHeight;
overflow: hidden;
.list-img {
2022-10-17 09:42:56 +08:00
height: 100px;
width: 140px;
2022-01-19 09:19:17 +08:00
border-radius: 6px;
@extend .go-transition;
}
2022-01-14 22:07:02 +08:00
}
2022-11-13 21:28:38 +08:00
.list-bottom {
display: none;
.list-bottom-text {
font-size: 12px;
padding-left: 5px;
}
}
}
2022-11-22 21:25:52 +08:00
&.single {
.item-box {
@extend .go-transition;
}
}
2022-11-13 21:28:38 +08:00
&.double {
.list-header {
padding: 2px 5px;
.list-header-text {
display: none;
}
.list-header-control-btn {
transform: scale(0.7);
}
}
.item-box {
width: $halfItemWidth;
2022-11-22 21:25:52 +08:00
max-width: $maxItemWidth;
2022-11-13 21:28:38 +08:00
}
.list-center {
height: $halfCenterHeight;
padding-bottom: 0px;
.list-img {
height: $halfCenterHeight;
width: auto;
2022-11-24 11:48:13 +08:00
transition: all 0.2s;
2022-11-13 21:28:38 +08:00
}
}
.list-bottom {
display: block;
}
2022-01-14 22:07:02 +08:00
}
2022-11-24 11:48:13 +08:00
/* 缩小展示 */
@keyframes miniAnimation {
from {
width: $itemWidth * 2;
}
to {
width: $itemWidth;
}
}
&.miniAnimation {
animation: miniAnimation 0.5s;
}
2022-01-14 22:07:02 +08:00
}
</style>