index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <div>
  3. <Dropdown placement="top">
  4. <div class="strengthen show-setting">
  5. <span>显示设置</span>
  6. <DownOutlined />
  7. </div>
  8. <template #overlay>
  9. <Menu>
  10. <menu-item v-for="option in showOptions">
  11. <ui-input
  12. @click.stop
  13. type="checkbox"
  14. :modelValue="option.stack.value"
  15. @update:modelValue="(s: boolean) => option.stack.value = s"
  16. :label="option.text"
  17. />
  18. </menu-item>
  19. </Menu>
  20. </template>
  21. </Dropdown>
  22. </div>
  23. </template>
  24. <script setup lang="ts">
  25. import { Dropdown, Menu, MenuItem } from "ant-design-vue";
  26. import {
  27. showMeasuresStack,
  28. showMonitorsStack,
  29. showPathsStack,
  30. showTaggingsStack,
  31. } from "@/env";
  32. import { DownOutlined } from "@ant-design/icons-vue";
  33. import { computed, watch, watchEffect } from "vue";
  34. import { selectPaths } from "@/store";
  35. const props = defineProps<{ value?: Record<string, boolean> }>();
  36. const emit = defineEmits<{ (e: "update:value", v: Record<string, boolean>): void }>();
  37. const showOptions = [
  38. { key: "showTagging", text: "标签", stack: showTaggingsStack.current.value },
  39. { key: "showMeasure", text: "测量", stack: showMeasuresStack.current.value },
  40. {
  41. key: "showPath",
  42. text: "路径",
  43. stack: computed({
  44. get: () => {
  45. return selectPaths.all.value || selectPaths.selects.value.length > 0;
  46. },
  47. set: (val: boolean) => {
  48. selectPaths.all.value = val;
  49. console.log(selectPaths.selects.value);
  50. },
  51. }),
  52. },
  53. ];
  54. watch(
  55. () => props.value,
  56. () => {
  57. if (!props.value) return;
  58. showOptions.forEach((item) => {
  59. item.stack.value = props.value![item.key];
  60. });
  61. },
  62. { immediate: true }
  63. );
  64. watchEffect(() => {
  65. emit(
  66. "update:value",
  67. Object.fromEntries(showOptions.map((item) => [item.key, item.stack.value] as const))
  68. );
  69. });
  70. </script>
  71. <style lang="scss" scoped>
  72. .show-setting {
  73. width: 160px;
  74. height: 34px;
  75. background: rgba(27, 27, 28, 0.9);
  76. border-radius: 4px;
  77. display: flex;
  78. padding: 8px;
  79. align-items: center;
  80. justify-content: space-between;
  81. }
  82. </style>