index.vue
9.82 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<template>
<div
class="go-chart-edit-tools"
:class="[settingStore.getChartToolsStatus, isMiniComputed ? 'isMini' : 'unMini']"
@click="isMini && (isMini = false)"
@mouseenter="toolsMouseoverHandle"
@mouseleave="toolsMouseoutHandle"
>
<!-- PawIcon -->
<n-icon
v-show="settingStore.getChartToolsStatus === ToolsStatusEnum.ASIDE && isMiniComputed"
class="asideLogo"
size="22"
>
<PawIcon></PawIcon>
</n-icon>
<n-tooltip
v-for="(item, index) in btnListComputed"
:key="item.key"
:disabled="!isAside || (isHide && asideTootipDis)"
trigger="hover"
placement="left"
>
<template #trigger>
<div class="btn-item">
<n-button v-if="item.type === TypeEnum.BUTTON" :circle="isAside" secondary @click="item.handle">
<template #icon>
<n-icon size="22" v-if="isAside">
<component :is="item.icon"></component>
</n-icon>
<component v-else :is="item.icon"></component>
</template>
<n-text depth="3" v-show="!isAside">{{ item.name }}</n-text>
</n-button>
<!-- 下载 -->
<n-upload
v-else-if="item.type === TypeEnum.IMPORTUPLOAD"
v-model:file-list="importUploadFileListRef"
:show-file-list="false"
:customRequest="importCustomRequest"
@before-upload="importBeforeUpload"
>
<n-button :circle="isAside" secondary>
<template #icon>
<n-icon size="22" v-if="isAside">
<component :is="item.icon"></component>
</n-icon>
<component v-else :is="item.icon"></component>
</template>
<n-text depth="3" v-show="!isAside">{{ item.name }}</n-text>
</n-button>
</n-upload>
</div>
</template>
<!-- 提示 -->
<span>{{ item.name }}</span>
</n-tooltip>
</div>
<!-- 系统设置 model -->
<go-system-set v-model:modelShow="globalSettingModel"></go-system-set>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
import { useSettingStore } from '@/store/modules/settingStore/settingStore'
import { ToolsStatusEnum } from '@/store/modules/settingStore/settingStore.d'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { EditCanvasTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
import {
fetchRouteParamsLocation,
fetchPathByName,
routerTurnByPath,
setSessionStorage,
getLocalStorage
} from '@/utils'
import { EditEnum } from '@/enums/pageEnum'
import { StorageEnum } from '@/enums/storageEnum'
import { useRoute } from 'vue-router'
import { GoSystemSet } from '@/components/GoSystemSet/index'
import { exportHandle } from './external'// THINGS_KIT 修改引入路径
import { useFile } from './hooks/useFile.hooks'
import { useSyncUpdate } from './hooks/useSyncUpdate.hook'
import { BtnListType, TypeEnum } from './index.d'
import { icon } from '@/plugins'
const { DownloadIcon, ShareIcon, PawIcon, SettingsSharpIcon, CreateIcon } = icon.ionicons5
const settingStore = useSettingStore()
const chartEditStore = useChartEditStore()
const routerParamsInfo = useRoute()
/// THINGS_KIT 关闭监听页面失焦数据同步数据
// 初始化编辑 JSON 模块
// useSyncUpdate()
// 鼠标悬停定时器
let mouseTime: any = null
// 系统设置 model
const globalSettingModel = ref(false)
// 最小化
const isMini = ref<boolean>(true)
// 控制 tootip 提示时机
const asideTootipDis = ref(true)
// 文件上传
const { importUploadFileListRef, importCustomRequest, importBeforeUpload } = useFile()
// 是否是侧边栏
const isAside = computed(() => settingStore.getChartToolsStatus === ToolsStatusEnum.ASIDE)
// 是否隐藏(悬浮展示)
const isHide = computed(() => settingStore.getChartToolsStatusHide)
// 是否展示最小化(与全局配置相关)
const isMiniComputed = computed(() => isMini.value && isHide.value)
// 页面渲染配置
const btnListComputed = computed(() => {
if (!isAside.value) return btnList
const reverseArr: BtnListType[] = []
btnList.map(item => {
reverseArr.unshift(item)
})
return reverseArr
})
// 鼠标移入
const toolsMouseoverHandle = () => {
mouseTime = setTimeout(() => {
if (isMini.value) {
isMini.value = false
asideTootipDis.value = true
}
}, 200)
setTimeout(() => {
asideTootipDis.value = false
}, 400)
}
// 鼠标移出
const toolsMouseoutHandle = () => {
clearTimeout(mouseTime)
if (!isMini.value) {
isMini.value = true
}
}
// 编辑处理
const editHandle = () => {
window['$message'].warning('请通过顶部【同步内容】按钮同步最新数据!')
chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_CODE_EDIT, true)
setTimeout(() => {
// 获取id路径
const path = fetchPathByName(EditEnum.CHART_EDIT_NAME, 'href')
if (!path) return
const id = fetchRouteParamsLocation()
updateToSession(id)
routerTurnByPath(path, [id], undefined, true)
}, 2000)
}
// 把内存中的数据同步到SessionStorage 便于传递给新窗口初始化数据
const updateToSession = (id: string) => {
const storageInfo = chartEditStore.getStorageInfo()
const sessionStorageInfo = getLocalStorage(StorageEnum.GO_CHART_STORAGE_LIST) || []
if (sessionStorageInfo?.length) {
const repeateIndex = sessionStorageInfo.findIndex((e: { id: string }) => e.id === id)
// 重复替换
if (repeateIndex !== -1) {
sessionStorageInfo.splice(repeateIndex, 1, { ...storageInfo, id })
setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, sessionStorageInfo)
} else {
sessionStorageInfo.push({ ...storageInfo, id })
setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, sessionStorageInfo)
}
} else {
setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, [{ ...storageInfo, id }])
}
}
// 配置列表
const btnList: BtnListType[] = [
{
key: 'import',
type: TypeEnum.IMPORTUPLOAD,
name: '导入',
icon: ShareIcon
},
{
key: 'export',
type: TypeEnum.BUTTON,
name: '导出',
icon: DownloadIcon,
handle: exportHandle
},
// {
// key: 'edit',
// type: TypeEnum.BUTTON,
// name: '编辑',
// icon: CreateIcon,
// handle: editHandle
// },
{
key: 'setting',
type: TypeEnum.BUTTON,
name: '设置',
icon: SettingsSharpIcon,
handle: () => {
globalSettingModel.value = true
}
}
]
</script>
<style lang="scss" scoped>
/* 底部区域的高度 */
$dockHeight: 30px;
$dockBottom: 60px;
$dockMiniWidth: 200px;
$dockMiniBottom: 53px;
$asideHeight: 130px;
$asideMiniHeight: 22px;
$asideBottom: 70px;
@include go('chart-edit-tools') {
@extend .go-background-filter;
position: absolute;
display: flex;
justify-content: space-around;
align-items: center;
border-radius: 25px;
border: 1px solid;
@include fetch-border-color('hover-border-color-shallow');
&.aside {
flex-direction: column-reverse;
height: auto;
right: 20px;
padding: 30px 8px;
bottom: $asideBottom;
overflow: hidden;
transition: height ease 0.4s;
.btn-item {
margin-bottom: 10px;
&:first-of-type {
margin-bottom: 0;
}
@include deep() {
.n-button__icon {
margin-right: 0;
margin-left: 0;
margin-bottom: 12px;
}
}
}
&.unMini {
animation: aside-in 0.4s ease forwards;
@keyframes aside-in {
0% {
opacity: 0.5;
height: $asideMiniHeight;
}
100% {
height: $asideHeight;
opacity: 1;
}
}
.btn-item {
position: relative;
display: block;
}
.asideLogo {
opacity: 0.4;
}
}
&.isMini {
cursor: pointer;
padding: 13px 13px;
background-color: var(--n-toggle-bar-color);
animation: aside-mini-in 0.4s ease forwards;
@keyframes aside-mini-in {
0% {
opacity: 0.5;
height: $asideHeight;
}
100% {
opacity: 1;
height: $asideMiniHeight;
}
}
.btn-item {
position: relative;
display: none;
}
.asideLogo {
opacity: 1;
}
}
}
&.dock {
width: auto;
left: 50%;
transform: translateX(-50%);
.btn-item {
margin-right: 20px;
&:last-child {
margin-right: 0;
}
}
&.unMini {
animation: dock-in 0.4s ease forwards;
@keyframes dock-in {
0% {
opacity: 0;
height: 0;
padding: 5px;
bottom: $dockMiniBottom;
}
100% {
height: $dockHeight;
padding: 8px 30px;
bottom: $dockBottom;
border-radius: 25px;
}
}
&::after {
content: '';
position: absolute;
left: 0;
width: 100%;
height: 10px;
bottom: -10px;
cursor: pointer;
}
}
/* 最小化 */
&.isMini {
height: 0;
width: $dockMiniWidth;
bottom: $dockMiniBottom;
padding: 5px;
border-radius: 8px;
cursor: pointer;
border: 0px;
animation: dock-mini-in 1s ease forwards;
@keyframes dock-mini-in {
0% {
opacity: 1;
height: $dockHeight;
padding: 8px 30px;
bottom: $dockBottom;
border-radius: 25px;
}
20% {
height: 0;
border-radius: 8px;
}
50% {
opacity: 0;
bottom: calc(#{$dockMiniBottom} - 10px);
pointer-events: none;
}
100% {
opacity: 1;
height: 0;
padding: 5px;
bottom: $dockMiniBottom;
}
}
.btn-item {
position: relative;
bottom: -50px;
display: none;
}
}
}
}
</style>