145 lines
4.1 KiB
Vue
Raw Normal View History

2022-01-05 18:04:41 +08:00
<template>
<n-space class="header-left-btn" :size="25">
2022-01-11 20:56:19 +08:00
<n-button size="small" quaternary @click="goHomeHandle()">
<template #icon>
<n-icon :depth="3">
2022-03-14 19:52:01 +08:00
<home-icon></home-icon>
2022-01-11 20:56:19 +08:00
</n-icon>
</template>
</n-button>
<n-space>
2022-01-16 22:17:34 +08:00
<n-tooltip v-for="item in btnList" :key="item.key" placement="bottom" trigger="hover">
<template #trigger>
<n-button size="small" ghost :type="styleHandle(item)" @click="clickHandle(item)">
<component :is="item.icon"></component>
</n-button>
</template>
<span>{{ item.title }}</span>
</n-tooltip>
<n-divider vertical />
<n-tooltip v-for="item in historyList" :key="item.key" placement="bottom" trigger="hover">
<template #trigger>
<n-button size="small" ghost type="primary" :disabled="!item.select" @click="clickHistoryHandle(item)">
<component :is="item.icon"></component>
</n-button>
</template>
<span>{{ item.title }}</span>
</n-tooltip>
</n-space>
2022-01-05 18:04:41 +08:00
</n-space>
</template>
<script setup lang="ts">
import { toRefs, Ref, reactive, computed } from 'vue'
2022-01-09 19:22:55 +08:00
import { renderIcon, goDialog, goHome } from '@/utils'
2022-01-05 20:52:49 +08:00
import { icon } from '@/plugins'
import { useRemoveKeyboard } from '../hooks/useKeyboard.hook'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { useChartHistoryStore } from '@/store/modules/chartHistoryStore/chartHistoryStore'
import { HistoryStackEnum } from '@/store/modules/chartHistoryStore/chartHistoryStore.d'
import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore'
2022-01-20 21:25:35 +08:00
import { ChartLayoutStoreEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d'
2022-01-05 20:52:49 +08:00
const { LayersIcon, BarChartIcon, PrismIcon, HomeIcon, ArrowBackIcon, ArrowForwardIcon } = icon.ionicons5
2022-01-08 14:27:56 +08:00
const { setItem } = useChartLayoutStore()
const { getLayers, getCharts, getDetails } = toRefs(useChartLayoutStore())
const chartEditStore = useChartEditStore()
const chartHistoryStore = useChartHistoryStore()
2022-01-05 18:04:41 +08:00
interface ItemType<T> {
key: T
2022-01-11 20:56:19 +08:00
select: Ref<boolean> | boolean
title: string
icon: any
}
const btnList = reactive<ItemType<ChartLayoutStoreEnum>[]>([
2022-01-05 18:04:41 +08:00
{
2022-01-20 21:25:35 +08:00
key: ChartLayoutStoreEnum.CHARTS,
2022-01-08 14:27:56 +08:00
select: getCharts,
2022-01-05 18:04:41 +08:00
title: '图表组件',
icon: renderIcon(BarChartIcon)
2022-01-05 20:52:49 +08:00
},
{
2022-01-20 21:25:35 +08:00
key: ChartLayoutStoreEnum.LAYERS,
select: getLayers,
title: '图层控制',
icon: renderIcon(LayersIcon)
},
2022-01-05 20:52:49 +08:00
{
2022-01-20 21:25:35 +08:00
key: ChartLayoutStoreEnum.DETAILS,
2022-01-08 14:27:56 +08:00
select: getDetails,
2022-01-05 20:52:49 +08:00
title: '详情设置',
icon: renderIcon(PrismIcon)
2022-01-05 18:04:41 +08:00
}
2022-01-08 14:27:56 +08:00
])
const isBackStack = computed(()=> chartHistoryStore.getBackStack.length> 1)
const isForwardStack = computed(()=> chartHistoryStore.getForwardStack.length> 0)
const historyList = reactive<ItemType<HistoryStackEnum>[]>([
{
key: HistoryStackEnum.BACK_STACK,
// 一定会有初始化画布
select: isBackStack,
title: '后退',
icon: renderIcon(ArrowBackIcon)
},
{
key: HistoryStackEnum.FORWARD_STACK,
select: isForwardStack,
title: '前进',
icon: renderIcon(ArrowForwardIcon)
}
])
2022-01-16 22:17:34 +08:00
2022-02-26 17:38:24 +08:00
// store 描述的是展示的值,所以和 ContentConfigurations 的 collapsed 是相反的
const styleHandle = (item: ItemType<ChartLayoutStoreEnum>) => {
2022-01-20 21:25:35 +08:00
if (item.key === ChartLayoutStoreEnum.DETAILS) {
2022-03-12 15:25:26 +08:00
return item.select ? '' : 'primary'
2022-01-16 22:17:34 +08:00
}
2022-03-12 15:25:26 +08:00
return item.select ? 'primary' : ''
2022-01-16 22:17:34 +08:00
}
// 布局处理
const clickHandle = (item: ItemType<ChartLayoutStoreEnum>) => {
2022-01-08 14:27:56 +08:00
setItem(item.key, !item.select)
}
2022-01-09 19:22:55 +08:00
// 历史记录处理
const clickHistoryHandle = (item: ItemType<HistoryStackEnum>) => {
switch (item.key) {
case HistoryStackEnum.BACK_STACK:
chartEditStore.setBack()
break;
case HistoryStackEnum.FORWARD_STACK:
chartEditStore.setForward()
break;
}
}
// 返回首页
2022-01-09 19:22:55 +08:00
const goHomeHandle = () => {
goDialog({
message: '返回将不会保存任何操作',
isMaskClosable: true,
2022-02-03 22:54:31 +08:00
onPositiveCallback: () => {
goHome()
useRemoveKeyboard()
}
2022-01-09 19:22:55 +08:00
})
}
2022-01-05 18:04:41 +08:00
</script>
2022-01-05 20:52:49 +08:00
<style lang="scss" scoped>
.header-left-btn {
margin-left: -37px;
}
2022-01-05 20:52:49 +08:00
</style>