index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div v-if="custom.showViewSetting && currentModel === fuseModel && !params.pure">
  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. custom,
  28. params,
  29. showMeasuresStack,
  30. showMonitorsStack,
  31. showPathsStack,
  32. showTaggingsStack,
  33. } from "@/env";
  34. import { DownOutlined } from "@ant-design/icons-vue";
  35. import { computed, watch, watchEffect } from "vue";
  36. import { selectPaths } from "@/store";
  37. import { currentModel, fuseModel } from "@/model";
  38. const props = defineProps<{ value?: Record<string, boolean> }>();
  39. const emit = defineEmits<{ (e: "update:value", v: Record<string, boolean>): void }>();
  40. const showOptions = [
  41. { key: "showTagging", text: "标签", stack: showTaggingsStack.current.value },
  42. { key: "showMeasure", text: "测量", stack: showMeasuresStack.current.value },
  43. {
  44. key: "showPath",
  45. text: "路径",
  46. stack: computed({
  47. get: () => {
  48. return selectPaths.all.value || selectPaths.selects.value.length > 0;
  49. },
  50. set: (val: boolean) => {
  51. selectPaths.all.value = val;
  52. console.log(selectPaths.selects.value);
  53. },
  54. }),
  55. },
  56. ];
  57. watch(
  58. () => props.value,
  59. () => {
  60. if (!props.value) return;
  61. showOptions.forEach((item) => {
  62. item.stack.value = props.value![item.key];
  63. });
  64. },
  65. { immediate: true }
  66. );
  67. watchEffect(() => {
  68. emit(
  69. "update:value",
  70. Object.fromEntries(showOptions.map((item) => [item.key, item.stack.value] as const))
  71. );
  72. });
  73. </script>
  74. <style lang="scss" scoped>
  75. .show-setting {
  76. width: 160px;
  77. height: 34px;
  78. background: rgba(27, 27, 28, 0.9);
  79. border-radius: 4px;
  80. display: flex;
  81. padding: 8px;
  82. align-items: center;
  83. justify-content: space-between;
  84. }
  85. </style>