165 lines
4.1 KiB
Vue
Raw Normal View History

2022-02-03 22:54:31 +08:00
<template>
<div class="go-flex-items-center">
<n-popover
class="edit-history-popover"
2022-02-03 22:54:31 +08:00
:show="showDropdownRef"
:show-arrow="false"
2022-02-03 22:54:31 +08:00
size="small"
trigger="click"
2022-02-03 22:54:31 +08:00
placement="top-start"
>
<template #trigger>
<n-button
class="mr-10"
secondary
size="small"
:disabled="options.length === 0"
@click="handleClick"
>
<span class="btn-text">历史记录</span>
</n-button>
</template>
<div class="history-list-box">
<n-scrollbar style="max-height: 500px">
<div
class="list-item go-flex-items-center go-ellipsis-1"
v-for="item in options"
:key="item.key"
:title="item.label"
>
<n-icon
class="item-icon"
size="16"
:depth="2"
:component="item.icon"
/>
<n-text depth="2">{{ item.label }}</n-text>
</div>
</n-scrollbar>
<div class="popover-modal"></div>
</div>
</n-popover>
2022-02-03 22:54:31 +08:00
<n-tooltip trigger="hover">
<template #trigger>
<n-icon size="21" :depth="3">
2022-03-14 19:52:01 +08:00
<help-outline-icon></help-outline-icon>
2022-02-03 22:54:31 +08:00
</n-icon>
</template>
<span>最多只保留{{ editHistoryMax }}条记录</span>
2022-02-03 22:54:31 +08:00
</n-tooltip>
</div>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
import { icon } from '@/plugins'
import { renderIcon } from '@/utils'
import { useChartHistoryStore } from '@/store/modules/chartHistoryStore/chartHistoryStore'
2022-02-03 22:54:31 +08:00
import { historyActionTypeName } from '@/store/modules/chartHistoryStore/chartHistoryDefine'
import { CreateComponentType } from '@/packages/index.d'
import { editHistoryMax } from '@/settings/designSetting'
import reverse from 'lodash/reverse'
2022-02-03 22:54:31 +08:00
import {
HistoryItemType,
HistoryTargetTypeEnum,
HistoryActionTypeEnum,
2022-02-03 22:54:31 +08:00
} from '@/store/modules/chartHistoryStore/chartHistoryStore.d'
const {
DesktopOutlineIcon,
PencilIcon,
TrashIcon,
CopyIcon,
LayersIcon,
DuplicateIcon,
HelpOutlineIcon,
2022-02-03 22:54:31 +08:00
} = icon.ionicons5
const { StackedMoveIcon } = icon.carbon
const showDropdownRef = ref(false)
const chartHistoryStoreStore = useChartHistoryStore()
2022-02-03 22:54:31 +08:00
// 设置类型对应图标
const iconHandle = (e: HistoryItemType) => {
// 画布编辑
if (e.targetType === HistoryTargetTypeEnum.CANVAS) {
return DesktopOutlineIcon
2022-02-03 22:54:31 +08:00
}
switch (e.actionType) {
case HistoryActionTypeEnum.UPDATE:
return PencilIcon
2022-02-03 22:54:31 +08:00
case HistoryActionTypeEnum.DELETE:
return TrashIcon
2022-02-03 22:54:31 +08:00
case HistoryActionTypeEnum.PASTE:
return CopyIcon
2022-02-04 18:28:02 +08:00
case HistoryActionTypeEnum.TOP:
return LayersIcon
2022-02-04 18:28:02 +08:00
case HistoryActionTypeEnum.BOTTOM:
return LayersIcon
2022-02-04 18:28:02 +08:00
case HistoryActionTypeEnum.UP:
return LayersIcon
2022-02-04 18:28:02 +08:00
case HistoryActionTypeEnum.DOWN:
return LayersIcon
2022-02-03 22:54:31 +08:00
case HistoryActionTypeEnum.MOVE:
return StackedMoveIcon
2022-02-03 22:54:31 +08:00
case HistoryActionTypeEnum.ADD:
return DuplicateIcon
2022-02-03 22:54:31 +08:00
default:
return PencilIcon
2022-02-03 22:54:31 +08:00
}
}
// 设置类型对应文本
const labelHandle = (e: HistoryItemType) => {
// 画布编辑
if (e.targetType === HistoryTargetTypeEnum.CANVAS) {
return historyActionTypeName[HistoryTargetTypeEnum.CANVAS]
}
return `${historyActionTypeName[e.actionType]} - ${
(e.historyData as CreateComponentType).chartConfig.title
2022-02-03 22:54:31 +08:00
}`
}
const options = computed(() => {
const backStack: HistoryItemType[] = chartHistoryStoreStore.getBackStack
const options = backStack.map((e: HistoryItemType) => {
return {
label: labelHandle(e),
key: e.id,
icon: iconHandle(e),
2022-02-03 22:54:31 +08:00
}
})
return reverse(options)
2022-02-03 22:54:31 +08:00
})
const handleClick = () => {
showDropdownRef.value = !showDropdownRef.value
}
</script>
<style lang="scss" scoped>
.mr-10 {
margin-right: 10px;
}
.edit-history-popover {
2022-02-03 22:54:31 +08:00
.btn-text {
font-size: 12px;
margin-right: 3px;
}
.history-list-box {
width: 100%;
.list-item {
z-index: 2;
position: relative;
cursor: default;
padding: 2px;
.item-icon {
margin-right: 10px;
}
}
}
2022-02-03 22:54:31 +08:00
}
</style>