176 lines
4.2 KiB
Vue
Raw Normal View History

2022-01-06 13:45:51 +08:00
<template>
2022-01-08 21:01:52 +08:00
<ContentBox
class="go-content-charts"
:class="{ scoped: !getCharts }"
2022-01-12 10:41:26 +08:00
title="组件"
2022-01-11 20:56:19 +08:00
:depth="1"
:backIcon="false"
2022-01-08 21:01:52 +08:00
>
<template #icon>
<n-icon size="14" :depth="2">
2022-01-12 10:41:26 +08:00
<BarChartIcon />
2022-01-08 21:01:52 +08:00
</n-icon>
</template>
2022-01-11 20:56:19 +08:00
<!-- 图表 -->
<aside>
<div class="menu-width-box">
<n-menu
class="menu-width"
v-model:value="selectValue"
:options="menuOptions"
:icon-size="16"
:indent="18"
@update:value="clickItemHandle"
/>
<div class="menu-component-box">
2022-01-13 16:20:25 +08:00
<transition name="component-fade" mode="out-in">
<keep-alive>
<component :is="selectNode"></component>
</keep-alive>
</transition>
2022-01-11 20:56:19 +08:00
</div>
</div>
</aside>
2022-01-06 13:45:51 +08:00
</ContentBox>
</template>
<script setup lang="ts">
2022-01-13 16:20:25 +08:00
import { reactive, ref, toRefs } from 'vue'
2022-01-06 13:45:51 +08:00
import { icon } from '@/plugins'
2022-01-11 20:56:19 +08:00
import { renderLang, renderIcon } from '@/utils'
2022-01-06 13:45:51 +08:00
import { ContentBox } from '../ContentBox/index'
2022-01-08 21:01:52 +08:00
import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore'
2022-01-12 10:41:26 +08:00
import { useDesignStore } from '@/store/modules/designStore/designStore'
2022-01-11 20:56:19 +08:00
import { ChartCommon } from './components/ChartCommon'
import { TableCommon } from './components/TableCommon'
import { TextCommon } from './components/TextCommon'
2022-01-12 10:41:26 +08:00
import { DecorateCommon } from './components/DecorateCommon'
2022-01-11 20:56:19 +08:00
2022-01-12 10:41:26 +08:00
// 图标
2022-01-11 20:56:19 +08:00
const { BarChartIcon } = icon.ionicons5
2022-01-13 16:20:25 +08:00
const {
TableSplitIcon,
RoadmapIcon,
SpellCheckIcon,
GraphicalDataFlowIcon
} = icon.carbon
2022-01-11 20:56:19 +08:00
2022-01-12 10:41:26 +08:00
// 全局颜色
const designStore = useDesignStore()
const themeColor = ref(designStore.getAppTheme)
// 结构控制
2022-01-11 20:56:19 +08:00
const { setItem } = useChartLayoutStore()
2022-01-08 21:01:52 +08:00
const { getCharts } = toRefs(useChartLayoutStore())
2022-01-11 20:56:19 +08:00
2022-01-12 10:41:26 +08:00
// 菜单
2022-01-11 20:56:19 +08:00
const collapsed = ref(false)
const menuOptions = reactive([
{
key: 'ChartCommon',
icon: renderIcon(RoadmapIcon),
label: renderLang('图表'),
node: ChartCommon
},
{
key: 'TextCommon',
icon: renderIcon(SpellCheckIcon),
label: renderLang('信息'),
node: TableCommon
},
{
key: 'TableCommon',
icon: renderIcon(TableSplitIcon),
label: renderLang('表格'),
node: TextCommon
2022-01-12 10:41:26 +08:00
},
{
key: 'DecorateCommon',
icon: renderIcon(GraphicalDataFlowIcon),
label: renderLang('装饰'),
node: DecorateCommon
2022-01-11 20:56:19 +08:00
}
])
// 记录选中值
let beforeSelect: string = menuOptions[0]['key']
const selectValue = ref<string>(menuOptions[0]['key'])
2022-01-12 10:41:26 +08:00
// 渲染的组件控制
2022-01-11 20:56:19 +08:00
const selectNode = ref(menuOptions[0]['node'])
// 点击 item
const clickItemHandle = <T extends { node: any }>(key: string, item: T) => {
// 处理渲染的 node
selectNode.value = item.node
// 处理折叠
if (beforeSelect === key) {
setItem('charts', !getCharts.value)
} else {
setItem('charts', true)
}
beforeSelect = key
}
2022-01-06 13:45:51 +08:00
</script>
<style lang="scss" scoped>
2022-01-12 10:41:26 +08:00
/* 整体宽度 */
2022-01-11 20:56:19 +08:00
$width: 300px;
2022-01-12 10:41:26 +08:00
/* 列表的宽度 */
$widthScoped: 65px;
2022-01-11 20:56:19 +08:00
/* 此高度与 ContentBox 组件关联*/
$topHeight: 36px;
2022-01-12 10:41:26 +08:00
2022-01-06 13:45:51 +08:00
@include go(content-charts) {
2022-01-11 20:56:19 +08:00
width: $width;
2022-01-08 21:01:52 +08:00
@extend .go-transition;
2022-01-11 20:56:19 +08:00
&.scoped,
.menu-width {
width: $widthScoped;
}
.menu-width-box {
display: flex;
height: calc(100vh - #{$--header-height} - #{$topHeight});
.menu-width {
2022-01-13 16:20:25 +08:00
flex-shrink: 0;
2022-01-13 18:01:33 +08:00
@include filter-bg-color('background-color2');
2022-01-11 20:56:19 +08:00
}
.menu-component-box {
2022-01-13 16:20:25 +08:00
flex-shrink: 0;
2022-01-11 20:56:19 +08:00
width: $width - $widthScoped;
overflow: hidden;
}
}
@include deep() {
2022-01-13 16:20:25 +08:00
.menu-width {
.n-menu-item {
height: auto !important;
&.n-menu-item--selected {
&::after {
content: '';
position: absolute;
left: 2px;
top: 0;
height: 100%;
width: 3px;
background-color: v-bind('themeColor');
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
}
}
.n-menu-item-content {
display: flex;
flex-direction: column;
padding: 6px 12px !important;
font-size: 12px !important;
}
.n-menu-item-content__icon {
font-size: 18px !important;
margin-right: 0 !important;
2022-01-12 10:41:26 +08:00
}
}
2022-01-11 20:56:19 +08:00
}
2022-01-08 21:01:52 +08:00
}
2022-01-06 13:45:51 +08:00
}
</style>