aside.vue 6.8 KB

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