FirstList.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <!-- 商城宣传页,列表页 -->
  2. <template>
  3. <view class="page-body" style="background: #f6f6f6;">
  4. <s-search-block :data="searchData" style="position: fixed;top: 0;left: 0;right: 0;z-index: 999;background-color: #fff;height: 80rpx;background-color: #f6f6f6;" :navbar="false" @input="onSearch" />
  5. <view v-if="state.pagination.total > 0 && cardType == 'activityCard'">
  6. <view class="article ss-r-10" v-for="item in state.pagination.list" @click="sheep.$router.go('/pages/public/richtext', {title:item.title});">
  7. <view class="title" >
  8. {{item.title}}
  9. </view>
  10. <view class="content">
  11. <view class="image " v-if="item.picUrl.trim()">
  12. <image :src="item.picUrl" mode="aspectFit" class="image-content"></image>
  13. </view>
  14. <view class="desc" >
  15. {{item.introduction}}
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. <view v-if="state.pagination.total > 0 && cardType == 'articleCard'">
  21. <view class="activity ss-r-10" v-for="item in state.pagination.list" :style="{ backgroundImage: `url(${item.picUrl})` }" @click="sheep.$router.go('/pages/public/richtext', {title:item.title});">
  22. <view class="activity-bottom">
  23. <text>{{item.title}}</text>
  24. <view class=""><image src="@/static/firstIndex/youjiantou.png" mode="aspectFit" /></view>
  25. </view>
  26. </view>
  27. </view>
  28. <s-empty v-if="state.pagination.total === 0" icon="/static/data-empty.png" :text="t('common.no_data')" />
  29. <uni-load-more v-if="state.pagination.total > 0" :status="state.loadStatus" :content-text="{ contentdown: '上拉加载更多'}" @tap="loadmore" />
  30. <s-tabbar path="/pages/index/FirstIndex" :tabbar="tabbar" />
  31. </view>
  32. </template>
  33. <script setup>
  34. import {
  35. computed,
  36. ref,
  37. reactive
  38. } from 'vue';
  39. import {
  40. onLoad,
  41. onShow,
  42. onReachBottom,
  43. onPullDownRefresh
  44. } from '@dcloudio/uni-app';
  45. import sheep from '@/sheep';
  46. import $share from '@/sheep/platform/share';
  47. import _ from 'lodash';
  48. import {
  49. isAndroid,
  50. getAndroidJiGuangId
  51. } from '@/sheep/hooks/useApp'
  52. import {
  53. showWalletModal,
  54. colseWalletModal
  55. } from '@/sheep/hooks/useModal';
  56. import { t } from '@/locale'
  57. import ArticleApi from '@/sheep/api/promotion/article';
  58. // 隐藏原生tabBar
  59. uni.hideTabBar();
  60. const appInfo = computed(() => sheep.$store('app').info);
  61. const {
  62. safeArea
  63. } = sheep.$platform.device;
  64. const pageHeight = computed(() => safeArea.height - 45);
  65. const searchData = ref({
  66. "height": 30,
  67. "showScan": false,
  68. "borderRadius": 0,
  69. "placeholder": "搜索文章",
  70. "placeholderPosition": "left",
  71. "backgroundColor": "rgb(238, 238, 238)",
  72. "textColor": "rgb(150, 151, 153)",
  73. "hottitles": [],
  74. "style": {
  75. "bgType": "color",
  76. "bgColor": "#fff",
  77. "marginBottom": 8,
  78. "paddingTop": 8,
  79. "paddingRight": 8,
  80. "paddingBottom": 8,
  81. "paddingLeft": 8
  82. }
  83. })
  84. const props = defineProps({
  85. // 是否显示tabbar
  86. tabbar: {
  87. type: Boolean,
  88. default: true
  89. },
  90. // 是否显示tabbar
  91. categoryId: {
  92. type: Number,
  93. default: 0
  94. },
  95. type:{
  96. type:String,
  97. default:'articleCard'
  98. }
  99. });
  100. const cardType = ref('articleCard');
  101. if(props.type){
  102. cardType.value = props.type
  103. }
  104. const tabbar = ref({
  105. "theme": "red",
  106. "style": {
  107. "bgType": "color",
  108. "bgColor": "#ffffff",
  109. "color": "#3c3c3c",
  110. "activeColor": "#1fa380"
  111. },
  112. "items": [{
  113. "text": t('common.home'),
  114. "url": "/pages/index/FirstIndex",
  115. "iconUrl": sheep.$url.static('/static/firstIndex/index.svg'),
  116. "activeIconUrl": sheep.$url.static('/static/firstIndex/index-active.svg')
  117. },
  118. {
  119. "text": t('common.activities'),
  120. "url": "/pages/index/FirstActivity",
  121. "iconUrl": sheep.$url.static('/static/firstIndex/activity.svg'),
  122. "activeIconUrl": sheep.$url.static('/static/firstIndex/activity-active.svg')
  123. },
  124. {
  125. "text": t('common.videos'),
  126. "url": "/pages/index/FirstVideo",
  127. "iconUrl": sheep.$url.static('/static/firstIndex/video.svg'),
  128. "activeIconUrl": sheep.$url.static('/static/firstIndex/video-active.svg')
  129. },
  130. {
  131. "text": t('common.mall'),
  132. "url": "/pages/index/index",
  133. "iconUrl": sheep.$url.static('/static/firstIndex/shop.svg'),
  134. "activeIconUrl": sheep.$url.static('/static/firstIndex/shop-active.svg')
  135. }
  136. ]
  137. });
  138. // 数据
  139. const state = reactive({
  140. categoryId: 0,
  141. pagination: {
  142. title:'',
  143. list: [],
  144. current_page: 1,
  145. total: 1,
  146. last_page: 1,
  147. },
  148. loadStatus: ''
  149. });
  150. async function getArticleList(page = 1, list_rows = 5) {
  151. state.loadStatus = 'loading';
  152. let { code, data } = await ArticleApi.getArticleByCategory({pageNo: page,pageSize: list_rows,categoryId: state.categoryId,title:state.pagination.title});
  153. if (code !== 0) {
  154. return;
  155. }
  156. let articleList = _.concat(state.pagination.list, data.list);
  157. state.pagination.list = articleList
  158. state.pagination.total = data.total;
  159. state.pagination.last_page = Math.ceil(data.total / 5)
  160. if (state.pagination.current_page < state.pagination.last_page) {
  161. state.loadStatus = 'more';
  162. } else {
  163. state.loadStatus = 'noMore';
  164. }
  165. console.log(state.pagination.list,state.pagination.total)
  166. }
  167. // 加载更多
  168. function loadMore() {
  169. if (state.loadStatus !== 'noMore') {
  170. state.pagination.current_page += 1
  171. getArticleList(state.pagination.current_page);
  172. }
  173. }
  174. // 搜索处理函数 (使用防抖)
  175. let searchTimer = null
  176. const onSearch = (e) => {
  177. if (searchTimer) clearTimeout(searchTimer)
  178. searchTimer = setTimeout(() => {
  179. // 搜索时重置分页数据
  180. state.pagination = {
  181. ...state.pagination,
  182. list: [], // 清空列表
  183. current_page: 1, // 重置到第一页
  184. total: 0, // 重置总数
  185. last_page: 1, // 重置最后一页
  186. title: e // 设置搜索关键词
  187. }
  188. getArticleList(1) // 从第一页开始搜索
  189. }, 300)
  190. }
  191. onLoad(async (option) => {
  192. if(option && option.categoryId){
  193. state.categoryId = option.categoryId
  194. }else{
  195. state.categoryId = props.categoryId
  196. }
  197. if(option && option.type){
  198. cardType.value = option.type
  199. }
  200. await getArticleList();
  201. });
  202. // 上拉加载更多
  203. onReachBottom(() => {
  204. loadMore();
  205. });
  206. // 下拉刷新
  207. onPullDownRefresh(() => {
  208. state.pagination.list = []
  209. state.pagination.current_page = 1
  210. state.pagination.total = 1
  211. state.pagination.last_page = 1
  212. getArticleList();
  213. setTimeout(function() {
  214. uni.stopPullDownRefresh();
  215. }, 800);
  216. });
  217. </script>
  218. <style scoped>
  219. .search-wrapper {
  220. position: fixed;
  221. top: 0;
  222. left: 0;
  223. right: 0;
  224. z-index: 999;
  225. background-color: #fff;
  226. padding: 20rpx;
  227. /* 可选: 添加阴影效果 */
  228. box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.1);
  229. }
  230. .list-content {
  231. /* search-wrapper 的高度 + padding */
  232. margin-top: calc(72rpx + 40rpx);
  233. }
  234. .page-body {
  235. width: 100%;
  236. position: relative;
  237. z-index: 1;
  238. flex: 1;
  239. padding-top:90rpx;
  240. box-sizing:border-box;
  241. .article {
  242. padding:16rpx;
  243. height: 230rpx;
  244. position: relative;
  245. width: 90%;
  246. margin: 0 auto;
  247. color:#000;
  248. margin-bottom: 40rpx;
  249. background-repeat: no-repeat;
  250. background-size: 100%;
  251. background-position: center;
  252. background-color: #fff;
  253. overflow: hidden;
  254. .title {
  255. font-size: 34rpx;
  256. /* font-weight: bold; */
  257. margin-bottom: 8px;
  258. }
  259. .content {
  260. display: flex;
  261. flex-direction: row;
  262. }
  263. .image {
  264. width: 300rpx;
  265. height: 169rpx;
  266. margin-right: 16rpx;
  267. background-color: #999;
  268. }
  269. .image-content {
  270. width: 100%;
  271. height: 100%;
  272. border-radius: 8rpx;
  273. }
  274. .desc {
  275. flex: 1;
  276. font-size: 32rpx;
  277. color: #333;
  278. line-height: 1.6;
  279. padding-top: 10rpx;
  280. overflow: hidden;
  281. display: -webkit-box;
  282. -webkit-box-orient: vertical;
  283. -webkit-line-clamp: 3;
  284. text-overflow: ellipsis;
  285. }
  286. }
  287. .activity {
  288. height: 300rpx;
  289. position: relative;
  290. width: 90%;
  291. margin: 0 auto;
  292. color:#fff;
  293. margin-bottom: 40rpx;
  294. background-repeat: no-repeat;
  295. background-size: 100%;
  296. background-position: center;
  297. background-color: #fff;
  298. overflow: hidden;
  299. .activity-bottom{
  300. position: absolute;
  301. bottom: 0;
  302. left: 0;
  303. width: 100%;
  304. height: 50rpx;
  305. background: rgba(0,0,0,0.5);
  306. padding:10rpx;
  307. box-sizing: border-box;
  308. display: flex;
  309. align-items: center;
  310. justify-content: space-between;
  311. text{
  312. white-space: nowrap;
  313. overflow: hidden;
  314. text-overflow: ellipsis;
  315. };
  316. image{
  317. width: 20rpx;
  318. height: 20rpx;
  319. }
  320. }
  321. }
  322. }
  323. </style>