93 lines
2.4 KiB
Vue
Raw Normal View History

2022-01-14 22:07:02 +08:00
<template>
2022-01-19 09:19:17 +08:00
<div class="go-content-charts-item-box">
<!-- 每一项组件的渲染 -->
<div
class="item-box"
v-for="(item, index) in menuOptions"
:key="index"
draggable
@dragstart="handleDragStart($event, item)"
>
<div class="list-header">
2022-02-26 17:38:24 +08:00
<MacOsControlBtn :mini="true" :disabled="true"></MacOsControlBtn>
2022-01-19 09:19:17 +08:00
<n-text class="list-header-text" depth="3">{{ item.title }}</n-text>
</div>
<div class="list-center go-flex-center">
<img class="list-img" v-lazy="item.image" alt="图表图片" />
2022-01-19 09:19:17 +08:00
</div>
2022-01-14 22:07:02 +08:00
</div>
</div>
</template>
<script setup lang="ts">
2022-03-07 12:33:05 +08:00
import { PropType, toRaw } from 'vue'
2022-02-26 17:38:24 +08:00
import { MacOsControlBtn } from '@/components/MacOsControlBtn/index'
2022-03-06 21:26:31 +08:00
import { componentInstall } from '@/utils'
2022-01-24 21:12:18 +08:00
import { DragKeyEnum } from '@/enums/editPageEnum'
import { ConfigType } from '@/packages/index.d'
import omit from 'lodash/omit'
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-01-24 21:12:18 +08:00
const handleDragStart = (e: DragEvent, item: ConfigType) => {
2022-02-26 17:38:24 +08:00
// 动态注册图表组件
2022-03-07 12:33:05 +08:00
componentInstall(item.key, item.node())
componentInstall(item.conKey, item.conNode())
2022-01-24 21:12:18 +08:00
// 将配置项绑定到拖拽属性上
2022-03-07 12:33:05 +08:00
e!.dataTransfer!.setData(DragKeyEnum.DROG_KEY, JSON.stringify(omit(item, ['node', 'conNode', 'image'])))
2022-01-19 09:19:17 +08:00
}
2022-01-14 22:07:02 +08:00
</script>
<style lang="scss" scoped>
/* 列表项宽度 */
$itemWidth: 86%;
/* 内容高度 */
2022-01-15 22:35:32 +08:00
$centerHeight: 100px;
2022-01-19 09:19:17 +08:00
@include go('content-charts-item-box') {
.item-box {
margin: 0 7%;
margin-bottom: 15px;
width: $itemWidth;
overflow: hidden;
border-radius: 6px;
cursor: pointer;
border: 1px solid rgba(0, 0, 0, 0);
@include filter-bg-color('background-color2');
@extend .go-transition;
&: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;
@include filter-bg-color('background-color3');
&-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 {
height: 100%;
border-radius: 6px;
@extend .go-transition;
}
2022-01-14 22:07:02 +08:00
}
}
}
</style>