imageLabel.vue 5.5 KB

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