157 lines
3.8 KiB
Vue
Raw Normal View History

2022-01-14 22:07:02 +08:00
<template>
<!-- 侧边栏和数据分发处理 -->
2022-01-14 22:07:02 +08:00
<div class="go-chart-common">
<n-menu
2022-01-15 14:56:48 +08:00
v-show="hidePackageOneCategory"
2022-01-14 22:07:02 +08:00
class="chart-menu-width"
v-model:value="selectValue"
:options="packages.menuOptions"
:icon-size="16"
:indent="18"
@update:value="clickItemHandle"
></n-menu>
2022-01-14 22:07:02 +08:00
<div class="chart-content-list">
<n-scrollbar trigger="none">
2022-04-21 22:35:28 +08:00
<charts-item-box :menuOptions="packages.selectOptions"></charts-item-box>
2022-01-15 21:05:11 +08:00
</n-scrollbar>
2022-01-14 22:07:02 +08:00
</div>
</div>
</template>
<script setup lang="ts">
2022-03-03 11:01:52 +08:00
import { ref, watch, computed, reactive } from 'vue'
2022-01-14 22:07:02 +08:00
import { ConfigType } from '@/packages/index.d'
2022-01-15 14:56:48 +08:00
import { useSettingStore } from '@/store/modules/settingStore/settingStore'
2022-02-25 21:45:14 +08:00
import { loadAsyncComponent } from '@/utils'
2023-05-23 20:55:24 +08:00
import { usePackagesStore } from '@/store/modules/packagesStore/packagesStore'
import { PackagesCategoryEnum } from '@/packages/index.d'
2022-02-25 21:45:14 +08:00
const ChartsItemBox = loadAsyncComponent(() => import('../ChartsItemBox/index.vue'))
2023-05-23 20:55:24 +08:00
const packagesStore = usePackagesStore()
2022-01-14 22:07:02 +08:00
const props = defineProps({
selectOptions: {
type: Object,
default: () => {}
2022-01-14 22:07:02 +08:00
}
})
2022-01-15 14:56:48 +08:00
// 隐藏设置
const settingStore = useSettingStore()
const hidePackageOneCategory = computed(() => {
2022-01-15 21:05:11 +08:00
if (packages.categorysNum > 2) return true
2022-01-15 14:56:48 +08:00
return !settingStore.getHidePackageOneCategory
})
2022-01-14 22:07:02 +08:00
let packages = reactive<{
[T: string]: any
}>({
// 侧边栏
menuOptions: [],
// 当前选择
selectOptions: {},
// 分类归档
2022-01-15 21:05:11 +08:00
categorys: {
all: []
},
categoryNames: {
all: '所有'
2022-01-15 21:05:11 +08:00
},
2022-01-14 22:18:47 +08:00
// 分类归档数量
categorysNum: 0,
2022-01-14 22:07:02 +08:00
// 存储不同类别组件进来的选中值
saveSelectOptions: {}
})
2023-05-23 20:55:24 +08:00
const selectValue = ref<string>('all')
2022-01-14 22:07:02 +08:00
// 设置初始列表
const setSelectOptions = (categorys: any) => {
for (const val in categorys) {
packages.selectOptions = categorys[val]
break
}
}
watch(
// @ts-ignore
() => props.selectOptions,
(newData: { list: ConfigType[] }) => {
2022-01-14 22:18:47 +08:00
packages.categorysNum = 0
2022-01-14 22:07:02 +08:00
if (!newData) return
newData.list.forEach((e: ConfigType) => {
const value: ConfigType[] = (packages.categorys as any)[e.category]
packages.categorys[e.category] = value && value.length ? [...value, e] : [e]
packages.categoryNames[e.category] = e.categoryName
packages.categorys['all'].push(e)
2022-01-14 22:07:02 +08:00
})
for (const val in packages.categorys) {
2022-01-14 22:18:47 +08:00
packages.categorysNum += 1
2022-01-14 22:07:02 +08:00
packages.menuOptions.push({
key: val,
label: packages.categoryNames[val]
2022-01-14 22:07:02 +08:00
})
}
setSelectOptions(packages.categorys)
// 默认选中处理
2022-01-14 22:07:02 +08:00
selectValue.value = packages.menuOptions[0]['key']
},
{
immediate: true
}
)
2023-05-23 20:55:24 +08:00
watch(
() => packagesStore.newPhoto,
newPhoto => {
if (!newPhoto) return
const newPhotoCategory = newPhoto.category
packages.categorys[newPhotoCategory].splice(1, 0, newPhoto)
packages.categorys['all'].splice(1, 0, newPhoto)
}
)
2022-01-14 22:07:02 +08:00
// 处理点击事件
const clickItemHandle = (key: string) => {
packages.selectOptions = packages.categorys[key]
}
</script>
<style lang="scss" scoped>
/* 此高度与 ContentBox 组件关联*/
2022-01-28 21:05:07 +08:00
$topHeight: 40px;
2022-01-14 22:07:02 +08:00
$menuWidth: 65px;
@include go('chart-common') {
2022-01-14 22:07:02 +08:00
display: flex;
height: calc(100vh - #{$--header-height} - #{$topHeight});
.chart-menu-width {
width: $menuWidth;
flex-shrink: 0;
2022-05-02 17:18:18 +08:00
@include fetch-bg-color('background-color2-shallow');
2022-01-14 22:07:02 +08:00
}
.chart-content-list {
width: 200px;
2022-01-14 22:07:02 +08:00
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
}
@include deep() {
.n-menu-item {
height: 30px;
&.n-menu-item--selected {
&::before {
background-color: rgba(0, 0, 0, 0);
}
}
.n-menu-item-content {
text-align: center;
padding: 0px 14px !important;
font-size: 12px !important;
}
}
}
}
</style>