TabVillageList.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <SimplePageListContentLoader class="d-flex flex-col flex-fill" :loader="loader">
  3. <Tab :tabs="tagsData" v-model="tab" autoSize itemWidth="100px" />
  4. <GridList :list="loader.content.value?.list" class="flex-fill" @item-click="handleItemClick" />
  5. </SimplePageListContentLoader>
  6. </template>
  7. <script setup lang="ts">
  8. import { computed, onMounted, ref, watch } from 'vue';
  9. import { useSimpleDataLoader } from '@/composeable/SimpleDataLoader';
  10. import { useRouter } from 'vue-router';
  11. import SimplePageListContentLoader from '@/components/SimplePageListContentLoader.vue';
  12. import GridList from '@/components/small/GridList.vue';
  13. import { ScrollRect } from '@imengyu/vue-scroll-rect';
  14. import VillageApi from '@/api/village/VillageApi';
  15. import CommonContent from '@/api/CommonContent';
  16. import Tab from '@/components/small/Tab.vue';
  17. import { useTvFocusImprovement } from '@/composeable/TvFocusImprovement';
  18. const emit = defineEmits(['itemClick']);
  19. const router = useRouter();
  20. const tab = ref(0);
  21. const tabId = computed(() => {
  22. return tagsData.value[tab.value]?.id || 0;
  23. })
  24. const { initSpatialNavigation } = useTvFocusImprovement();
  25. const loader = useSimpleDataLoader(async () => {
  26. const res = await VillageApi.getVillageList(tabId.value);
  27. setTimeout(initSpatialNavigation, 200);
  28. return {
  29. page: 1,
  30. total: res.length,
  31. list: res
  32. .map((item, index) => {
  33. return {
  34. title: item.villageName,
  35. desc: item.desc,
  36. ...item,
  37. addItems: [],
  38. bottomTags: [
  39. item.levelText,
  40. item.batchText,
  41. item.historyLevelText,
  42. ],
  43. };
  44. })
  45. ,
  46. }
  47. });
  48. watch(tab, () => loader.loadData(undefined, true))
  49. //子分类
  50. const tagsData = ref<{
  51. id: number,
  52. label: string,
  53. }[]>([]);
  54. onMounted(async () => {
  55. const res = await CommonContent.getCategoryList(151);
  56. const it1 = res.find(p => p.title == '国家级');
  57. const it2 = res.find(p => p.title == '省级');
  58. if (it1) it1.title = '特色村舍';
  59. if (it2) it2.title = '传统村落';
  60. tagsData.value = res.slice(1).map((p) => ({ id: p.id, label: p.title }));
  61. })
  62. function handleItemClick(item: any) {
  63. localStorage.setItem('VillageTemp', JSON.stringify(item));
  64. setTimeout(() => {
  65. router.push({ name: 'VillageDetail', query: { id: item.id } });
  66. }, 200);
  67. }
  68. </script>
  69. <style scoped lang="scss">
  70. </style>