314 lines
8.7 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"
2023-05-24 17:59:27 +08:00
v-for="(item, index) in menuOptions"
2023-05-23 20:55:24 +08:00
:key="item.title"
2022-11-22 21:25:52 +08:00
draggable
@dragstart="!item.disabled && dragStartHandle($event, item)"
@dragend="!item.disabled && dragendHandle"
2022-11-22 21:25:52 +08:00
@dblclick="dblclickHandle(item)"
@click="clickHandle(item)"
2022-11-22 21:25:52 +08:00
>
<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>
2023-05-19 17:15:24 +08:00
<div class="list-center go-flex-center go-transition" draggable="true">
2023-12-17 00:12:50 +08:00
<GoIconify v-if="item.icon" class="list-img" :icon="item.icon" color="#999" width="48" style="height: auto" />
<chart-glob-image v-else class="list-img" :chartConfig="item" />
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>
<!-- 遮罩 -->
<div v-if="item.disabled" class="list-model"></div>
<!-- 工具栏 -->
2023-05-24 17:59:27 +08:00
<div v-if="isShowTools(item)" class="list-tools go-transition" @click="deleteHandle(item, index)">
<n-button text type="default" color="#ffffff">
<template #icon>
<n-icon>
<TrashIcon />
</n-icon>
</template>
<span>删除</span>
</n-button>
</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 { ChartGlobImage } from '@/components/Pages/ChartGlobImage'
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'
2023-05-24 17:59:27 +08:00
import { usePackagesStore } from '@/store/modules/packagesStore/packagesStore'
import { componentInstall, loadingStart, loadingFinish, loadingError, JSONStringify, goDialog } from '@/utils'
2022-01-24 21:12:18 +08:00
import { DragKeyEnum } from '@/enums/editPageEnum'
import { createComponent } from '@/packages'
import { ConfigType, CreateComponentType, PackagesCategoryEnum } from '@/packages/index.d'
import { ChatCategoryEnum } from '@/packages/components/Photos/index.d'
import { fetchConfigComponent, fetchChartComponent } from '@/packages/index'
2023-12-17 00:12:50 +08:00
import { GoIconify } from '@/components/GoIconify'
import { icon } from '@/plugins'
2022-01-24 21:12:18 +08:00
import omit from 'lodash/omit'
2022-04-11 18:17:09 +08:00
const chartEditStore = useChartEditStore()
const { TrashIcon } = icon.ionicons5
2022-01-24 21:12:18 +08:00
2023-05-24 17:59:27 +08:00
const emit = defineEmits(['deletePhoto'])
2023-05-23 20:55:24 +08:00
const props = defineProps({
2022-01-14 22:07:02 +08:00
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 isShowTools = (item: ConfigType) => {
return !item.disabled && item.package === PackagesCategoryEnum.PHOTOS && item.category === ChatCategoryEnum.PRIVATE
}
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) => {
if (item.disabled) return
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) => {
if (item.disabled) return
try {
loadingStart()
// 动态注册图表组件
componentInstall(item.chartKey, fetchChartComponent(item))
componentInstall(item.conKey, fetchConfigComponent(item))
// 创建新图表组件
let newComponent: CreateComponentType = await createComponent(item)
2023-05-23 20:55:24 +08:00
if (item.redirectComponent) {
item.dataset && (newComponent.option.dataset = item.dataset)
newComponent.chartConfig.title = item.title
newComponent.chartConfig.chartFrame = item.chartFrame
}
// 添加
chartEditStore.addComponentList(newComponent, false, true)
// 选中
chartEditStore.setTargetSelectChart(newComponent.id)
loadingFinish()
} catch (error) {
loadingError()
window['$message'].warning(`图表正在研发中, 敬请期待...`)
}
}
2022-11-22 21:25:52 +08:00
// 单击事件
2023-05-24 17:59:27 +08:00
const clickHandle = (item: ConfigType) => {
item?.configEvents?.addHandle(item)
}
const deleteHandle = (item: ConfigType, index: number) => {
goDialog({
message: '是否删除此图片?',
transformOrigin: 'center',
onPositiveCallback: () => {
const packagesStore = usePackagesStore()
emit('deletePhoto', item, index)
packagesStore.deletePhotos(item, index)
}
})
}
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 {
position: relative;
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.08);
}
.list-tools {
opacity: 1;
2022-01-19 09:19:17 +08:00
}
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;
2023-05-24 17:59:27 +08:00
user-select: none;
2022-01-19 09:19:17 +08:00
}
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;
2023-05-23 20:55:24 +08:00
max-width: 140px;
2022-01-19 09:19:17 +08:00
border-radius: 6px;
object-fit: contain;
2022-01-19 09:19:17 +08:00
@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;
}
}
.list-model {
z-index: 1;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0);
}
.list-tools {
position: absolute;
display: flex;
justify-content: center;
align-items: center;
bottom: 0;
left: 0;
margin: 0 4px 2px;
height: 26px;
width: calc(100% - 8px);
opacity: 0;
border-radius: 6px;
backdrop-filter: blur(20px);
2023-05-24 17:59:27 +08:00
background-color: rgba(255, 255, 255, 0.15);
&:hover {
background-color: rgba(232, 128, 128, 0.7);
}
}
2022-11-13 21:28:38 +08:00
}
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;
2023-05-23 20:55:24 +08:00
.list-img {
max-width: 76px;
}
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;
object-fit: contain;
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>