index.vue
5.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<template>
<div class="go-flex-items-center">
<n-popover class="edit-history-popover" :show-arrow="false" size="small" trigger="click" placement="top-start">
<template #trigger>
<n-button class="mr-10" secondary size="small" :disabled="options.length === 0">
<span class="btn-text">{{ t('common.histor') }}</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, index) in options"
:key="index"
: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>
<n-tooltip trigger="hover">
<template #trigger>
<n-icon size="21" :depth="3">
<help-outline-icon></help-outline-icon>
</n-icon>
</template>
<!-- <span>最多只保留{{ editHistoryMax }}条记录</span> -->
<span>{{ t('common.maxNumber100',{number:editHistoryMax}) }}</span>
</n-tooltip>
</div>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
import { icon } from '@/plugins'
import { useChartHistoryStore } from '@/store/modules/chartHistoryStore/chartHistoryStore'
// import { historyActionTypeName } from '@/store/modules/chartHistoryStore/chartHistoryDefine'
import { CreateComponentType } from '@/packages/index.d'
import { editHistoryMax } from '@/settings/designSetting'
import reverse from 'lodash/reverse'
import {
HistoryItemType,
HistoryTargetTypeEnum,
HistoryActionTypeEnum
} from '@/store/modules/chartHistoryStore/chartHistoryStore.d'
const {
DesktopOutlineIcon,
PencilIcon,
TrashIcon,
CopyIcon,
LayersIcon,
DuplicateIcon,
HelpOutlineIcon,
LockClosedOutlineIcon,
LockOpenOutlineIcon,
EyeOffOutlineIcon,
EyeOutlineIcon
} = icon.ionicons5
const { StackedMoveIcon, Carbon3DCursorIcon, Carbon3DSoftwareIcon } = icon.carbon
const t = window['$t']
const historyActionTypeName = {
[HistoryActionTypeEnum.ADD]: t('common.historyActionTypes.add'),
[HistoryActionTypeEnum.DELETE]: t('common.historyActionTypes.delete'),
[HistoryActionTypeEnum.UPDATE]: t('common.historyActionTypes.update'),
[HistoryActionTypeEnum.MOVE]: t('common.historyActionTypes.move'),
[HistoryActionTypeEnum.PASTE]: t('common.historyActionTypes.paste'),
[HistoryActionTypeEnum.COPY]: t('common.historyActionTypes.copy'),
[HistoryActionTypeEnum.CUT]: t('common.historyActionTypes.cut'),
[HistoryActionTypeEnum.TOP]: t('common.historyActionTypes.top'),
[HistoryActionTypeEnum.BOTTOM]:t('common.historyActionTypes.bottom'),
[HistoryActionTypeEnum.UP]: t('common.historyActionTypes.up'),
[HistoryActionTypeEnum.DOWN]: t('common.historyActionTypes.down'),
[HistoryActionTypeEnum.GROUP]: t('common.historyActionTypes.group'),
[HistoryActionTypeEnum.UN_GROUP]: t('common.historyActionTypes.unGroup'),
[HistoryActionTypeEnum.LOCK]: t('common.historyActionTypes.lock'),
[HistoryActionTypeEnum.UNLOCK]: t('common.historyActionTypes.unlock'),
[HistoryActionTypeEnum.HIDE]: t('common.historyActionTypes.hide'),
[HistoryActionTypeEnum.SHOW]: t('common.historyActionTypes.show'),
[HistoryTargetTypeEnum.CANVAS]: t('common.historyActionTypes.canvas')
}
const chartHistoryStoreStore = useChartHistoryStore()
// 设置类型对应图标
const iconHandle = (e: HistoryItemType) => {
// 画布编辑
if (e.targetType === HistoryTargetTypeEnum.CANVAS) {
return DesktopOutlineIcon
}
switch (e.actionType) {
case HistoryActionTypeEnum.UPDATE:
return PencilIcon
case HistoryActionTypeEnum.DELETE:
return TrashIcon
case HistoryActionTypeEnum.PASTE:
return CopyIcon
case HistoryActionTypeEnum.TOP:
return LayersIcon
case HistoryActionTypeEnum.BOTTOM:
return LayersIcon
case HistoryActionTypeEnum.UP:
return LayersIcon
case HistoryActionTypeEnum.DOWN:
return LayersIcon
case HistoryActionTypeEnum.MOVE:
return StackedMoveIcon
case HistoryActionTypeEnum.ADD:
return DuplicateIcon
case HistoryActionTypeEnum.GROUP:
return Carbon3DCursorIcon
case HistoryActionTypeEnum.UN_GROUP:
return Carbon3DSoftwareIcon
case HistoryActionTypeEnum.LOCK:
return LockClosedOutlineIcon
case HistoryActionTypeEnum.UNLOCK:
return LockOpenOutlineIcon
case HistoryActionTypeEnum.HIDE:
return EyeOffOutlineIcon
case HistoryActionTypeEnum.SHOW:
return EyeOutlineIcon
default:
return PencilIcon
}
}
// 设置类型对应文本
const labelHandle = (e: HistoryItemType) => {
// 画布编辑
if (e.targetType === HistoryTargetTypeEnum.CANVAS) {
return historyActionTypeName[HistoryTargetTypeEnum.CANVAS]
} else if (e.actionType === HistoryActionTypeEnum.GROUP || e.actionType === HistoryActionTypeEnum.UN_GROUP) {
return `${historyActionTypeName[e.actionType]}`
} else if (e.historyData.length) {
return `${historyActionTypeName[e.actionType]} - ${t((e.historyData[0] as CreateComponentType).chartConfig.title)}`
}
}
const options = computed(() => {
const backStack: HistoryItemType[] = chartHistoryStoreStore.getBackStack
const options = backStack.map((e: HistoryItemType) => {
return {
label: labelHandle(e),
icon: iconHandle(e)
}
})
return reverse(options.filter(item => item.label))
})
</script>
<style lang="scss" scoped>
.mr-10 {
margin-right: 10px;
}
.edit-history-popover {
.btn-text {
font-size: 12px;
margin-right: 3px;
}
.history-list-box {
width: 100%;
.list-item {
// z-index: 2;
// position: relative;
cursor: pointer;
padding: 2px;
.item-icon {
margin-right: 10px;
}
}
}
}
</style>