aside.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <template>
  2. <div class="aside">
  3. <div class="vtitle">
  4. {{ currentId === "museum" ? "博物馆列表" : "虚拟场景列表" }}
  5. </div>
  6. <ul class="select">
  7. <li
  8. @click="onClickSelect({ id: 'museum' })"
  9. :class="{ active: currentId == 'museum' }"
  10. >
  11. <span></span>
  12. <span>博物馆</span>
  13. </li>
  14. <li
  15. @click="onClickSelect({ id: 'scene' })"
  16. :class="{ active: currentId == 'scene' }"
  17. >
  18. <span></span>
  19. <span>虚拟场景</span>
  20. </li>
  21. </ul>
  22. <div class="list">
  23. <p class="gd" @click="router.push({ name: 'gdmuseum' })">广东省博物馆</p>
  24. <section>
  25. <ul v-if="list.length > 0">
  26. <li v-for="(sub, idx) in list" :key="idx">
  27. <p :id="'aside-list-sidebar-' + sub.type">{{ sub.type }}</p>
  28. <ul v-if="sub.arr.length > 0">
  29. <li
  30. @click="onClickItem(son)"
  31. v-for="(son, sonidx) in sub.arr"
  32. :key="sonidx"
  33. >
  34. {{ son.name }}
  35. </li>
  36. </ul>
  37. </li>
  38. </ul>
  39. <div v-else class="searchNone">暂无数据</div>
  40. </section>
  41. <div class="sidebar">
  42. <ul>
  43. <li
  44. v-for="(item, i) in charStrs"
  45. :key="i"
  46. @click="onClickSidebarItem(item)"
  47. >
  48. {{ item }}
  49. </li>
  50. </ul>
  51. </div>
  52. <div class="sanjiao"></div>
  53. </div>
  54. <div class="search">
  55. <input
  56. @keydown.enter="search"
  57. v-model="searchkey"
  58. type="text"
  59. placeholder="请输入关键字查询"
  60. />
  61. <img
  62. @click="search"
  63. :src="require('@/assets/images/icon/search_red.png')"
  64. alt=""
  65. />
  66. </div>
  67. </div>
  68. </template>
  69. <script setup>
  70. import { ref, onMounted, computed, watch, nextTick } from "vue";
  71. import { getMuseumList, getExhibitionList } from "@/config/api";
  72. import { defineExpose } from "vue";
  73. import { useRouter, useRoute } from "vue-router";
  74. const router = useRouter();
  75. const route = useRoute();
  76. const isShow = ref(false);
  77. const currentId = ref("museum");
  78. const charStrs = ref("");
  79. const list = ref([]);
  80. const emit = defineEmits(["changeMap"]);
  81. const onClickSelect = (data) => {
  82. emit("changeMap", data.id);
  83. isShow.value = true;
  84. currentId.value = data.id;
  85. };
  86. const onClickSidebarItem = (item) => {
  87. const targetNode = document.getElementById("aside-list-sidebar-" + item);
  88. if (targetNode) {
  89. targetNode.scrollIntoView();
  90. }
  91. };
  92. const searchkey = ref("");
  93. const onClickItem = (data) => {
  94. if (currentId.value == "museum") {
  95. router.push({ name: "exhibition", query: { id: data.id } });
  96. } else {
  97. router.push({ name: "zhanlan", params: { id: data.id } });
  98. }
  99. };
  100. const getList = (cityId = "") => {
  101. let getData = currentId.value == "museum" ? getMuseumList : getExhibitionList;
  102. list.value = [];
  103. getData(
  104. {
  105. cityId: cityId,
  106. pageNum: 1,
  107. pageSize: 1000,
  108. searchKey: searchkey.value,
  109. },
  110. (data) => {
  111. data.data.records.forEach((item) => {
  112. let ele = list.value.findIndex(
  113. (sub) => sub.type == item.initial.toUpperCase()
  114. );
  115. if (ele < 0) {
  116. list.value.push({
  117. type: item.initial.toUpperCase(),
  118. arr: [{ ...item }],
  119. });
  120. } else {
  121. list.value[ele].arr.push({ ...item });
  122. }
  123. });
  124. list.value = list.value.sort((a, b) => {
  125. if (a.type < b.type) {
  126. return -1;
  127. }
  128. if (a.type > b.type) {
  129. return 1;
  130. }
  131. return 0;
  132. });
  133. charStrs.value = list.value.map((item) => item.type);
  134. }
  135. );
  136. };
  137. defineExpose({
  138. getList,
  139. });
  140. const search = () => {
  141. getList();
  142. };
  143. watch(currentId, () => {
  144. getList();
  145. });
  146. onMounted(() => {
  147. getList();
  148. });
  149. </script>
  150. <style lang="scss" scoped>
  151. .aside {
  152. width: 300px;
  153. height: 90%;
  154. background: var(--main-color);
  155. border-radius: 8px;
  156. padding: 18px;
  157. text-align: center;
  158. .vtitle {
  159. color: var(--font-active);
  160. font-size: 24px;
  161. font-weight: bold;
  162. }
  163. .select {
  164. width: 100%;
  165. display: flex;
  166. margin: 20px 0;
  167. > li {
  168. display: flex;
  169. align-items: center;
  170. margin-right: 30px;
  171. cursor: pointer;
  172. > span {
  173. margin-right: 6px;
  174. display: inline-block;
  175. &:first-of-type {
  176. width: 20px;
  177. height: 20px;
  178. position: relative;
  179. border-radius: 50%;
  180. background: #fff;
  181. }
  182. }
  183. &.active {
  184. > span {
  185. &:first-of-type {
  186. &::before {
  187. content: "";
  188. position: absolute;
  189. width: 10px;
  190. height: 10px;
  191. background: var(--font-active);
  192. border-radius: 50%;
  193. top: 50%;
  194. left: 50%;
  195. transform: translate(-50%, -50%);
  196. }
  197. }
  198. }
  199. }
  200. }
  201. }
  202. .list {
  203. background-color: #fffef6;
  204. border-radius: 5px;
  205. height: calc(100% - 150px);
  206. color: #333333;
  207. text-align: left;
  208. position: relative;
  209. padding: 18px 10px;
  210. .gd {
  211. color: var(--main-color);
  212. font-size: 16px;
  213. font-weight: bold;
  214. padding-left: 16px;
  215. cursor: pointer;
  216. position: relative;
  217. &::before {
  218. content: "";
  219. position: absolute;
  220. left: 0;
  221. top: 50%;
  222. transform: translateY(-50%);
  223. display: inline-block;
  224. width: 10px;
  225. height: 10px;
  226. background: var(--main-color);
  227. border-radius: 50%;
  228. }
  229. }
  230. > section {
  231. height: 95%;
  232. overflow-y: auto;
  233. &::-webkit-scrollbar {
  234. display: none;
  235. } /*宽度是对垂直滚动条而言,高度是对水平滚动条而言*/
  236. > ul {
  237. padding-left: 16px;
  238. > li {
  239. margin: 14px 0;
  240. cursor: pointer;
  241. > p {
  242. font-weight: bold;
  243. }
  244. > ul {
  245. > li {
  246. color: #999999;
  247. margin: 10px 0;
  248. }
  249. }
  250. }
  251. }
  252. .searchNone {
  253. color: #999999;
  254. width: 100%;
  255. height: 100%;
  256. display: flex;
  257. justify-content: center;
  258. align-items: center;
  259. }
  260. }
  261. .sidebar {
  262. width: 20px;
  263. height: 94%;
  264. background: #f3f2e8;
  265. border-radius: 50px;
  266. position: absolute;
  267. right: 10px;
  268. top: 18px;
  269. > ul {
  270. text-align: center;
  271. display: flex;
  272. flex-direction: column;
  273. justify-content: space-around;
  274. align-items: center;
  275. height: 100%;
  276. > li {
  277. color: #999999;
  278. font-size: 12px;
  279. cursor: pointer;
  280. }
  281. }
  282. }
  283. .sanjiao {
  284. position: absolute;
  285. left: 50%;
  286. transform: translateX(-50%);
  287. bottom: 2px;
  288. border: 10px solid transparent;
  289. border-top-color: var(--main-color);
  290. }
  291. }
  292. .search {
  293. width: 100%;
  294. height: 40px;
  295. background: #fffef6;
  296. border-radius: 8px;
  297. margin-top: 16px;
  298. position: relative;
  299. > input {
  300. line-height: 40px;
  301. text-align: left;
  302. width: 100%;
  303. padding: 0 40px 0 10px;
  304. }
  305. > img {
  306. cursor: pointer;
  307. position: absolute;
  308. right: 10px;
  309. top: 50%;
  310. transform: translateY(-50%);
  311. width: 20px;
  312. }
  313. }
  314. }
  315. </style>