Browse Source

feat:首页导航带参数跳转到游记列表

qiao 3 months ago
parent
commit
3a4adf35e0
2 changed files with 39 additions and 7 deletions
  1. 30 7
      src/pages/travel-notes/index.vue
  2. 9 0
      src/pages/yj/[id].vue

+ 30 - 7
src/pages/travel-notes/index.vue

@@ -48,8 +48,11 @@
 </template>
 
 <script setup>
+const router = useRoute()
 const AREA_TEXT = '地域'
 
+const areaId = useRouteParam("area")
+
 const filterList = ref([])//地域列表
 
 const curFilter = ref({})//当前筛选条件(国家)
@@ -66,19 +69,37 @@ const dropDownMenuRef = ref(null)
 // 获取筛选列表
 async function getFilters() {
   const { data } = await request(`website/tourism/projectTravelNotes/travelNotesDirectoryList`).finally(()=>{closeToast()})
-  if (!Array.isArray(data)) return
+  
+  if (!Array.isArray(data)) return getList()
+  const routerAreaId = null
   data.map((item, index) => {
     data[index].id = item.areaId
     data[index].text = item.areaName
+
+    // 处理地址栏带area参数的情况
+    if(router.query.area == item.areaId){
+      curFilter.value.areaId = router.query.area
+      document.title = item.areaName
+      areaIndex.value = index + 1
+      curFilter.value.id = item.areaId+',all'
+      areaFilterTitle.value = item.areaName
+    }
+
     if (Array.isArray(item.children)) {
+      data[index].children.unshift({countryName:'全部',countryId:item.areaId+',all'})
       item.children.map((item2, index2) => {
         data[index].children[index2].id = item2.countryId
         data[index].children[index2].text = item2.countryName
         data[index].children[index2].areaId = item.areaId
+        data[index].children[index2].areaName = item.areaName
       })
     }
   })
+  if(routerAreaId){
+
+  }
   filterList.value = [{ id: 0, text: '全部', children: [{ id: 0, text: '全部' }] }, ...data]
+  getList()
 }
 
 // 监听地域筛选框收起
@@ -114,10 +135,13 @@ async function getList() {
     pageSize: pageSize.value,
   }
 
-  if (curFilter.value.id) {
-    param.areaId = curFilter.value.areaId
-    param.countryId = curFilter.value.id
+  if(curFilter.value.areaId) param.areaId = curFilter.value.areaId
+
+  if(curFilter.value.id) {
+    const countryId = curFilter.value.id.split(',')
+    if(!countryId[1]) param.countryId = curFilter.value.id
   }
+  
   if (travelWriteType.value) {
     param.travelWriteType = travelWriteType.value
   }
@@ -150,7 +174,7 @@ function handleFilterClick(item) {
   dataList.value = []
   getList()
   dropDownMenuRef.value && dropDownMenuRef.value.close()
-  document.title=`${item.id?'游记-'+item.text:'旅游笔记'}`
+  document.title=`${item.id?'游记-'+item.areaName+'-'+item.text:'旅游笔记'}`
 }
 
 function transferCount(num=0){
@@ -170,8 +194,7 @@ function convertTag(str=''){
   return str.split('&')
 }
 
-onMounted(() => {
-  getList()
+onMounted( async () => {
   getFilters()
 })
 

+ 9 - 0
src/pages/yj/[id].vue

@@ -293,6 +293,15 @@ async function isCollectTravelNotes() {
 
 // 收藏/取消收藏
 async function handleCollect() {
+  if (!token.value) {
+    showConfirmDialog({
+      showConfirmDialog: true,
+      title: '提示',
+      message: '登录后可以收藏游记',
+      theme: 'round-button',
+    }).then(async () => { navigateTo({ path: '/login' }) })
+    return
+  }
   const type = isCollect.value ? 0 : 1
   showLoadingToast({
     forbidClick: true,