82 lines
2.4 KiB
Vue
Raw Normal View History

2022-01-05 18:04:41 +08:00
<template>
<n-space class="go-mt-0">
2022-04-09 23:55:09 +08:00
<n-button v-for="item in btnList" :key="item.title" ghost @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-04-05 19:01:52 +08:00
import { renderIcon, fetchPathByName, routerTurnByPath, setSessionStorage, getLocalStorage } from '@/utils'
2022-03-06 02:08:14 +08:00
import { PreviewEnum } from '@/enums/pageEnum'
import { StorageEnum } from '@/enums/storageEnum'
import { useRoute } from 'vue-router'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
2022-04-05 19:01:52 +08:00
import { EditCanvasTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
2022-04-07 11:24:40 +08:00
import { icon } from '@/plugins'
2022-03-06 02:08:14 +08:00
2022-04-09 23:55:09 +08:00
const { BrowsersOutlineIcon, SendIcon } = icon.ionicons5
2022-03-06 02:08:14 +08:00
const chartEditStore = useChartEditStore()
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 sessionStorageInfo = getLocalStorage(StorageEnum.GO_CHART_STORAGE_LIST) || []
2022-03-06 02:08:14 +08:00
if (sessionStorageInfo?.length) {
const repeateIndex = sessionStorageInfo.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) {
sessionStorageInfo.splice(repeateIndex, 1, { id: previewId, ...storageInfo })
setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, sessionStorageInfo)
2022-03-06 20:31:45 +08:00
} else {
sessionStorageInfo.push({
2022-03-06 20:31:45 +08:00
id: previewId, ...storageInfo
})
setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, sessionStorageInfo)
2022-03-06 02:08:14 +08:00
}
} else {
setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, [{ id: previewId, ...storageInfo }])
2022-03-06 02:08:14 +08:00
}
// 跳转
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
{
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
}
])
2022-04-07 15:28:25 +08:00
2022-01-05 18:04:41 +08:00
</script>
<style lang="scss" scoped>
.align-center {
margin-top: -4px;
}
</style>