imageLabel.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <div class="graphic-child-menus">
  3. <div class="header">
  4. <ui-icon type="return" class="icon" ctrl @click="$emit('quit')" />
  5. <p>{{ config.title }}</p>
  6. </div>
  7. <ui-input type="text" width="100%" v-model="keyword">
  8. <template v-slot:preIcon>
  9. <ui-icon type="magnify_g" color="rgba(255,255,255,0.6)" />
  10. </template>
  11. </ui-input>
  12. <template v-if="typeMenus.length">
  13. <div v-for="typeMenu in typeMenus" :key="typeMenu.title" class="type-menu">
  14. <h2
  15. @click="showTypeMenu = showTypeMenu?.title === typeMenu.title ? null : typeMenu"
  16. >
  17. {{ typeMenu.title }}
  18. <ui-icon :type="showTypeMenu?.title === typeMenu.title ? 'fold' : 'unfold'" />
  19. </h2>
  20. <div class="menu-list" v-show="showTypeMenu?.title === typeMenu.title">
  21. <div
  22. v-for="menu in typeMenu.children"
  23. :key="menu.key"
  24. class="menu"
  25. :class="{ active: uiType.current === menu.key }"
  26. @click="clickHandler(menu.key)"
  27. >
  28. <ui-icon :type="menu.icon" class="icon" />
  29. <p>{{ menu.text }}</p>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <div v-else class="empty-images">
  35. <div>
  36. <img src="@/assets/images/empty-label.png" />
  37. <p>无结果</p>
  38. </div>
  39. </div>
  40. </div>
  41. </template>
  42. <script setup lang="ts">
  43. import UiIcon from "@/components/base/components/icon/index.vue";
  44. import { uiType } from "@/hook/useGraphic";
  45. import icons, {
  46. imageTypeKeys,
  47. structureTypeKeys,
  48. } from "@/graphic/CanvasStyle/ImageLabels/SVGIcons";
  49. import { computed, ref, watch } from "vue";
  50. import UiInput from "@/components/base/components/input/index.vue";
  51. import { uses } from "@/store/SVGLabel";
  52. import { UITypeExtend } from "./menus";
  53. const props = defineProps<{ type: string }>();
  54. const config = computed(() =>
  55. props.type === UITypeExtend.image
  56. ? { title: "图例", data: imageTypeKeys, enableUse: true }
  57. : { title: "道路结构", data: structureTypeKeys, enableUse: false }
  58. );
  59. const typeMenusRaw = computed(() =>
  60. config.value.data.map(({ type, children }) => ({
  61. title: type,
  62. children: children.map((key) => ({
  63. key: key,
  64. text: icons[key].text,
  65. icon: key.substring(0, key.lastIndexOf(".")),
  66. })),
  67. }))
  68. );
  69. const keyword = ref("");
  70. const typeMenus = computed(() => {
  71. const raws = typeMenusRaw.value.map((typeMenu) => ({
  72. ...typeMenu,
  73. children: typeMenu.children
  74. .filter((item) => item.text.includes(keyword.value))
  75. .sort((a, b) => a.icon.localeCompare(b.icon)),
  76. }));
  77. const items =
  78. keyword.value || !config.value.enableUse
  79. ? raws
  80. : [
  81. {
  82. title: "常用",
  83. children: uses.value
  84. .sort((item1, item2) => (item2.count || 0) - (item1.count || 0))
  85. .slice(0, 10)
  86. .map((item) => {
  87. for (let menu of typeMenusRaw.value) {
  88. const findItem = menu.children.find(
  89. (menuItem) => menuItem.key === item.key
  90. );
  91. if (findItem) {
  92. return findItem;
  93. }
  94. }
  95. })
  96. .filter((item) => !!item),
  97. },
  98. ...raws,
  99. ];
  100. return items.filter((item) => item.children.length);
  101. });
  102. const showTypeMenu = ref();
  103. watch(typeMenus, () => (showTypeMenu.value = typeMenus.value[0]), { immediate: true });
  104. const clickHandler = (key) => {
  105. if (config.value.enableUse) {
  106. const findUse = uses.value.find((use) => use.key === key);
  107. const lastUpdateTime = new Date().getTime();
  108. if (findUse) {
  109. findUse.count++;
  110. findUse.lastUpdateTime = lastUpdateTime;
  111. } else {
  112. uses.value.push({ key, count: 1, lastUpdateTime });
  113. }
  114. }
  115. uiType.change(key as any);
  116. };
  117. defineEmits<{ (e: "quit") }>();
  118. </script>
  119. <style lang="scss" scoped>
  120. .graphic-child-menus {
  121. background-color: var(--editor-menu-back);
  122. position: absolute;
  123. top: calc(var(--editor-head-height) + var(--header-top));
  124. bottom: 0;
  125. left: calc(var(--editor-menu-left) + var(--editor-menu-width));
  126. padding: 16px;
  127. overflow-y: auto;
  128. width: 304px;
  129. .menu-list {
  130. display: grid;
  131. grid-template-columns: repeat(3, 80px);
  132. grid-gap: 16px;
  133. padding-bottom: 16px;
  134. }
  135. }
  136. .menu {
  137. display: flex;
  138. flex-direction: column;
  139. cursor: pointer;
  140. height: 100px;
  141. transition: color 0.3s ease;
  142. //&:hover,
  143. &.active {
  144. color: var(--colors-primary-base);
  145. }
  146. &.active {
  147. background-color: rgba(255, 255, 255, 0.06);
  148. }
  149. .icon {
  150. display: flex;
  151. align-items: center;
  152. justify-content: center;
  153. flex: 1;
  154. font-size: 40px;
  155. text-align: center;
  156. background: #383838;
  157. }
  158. p {
  159. padding: 4px;
  160. font-size: 12px;
  161. text-align: center;
  162. }
  163. }
  164. .header {
  165. margin-bottom: 10px;
  166. padding: 5px 0;
  167. text-align: center;
  168. font-size: 16px;
  169. position: relative;
  170. .icon {
  171. position: absolute;
  172. top: 50%;
  173. transform: translateY(-50%);
  174. left: 0;
  175. }
  176. }
  177. .type-menu {
  178. margin-top: 21px;
  179. h2 {
  180. margin: 16px 0;
  181. font-size: 16px;
  182. font-weight: bold;
  183. color: rgba(255, 255, 255, 0.6);
  184. display: flex;
  185. align-items: center;
  186. justify-content: space-between;
  187. .icon {
  188. font-size: 16px;
  189. }
  190. }
  191. border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  192. }
  193. .empty-images {
  194. display: flex;
  195. align-items: center;
  196. justify-content: center;
  197. text-align: center;
  198. height: calc(100% - 80px);
  199. div img {
  200. display: block;
  201. width: 128px;
  202. }
  203. div p {
  204. margin-top: 10px;
  205. color: rgba(255, 255, 255, 1);
  206. }
  207. }
  208. </style>