index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <!-- 侧边栏和数据分发处理 -->
  3. <div class="go-chart-common">
  4. <n-menu
  5. v-show="hidePackageOneCategory"
  6. class="chart-menu-width"
  7. v-model:value="selectValue"
  8. :options="packages.menuOptions"
  9. :icon-size="16"
  10. :indent="18"
  11. @update:value="clickItemHandle"
  12. />
  13. <div class="chart-content-list">
  14. <n-scrollbar>
  15. <ItemBox :menuOptions="packages.selectOptions" />
  16. </n-scrollbar>
  17. </div>
  18. </div>
  19. </template>
  20. <script setup lang="ts">
  21. import { ref, watch, reactive, computed } from 'vue'
  22. import { ItemBox } from '../ItemBox/index'
  23. import { ConfigType } from '@/packages/index.d'
  24. import { useSettingStore } from '@/store/modules/settingStore/settingStore'
  25. const props = defineProps({
  26. selectOptions: {
  27. type: Object,
  28. default: () => []
  29. }
  30. })
  31. // 隐藏设置
  32. const settingStore = useSettingStore()
  33. const hidePackageOneCategory = computed(() => {
  34. if (packages.categorysNum > 2) return true
  35. return !settingStore.getHidePackageOneCategory
  36. })
  37. // TODO 调试结束改成 markeRaw
  38. let packages = reactive<{
  39. [T: string]: any
  40. }>({
  41. // 侧边栏
  42. menuOptions: [],
  43. // 当前选择
  44. selectOptions: {},
  45. // 分类归档
  46. categorys: {
  47. // todo 先用中文, 后面需要换成关键key
  48. all: []
  49. },
  50. categoryNames: {
  51. all: '所有'
  52. },
  53. // 分类归档数量
  54. categorysNum: 0,
  55. // 存储不同类别组件进来的选中值
  56. saveSelectOptions: {}
  57. })
  58. const selectValue = ref<string>()
  59. // 设置初始列表
  60. const setSelectOptions = (categorys: any) => {
  61. for (const val in categorys) {
  62. packages.selectOptions = categorys[val]
  63. break
  64. }
  65. }
  66. watch(
  67. // @ts-ignore
  68. () => props.selectOptions,
  69. (newData: { list: ConfigType[] }) => {
  70. packages.categorysNum = 0
  71. if (!newData) return
  72. newData.list.forEach((e: ConfigType) => {
  73. const value: ConfigType[] = (packages.categorys as any)[e.category]
  74. // @ts-ignore
  75. packages.categorys[e.category] = value && value.length ? [...value, e] : [e]
  76. packages.categoryNames[e.category] = e.categoryName
  77. packages.categorys['all'].push(e)
  78. })
  79. for (const val in packages.categorys) {
  80. packages.categorysNum += 1
  81. packages.menuOptions.push({
  82. key: val,
  83. label: packages.categoryNames[val]
  84. })
  85. }
  86. setSelectOptions(packages.categorys)
  87. // 默认选中处理
  88. selectValue.value = packages.menuOptions[0]['key']
  89. },
  90. {
  91. deep: true,
  92. immediate: true
  93. }
  94. )
  95. // 处理点击事件
  96. const clickItemHandle = (key: string) => {
  97. packages.selectOptions = packages.categorys[key]
  98. }
  99. </script>
  100. <style lang="scss" scoped>
  101. /* 此高度与 ContentBox 组件关联*/
  102. $topHeight: 40px;
  103. $menuWidth: 65px;
  104. @include go('chart-common') {
  105. display: flex;
  106. height: calc(100vh - #{$--header-height} - #{$topHeight});
  107. .chart-menu-width {
  108. width: $menuWidth;
  109. flex-shrink: 0;
  110. @include filter-bg-color('background-color2-shallow');
  111. }
  112. .chart-content-list {
  113. flex: 1;
  114. display: flex;
  115. flex-direction: column;
  116. align-items: center;
  117. padding: 10px 0;
  118. }
  119. @include deep() {
  120. .n-menu-item {
  121. height: 30px;
  122. &.n-menu-item--selected {
  123. &::before {
  124. background-color: rgba(0, 0, 0, 0);
  125. }
  126. }
  127. .n-menu-item-content {
  128. text-align: center;
  129. padding: 0px 14px !important;
  130. font-size: 12px !important;
  131. }
  132. }
  133. }
  134. }
  135. </style>