index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view class="main">
  3. <view class="search">
  4. <uni-search-bar
  5. v-model="searchValue"
  6. radius="100"
  7. bgColor="#fff"
  8. placeholder="搜一搜"
  9. clearButton="auto"
  10. cancelButton="none"
  11. @confirm="search"
  12. />
  13. </view>
  14. <u-tabs
  15. :current="currentCategoryId"
  16. :list="categoryList"
  17. lineWidth="30"
  18. lineColor="rgb(255, 135, 25)"
  19. :activeStyle="{
  20. color: '#000',
  21. fontWeight: 'bold',
  22. transform: 'scale(1.05)'
  23. }"
  24. :inactiveStyle="{
  25. color: '#606266',
  26. transform: 'scale(1)'
  27. }"
  28. :scrollable="false"
  29. class="top-tab"
  30. @click="tabClick"
  31. />
  32. <view class="post-list">
  33. <view
  34. v-for="item in listLoader.list.value"
  35. :key="item.id"
  36. class="item"
  37. @click="goDetails(item.id)"
  38. >
  39. <view class="image-wrap" :style="{backgroundImage:'url('+item.image+')'}">
  40. <view class="like" :class="{liked: item.isLike}">
  41. <text class="iconfont icon-liked" v-if="item.isLike"></text>
  42. <text class="iconfont icon-like" v-else></text>
  43. <text>{{ item.likes }}</text>
  44. </view>
  45. </view>
  46. <view class="desc ellipsis-2">{{ item.title }}</view>
  47. </view>
  48. </view>
  49. <SimplePageListLoader :loader="listLoader" />
  50. </view>
  51. </template>
  52. <script setup lang="ts">
  53. import { ref, watch } from 'vue'
  54. import { useSimplePageListLoader } from '@/common/composeabe/SimplePageListLoader';
  55. import { navTo } from '@/common/utils/PageAction';
  56. import SimplePageListLoader from '@/common/components/SimplePageListLoader.vue';
  57. import { GetContentListItem, GetContentListParams } from '@/api/CommonContent';
  58. import NewsIndexContent from '@/api/news/NewsIndexContent';
  59. const searchValue = ref('');
  60. const currentCategoryId = ref(3);
  61. const categoryList = [
  62. {
  63. id: 1,
  64. name: '美好时光'
  65. },
  66. {
  67. id: 2,
  68. name: '伴手好礼'
  69. }, {
  70. id: 3,
  71. name: '特色佳肴'
  72. }, {
  73. id: 4,
  74. name: '海鲜盛宴'
  75. }
  76. ];
  77. const listLoader = useSimplePageListLoader<GetContentListItem>(8, async (page, pageSize) => {
  78. const res = await NewsIndexContent.getContentList(new GetContentListParams().setSelfValues({
  79. keywords: searchValue.value,
  80. mainBodyColumnId: 303
  81. }), page, pageSize);
  82. return res.list;
  83. });
  84. watch(currentCategoryId, () => {
  85. listLoader.loadData(undefined, true);
  86. }, { immediate: true });
  87. function goDetails(id: number) {
  88. navTo('../details', { id })
  89. }
  90. function search() {
  91. listLoader.loadData(undefined, true);
  92. }
  93. function tabClick(e: { index: number }) {
  94. currentCategoryId.value = e.index;
  95. }
  96. </script>
  97. <style lang="scss" scoped>
  98. </style>