index.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <n-space class="header-left-btn" :size="25">
  3. <n-button size="small" quaternary @click="goHomeHandle()">
  4. <template #icon>
  5. <n-icon :depth="3">
  6. <HomeIcon />
  7. </n-icon>
  8. </template>
  9. </n-button>
  10. <n-space>
  11. <n-tooltip v-for="item in btnList" :key="item.key" placement="bottom" trigger="hover">
  12. <template #trigger>
  13. <n-button :type="styleHandle(item)" size="small" ghost @click="clickHandle(item)">
  14. <component :is="item.icon"></component>
  15. </n-button>
  16. </template>
  17. <span>{{ item.title }}</span>
  18. </n-tooltip>
  19. </n-space>
  20. </n-space>
  21. </template>
  22. <script setup lang="ts">
  23. import { toRefs, Ref, reactive } from 'vue'
  24. import { renderIcon, goDialog, goHome } from '@/utils'
  25. import { icon } from '@/plugins'
  26. const { LayersIcon, BarChartIcon, PrismIcon, HomeIcon } = icon.ionicons5
  27. import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore'
  28. import { ChartLayoutStoreEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d'
  29. import { useRemoveKeyboard } from '../hooks/useKeyboard.hook'
  30. const { setItem } = useChartLayoutStore()
  31. const { getLayers, getCharts, getDetails } = toRefs(useChartLayoutStore())
  32. type ItemType = {
  33. key: string
  34. select: Ref<boolean> | boolean
  35. title: string
  36. icon: any
  37. }
  38. const btnList = reactive<ItemType[]>([
  39. {
  40. key: ChartLayoutStoreEnum.CHARTS,
  41. select: getCharts,
  42. title: '图表组件',
  43. icon: renderIcon(BarChartIcon)
  44. },
  45. {
  46. key: ChartLayoutStoreEnum.LAYERS,
  47. select: getLayers,
  48. title: '图层控制',
  49. icon: renderIcon(LayersIcon)
  50. },
  51. {
  52. key: ChartLayoutStoreEnum.DETAILS,
  53. select: getDetails,
  54. title: '详情设置',
  55. icon: renderIcon(PrismIcon)
  56. }
  57. ])
  58. // store 描述的是展示的值,所以和 ContentConfigurations 的 collapsed 是相反的
  59. const styleHandle = (item: ItemType) => {
  60. if (item.key === ChartLayoutStoreEnum.DETAILS) {
  61. return item.select ? '' : 'success'
  62. }
  63. return item.select ? 'success' : ''
  64. }
  65. const clickHandle = (item: ItemType) => {
  66. setItem(item.key, !item.select)
  67. }
  68. const goHomeHandle = () => {
  69. goDialog({
  70. message: '返回将不会保存任何操作',
  71. isMaskClosable: true,
  72. onPositiveCallback: () => {
  73. goHome()
  74. useRemoveKeyboard()
  75. }
  76. })
  77. }
  78. </script>
  79. <style lang="scss" scoped>
  80. .header-left-btn {
  81. margin-left: -37px;
  82. padding-right: 149px;
  83. }
  84. </style>