index.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. const { setItem } = useChartLayoutStore()
  30. const { getLayers, getCharts, getDetails } = toRefs(useChartLayoutStore())
  31. type ItemType = {
  32. key: string
  33. select: Ref<boolean> | boolean
  34. title: string
  35. icon: any
  36. }
  37. const btnList = reactive<ItemType[]>([
  38. {
  39. key: ChartLayoutStoreEnum.CHARTS,
  40. select: getCharts,
  41. title: '图表组件',
  42. icon: renderIcon(BarChartIcon)
  43. },
  44. {
  45. key: ChartLayoutStoreEnum.LAYERS,
  46. select: getLayers,
  47. title: '图层控制',
  48. icon: renderIcon(LayersIcon)
  49. },
  50. {
  51. key: ChartLayoutStoreEnum.DETAILS,
  52. select: getDetails,
  53. title: '详情设置',
  54. icon: renderIcon(PrismIcon)
  55. }
  56. ])
  57. // store 描述的是展示的值,所以和 ContentDetails 的 collapsed 是相反的
  58. const styleHandle = (item: ItemType) => {
  59. if (item.key === ChartLayoutStoreEnum.DETAILS) {
  60. return item.select ? '' : 'success'
  61. }
  62. return item.select ? 'success' : ''
  63. }
  64. const clickHandle = (item: ItemType) => {
  65. setItem(item.key, !item.select)
  66. }
  67. const goHomeHandle = () => {
  68. goDialog({
  69. message: '返回将不会保存任何操作',
  70. isMaskClosable: true,
  71. onPositiveCallback: goHome
  72. })
  73. }
  74. </script>
  75. <style lang="scss" scoped>
  76. .header-left-btn {
  77. margin-left: -37px;
  78. padding-right: 149px;
  79. }
  80. </style>