aside.vue 6.5 KB

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