2022-01-05 18:04:41 +08:00
|
|
|
<template>
|
|
|
|
<n-space class="go-mt-0">
|
2022-03-06 02:08:14 +08:00
|
|
|
<n-button v-for="item in btnList" :key="item.title" ghost size="small" @click="item.event">
|
2022-01-05 18:04:41 +08:00
|
|
|
<template #icon>
|
|
|
|
<component :is="item.icon"></component>
|
|
|
|
</template>
|
2022-03-06 02:08:14 +08:00
|
|
|
<span>{{ item.title }}</span>
|
2022-01-05 18:04:41 +08:00
|
|
|
</n-button>
|
|
|
|
</n-space>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2022-03-09 17:37:32 +08:00
|
|
|
import { shallowReactive } from 'vue'
|
2022-03-06 02:08:14 +08:00
|
|
|
import { renderIcon, fetchPathByName, routerTurnByPath, setLocalStorage, getLocalStorage } from '@/utils'
|
|
|
|
import { PreviewEnum } from '@/enums/pageEnum'
|
|
|
|
import { StorageEnum } from '@/enums/storageEnum'
|
2022-01-05 18:04:41 +08:00
|
|
|
import { icon } from '@/plugins'
|
2022-03-06 02:08:14 +08:00
|
|
|
import { useRoute } from 'vue-router'
|
|
|
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
|
|
|
|
2022-02-06 21:35:38 +08:00
|
|
|
const { BrowsersOutlineIcon, SendIcon } = icon.ionicons5
|
2022-03-06 02:08:14 +08:00
|
|
|
const chartEditStore = useChartEditStore()
|
|
|
|
|
|
|
|
// TODO 我也不知道为什么不能实时获取,必须初始化获取
|
|
|
|
const routerParamsInfo = useRoute()
|
|
|
|
|
|
|
|
// 预览
|
|
|
|
const previewHandle = () => {
|
|
|
|
const path = fetchPathByName(PreviewEnum.CHART_PREVIEW_NAME, 'href')
|
|
|
|
if (!path) return
|
|
|
|
const { id } = routerParamsInfo.params
|
|
|
|
// id 标识
|
|
|
|
const previewId = typeof id === 'string' ? id : id[0]
|
|
|
|
const storageInfo = chartEditStore.getStorageInfo
|
|
|
|
const localStorageInfo = getLocalStorage(StorageEnum.GO_CHART_STORAGE_LIST) || []
|
|
|
|
|
|
|
|
if (localStorageInfo?.length) {
|
|
|
|
const repeateIndex = localStorageInfo.findIndex((e: { id: string }) => e.id === previewId)
|
2022-03-06 20:31:45 +08:00
|
|
|
// 重复替换
|
2022-03-06 02:08:14 +08:00
|
|
|
if (repeateIndex !== -1) {
|
|
|
|
localStorageInfo.splice(repeateIndex, 1, { id: previewId, ...storageInfo })
|
2022-03-06 20:31:45 +08:00
|
|
|
setLocalStorage(StorageEnum.GO_CHART_STORAGE_LIST, localStorageInfo)
|
|
|
|
} else {
|
|
|
|
localStorageInfo.push({
|
|
|
|
id: previewId, ...storageInfo
|
|
|
|
})
|
|
|
|
setLocalStorage(StorageEnum.GO_CHART_STORAGE_LIST, localStorageInfo)
|
2022-03-06 02:08:14 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
setLocalStorage(StorageEnum.GO_CHART_STORAGE_LIST, [{ id: previewId, ...storageInfo }])
|
|
|
|
}
|
|
|
|
// 跳转
|
|
|
|
routerTurnByPath(path, [previewId], undefined, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 发布
|
|
|
|
const sendHandle = () => {
|
|
|
|
window['$message'].warning('该功能暂未实现(因为压根没有后台)')
|
|
|
|
}
|
2022-01-05 18:04:41 +08:00
|
|
|
|
2022-03-09 17:37:32 +08:00
|
|
|
const btnList = shallowReactive([
|
2022-01-05 18:04:41 +08:00
|
|
|
{
|
2022-03-06 02:08:14 +08:00
|
|
|
key: '',
|
2022-01-05 18:04:41 +08:00
|
|
|
select: true,
|
|
|
|
title: '预览',
|
2022-03-06 02:08:14 +08:00
|
|
|
icon: renderIcon(BrowsersOutlineIcon),
|
|
|
|
event: previewHandle
|
2022-01-05 18:04:41 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
select: true,
|
|
|
|
title: '发布',
|
2022-03-06 02:08:14 +08:00
|
|
|
icon: renderIcon(SendIcon),
|
|
|
|
event: sendHandle
|
2022-01-05 18:04:41 +08:00
|
|
|
}
|
|
|
|
])
|
|
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.align-center {
|
|
|
|
margin-top: -4px;
|
|
|
|
}
|
|
|
|
</style>
|