select-back.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div class="back-layout">
  3. <template v-for="back in backs" :key="back.value">
  4. <div v-if="back.children" class="child-layout-parent">
  5. <Dropdown placement="bottom">
  6. <div class="child-layout" :class="{ active: activeParent === back.value }">
  7. <ui-icon type="rectification" />
  8. <BackItem
  9. :type="back.type"
  10. :label="back.label"
  11. :url="back.image"
  12. :active="activeParent === back.value"
  13. @click="value !== back.value && $emit('update:value', back.value)"
  14. />
  15. </div>
  16. <template #overlay>
  17. <Menu :selectedKeys="[value]">
  18. <MenuItem
  19. v-for="item in back.children"
  20. @click="value !== item.value && $emit('update:value', item.value)"
  21. :key="item.value"
  22. >
  23. {{ item.label }}
  24. </MenuItem>
  25. </Menu>
  26. </template>
  27. </Dropdown>
  28. </div>
  29. <BackItem
  30. v-else
  31. :type="back.type"
  32. :label="back.label"
  33. :url="back.image"
  34. :active="value === back.value"
  35. @click="value !== back.value && $emit('update:value', back.value)"
  36. />
  37. </template>
  38. </div>
  39. </template>
  40. <script lang="ts" setup>
  41. import { Dropdown, MenuItem, Menu } from "ant-design-vue";
  42. import { computed, ref } from "vue";
  43. import BackItem from "./back-item.vue";
  44. const props = defineProps<{ value: string | undefined }>();
  45. defineEmits<{ (e: "update:value", value: string): void }>();
  46. const backs = ref([
  47. { label: "无", type: "icon", image: "icon-without", value: "none" },
  48. {
  49. label: "地图",
  50. type: "map",
  51. image: "/oss/fusion/default/images/map.png",
  52. value: "dt",
  53. children: [
  54. { label: "天地图", value: "map" },
  55. { label: "高德地图", value: "gdMap" },
  56. { label: "谷歌地图", value: "gMap" },
  57. ],
  58. },
  59. {
  60. label: "蓝天白云",
  61. type: "img",
  62. image: "/oss/fusion/default/images/pic_ltby@2x.png",
  63. value: "/oss/fusion/default/images/蓝天白云.jpg",
  64. },
  65. {
  66. label: "乌云密布",
  67. type: "img",
  68. image: "/oss/fusion/default/images/pic_wymb@2x.png",
  69. value: "/oss/fusion/default/images/乌云密布.jpg",
  70. },
  71. {
  72. label: "夜空",
  73. type: "img",
  74. image: "/oss/fusion/default/images/pic_yk@2x.png",
  75. value: "/oss/fusion/default/images/夜空.jpg",
  76. },
  77. {
  78. label: "傍晚",
  79. type: "img",
  80. image: "/oss/fusion/default/images/pic_bw@2x.png",
  81. value: "/oss/fusion/default/images/傍晚.jpg",
  82. },
  83. ]);
  84. const activeParent = computed(() => {
  85. for (const back of backs.value) {
  86. if (back.value === props.value) {
  87. return back.value;
  88. } else if (back.children) {
  89. for (const c of back.children) {
  90. if (c.value === props.value) {
  91. return back.value;
  92. }
  93. }
  94. }
  95. }
  96. });
  97. </script>
  98. <style lang="scss" scoped>
  99. .back-layout {
  100. display: grid;
  101. grid-template-columns: repeat(3, 1fr);
  102. gap: 20px;
  103. }
  104. .child-layout-parent {
  105. position: relative;
  106. }
  107. .child-layout {
  108. position: absolute;
  109. top: 0;
  110. left: 0;
  111. height: 88px;
  112. > .icon {
  113. position: absolute;
  114. font-size: 22px;
  115. left: 50%;
  116. top: 50%;
  117. transform: translate(-50%, -50%);
  118. z-index: 2;
  119. }
  120. &::after {
  121. content: "";
  122. position: absolute;
  123. z-index: 1;
  124. background: rgba(0, 0, 0, 0.5);
  125. inset: 0;
  126. border-radius: 4px;
  127. cursor: pointer;
  128. }
  129. &.active::after {
  130. inset: -2px;
  131. }
  132. }
  133. </style>