index.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  1. <template>
  2. <view :style="{ height: windowHeight + 'px' }">
  3. <!-- <view style="display: flex; justify-content: flex-end">
  4. <view class="view0 step1"></view>
  5. </view>
  6. <view class="view1 step2"></view>
  7. <view class="view2 step3"></view>
  8. <view class="view3 step4"></view>
  9. <view class="view4 step5"></view>
  10. <view class="view5 step6"></view>
  11. <view style="display: flex; justify-content: flex-end">
  12. <view class="view6 step7"></view>
  13. </view> -- </view> -->
  14. <z-paging :use-custom-refresher="false" ref="paging" v-model="dataList" :auto="false"
  15. :style="{ height: windowHeight - 80 + 'px' }" :show-scrollbar="false" :refresher-enabled="true"
  16. @refresherrefresh="onRefresh" @refresherrestore="onRefresherRestore" @query="queryLists" :fixed="true"
  17. :safe-area-inset-bottom="true" :loading-more-enabled="true" :loading-more-no-more-text="'没有更多了'"
  18. :loading-more-loading-text="'加载中...'" :loading-more-fail-text="'加载失败,点击重试'"
  19. :loading-more-default-text="'上拉加载更多'" :loading-more-loading-style="{ color: '#999' }"
  20. :loading-more-no-more-style="{ color: '#999' }" :loading-more-fail-style="{ color: '#999' }"
  21. :loading-more-default-style="{ color: '#999' }" @loadingMore="onZPagingLoadMore">
  22. <template #top>
  23. <page-navbar>
  24. <template #navCenter>
  25. <view class="top" style="display: flex">
  26. <!-- 手动选择城市功能隐藏 -->
  27. <!-- <view class="topBox" @click="lhSelectCityFun"> -->
  28. <view class="topBox">
  29. <text style="
  30. margin-left: 10rpx;
  31. margin-right: 20rpx;
  32. font-size: 44rpx;
  33. font-weight: 600;
  34. ">
  35. {{ currentCity }}
  36. </text>
  37. <!-- <image src="@/static/home/home-bom.png"
  38. style="width: 36rpx; height: 36rpx;margin-left: 15rpx;margin-right: 30rpx;"></image> -->
  39. </view>
  40. <view class="weather">
  41. <p>
  42. {{ weather.weather }}<i :class="'qi-' + weather.icon"></i>️{{
  43. weather.temp
  44. }}
  45. </p>
  46. <p>{{ getDayOfWeek }}</p>
  47. </view>
  48. </view>
  49. <view class="search" @click="goPage('/pages/index/Search')">
  50. <uv-input placeholder="🔥 潮玩大作战 派对季重磅开启!" border="none"
  51. :custom-style="{ background: '#fff', paddingLeft: '25rpx' }" shape="circle">
  52. <image class="testImg" src="@/static/home/icon-hot.png"
  53. style="width: 22rpx; height: 30rpx"></image>
  54. <template #suffix>
  55. <view class="input-box">
  56. <image src="@/static/icon/search.png" style="width: 32rpx; height: 32rpx">
  57. </image>
  58. </view>
  59. </template>
  60. </uv-input>
  61. </view>
  62. </template>
  63. </page-navbar>
  64. </template>
  65. <z-paging-cell class="benner-box" style="padding-bottom: 0;">
  66. <sortble :default-sorts="['uvSwiper', 'classModel', 'uvSwiperCard']">
  67. <template #uvSwiper>
  68. <uv-swiper :list="bannerList" :autoplay="true" circular :interval="5000" indicator
  69. indicator-mode="dot" height="120" radius="0"></uv-swiper>
  70. </template>
  71. <template #classModel>
  72. <view class="classModel" v-if="isTheTask">
  73. <image src="@/static/home/benner-iconBom.png" class="benner-iconBom" mode=""></image>
  74. <image src="@/static/home/benner-icontop.png" class="benner-icontop" mode=""></image>
  75. <view class="benner-box benner-left-box" @click="goPage('/pages/my/job')">
  76. <view class="text1"> 获取奖励 </view>
  77. <view class="btn"> 立即前往 </view>
  78. </view>
  79. <view class="benner-box benner-right-box" ref="classModel1">
  80. <view class="guard">
  81. <view class="text"> 潮玩IP </view>
  82. </view>
  83. <view class="match">
  84. <view class="text"> 社交 </view>
  85. </view>
  86. </view>
  87. </view>
  88. </template>
  89. </sortble>
  90. </z-paging-cell>
  91. <z-paging-cell style="background: #fff">
  92. <view class="tab-nav">
  93. <view v-for="(tab, index) in tabs" :key="index"
  94. :class="['tab-item', currentTab === index ? 'active' : '']" @click="switchTab(index)">
  95. {{ tab }}
  96. <view class="indicator-triangle"> </view>
  97. </view>
  98. </view>
  99. <swiper class="tab-content-swiper" :current="currentTab" @change="handleTabChange" :duration="300"
  100. :style="{ height: swiperHeight + 'px' }">
  101. <!-- 关注列表 -->
  102. <swiper-item>
  103. <view class="follow-list">
  104. <block v-if="currentTab === 0 && followList.length > 0">
  105. <w-waterfall :data="followList">
  106. <template v-slot:content="{ item, width }">
  107. <card :item="formatItem(item)" :width="width"
  108. :custom-style="{ background: '#fff' }" textColor="#000"
  109. @imageLoad="onImageLoaded">
  110. </card>
  111. </template>
  112. </w-waterfall>
  113. </block>
  114. <view class="no-data"
  115. v-else-if="currentTab === 0 && !isLoadingFollow && followList.length === 0">
  116. <text>暂无关注数据</text>
  117. </view>
  118. </view>
  119. </swiper-item>
  120. <!-- 推荐列表 -->
  121. <swiper-item>
  122. <view class="recommend-list">
  123. <w-waterfall v-if="currentTab === 1 && recommendList.length > 0" :data="recommendList">
  124. <template v-slot:content="{ item, width }">
  125. <card :item="formatItem(item)" :width="width" :custom-style="{ background: '#fff' }"
  126. textColor="#000" @imageLoad="onImageLoaded">
  127. </card>
  128. </template>
  129. </w-waterfall>
  130. <view class="no-data"
  131. v-if="currentTab === 1 && recommendList.length === 0 && !isLoadingRecommend">
  132. <text>暂无推荐数据</text>
  133. </view>
  134. </view>
  135. </swiper-item>
  136. <!-- 探索列表 -->
  137. <swiper-item>
  138. <view class="explore-list">
  139. <view class="hot-topics" v-if="currentTab === 2">
  140. <view class="hot-topics-header">
  141. <image class="hot-topics-title" src="@/static/home/hot-topics-title.png" mode="">
  142. </image>
  143. </view>
  144. <swiper class="hot-topics-swiper" :current="currentTopicPage"
  145. @change="handleTopicPageChange">
  146. <swiper-item v-for="(page, pageIndex) in topicPages" :key="pageIndex">
  147. <view class="hot-topics-list">
  148. <view v-for="(topic, index) in page" :key="index" class="topic-item"
  149. @click="goToArticleDetail(topic.id)">
  150. <view class="hot-topics-left">
  151. <image v-if="pageIndex * 4 + index == 0"
  152. src="@/static/icon/icon-first.png"
  153. class="topic-index topic-index-img" mode=""></image>
  154. <image v-else-if="pageIndex * 4 + index == 1"
  155. src="@/static/icon/icon-second.png"
  156. class="topic-index topic-index-img" mode=""></image>
  157. <image v-else-if="pageIndex * 4 + index == 2"
  158. src="@/static/icon/icon-third.png"
  159. class="topic-index topic-index-img" mode=""></image>
  160. <text v-else class="topic-index">{{
  161. pageIndex * 4 + index + 1
  162. }}</text>
  163. <view class="topic-content toe">
  164. {{ topic.title }}
  165. </view>
  166. <image v-if="topic.isHot" src="@/static/icon/icon-hot.png"
  167. class="hot-tag" mode=""></image>
  168. </view>
  169. <text class="topic-participants">{{ topic.num_like }}人正在热议</text>
  170. </view>
  171. </view>
  172. </swiper-item>
  173. </swiper>
  174. <view class="indicator-dots">
  175. <view v-for="i in 2" :key="i"
  176. :class="['dot', currentTopicPage === i - 1 ? 'active' : '']">
  177. </view>
  178. </view>
  179. </view>
  180. <view class="news-list">
  181. <w-waterfall v-if="currentTab === 2 && newsList.length > 0" :data="newsList">
  182. <template v-slot:content="{ item, width }">
  183. <card :item="formatItem(item)" :width="width"
  184. goLink="/pages/index/articleDetail?id="
  185. :custom-style="{ background: '#fff' }" textColor="#000"
  186. @imageLoad="onImageLoaded"></card>
  187. </template>
  188. </w-waterfall>
  189. </view>
  190. <view class="no-data" v-if="currentTab === 2 && newsList.length === 0 && !isLoadingNews">
  191. <text>暂无新闻数据</text>
  192. </view>
  193. </view>
  194. </swiper-item>
  195. </swiper>
  196. </z-paging-cell>
  197. <view class="blankHeight"></view>
  198. </z-paging>
  199. <tabbar-vue :tabbars="tabbars" :currentIndex="0" ref="tabbar"></tabbar-vue>
  200. <!-- 添加浮动按钮 -->
  201. <view v-if="currentTab === 2" class="float-btn" @click="goToMake">
  202. <image src="/static/home/release-btn.png" class="float-btn-icon"></image>
  203. </view>
  204. <!-- <novice-guidance :step="step"></novice-guidance> -->
  205. <lhSelectCity style="height: 100vh" class="lhSelectCity" :currentCity="currentCity" :windowHeight="windowHeight"
  206. :hotCitys="hotCitys" @onSelect="City" v-if="lhSelectCityFalg"
  207. @closeLhSelectCityFun="closeLhSelectCityFun()" />
  208. </view>
  209. </template>
  210. <script>
  211. import sortble from "@/components/sortble/sortble.vue";
  212. import tabbarVue from "@/components/tabbar/tabbar.vue";
  213. import pageNavbar from "@/components/page-navbar/page-navbar.vue";
  214. import wWaterfall from "@/components/w-waterfall/w-waterfall.vue";
  215. import tabbar from "@/mixins/tabbar";
  216. import card from "@/components/card/card.vue";
  217. import lhSelectCity from "@/components/lh-select-city/index.vue";
  218. import { mapState,mapGetters } from 'vuex'
  219. import {
  220. getStorage,
  221. setStorage,
  222. removeStorage
  223. } from "@/common/util.js";
  224. // import noviceGuidance from "@/components/novice-guidance/index.vue";
  225. export default {
  226. components: {
  227. sortble,
  228. tabbarVue,
  229. pageNavbar,
  230. wWaterfall,
  231. lhSelectCity,
  232. card,
  233. // noviceGuidance
  234. },
  235. mixins: [tabbar],
  236. data() {
  237. return {
  238. isFirstLoad: true, // 添加标记,用于判断是否是第一次加载
  239. swiperHeight: 300, // 默认swiper高度
  240. noMoreDataTimer: null, // 用于防抖处理的定时器
  241. step: {
  242. name: "workbenchSet5",
  243. guideList: [{
  244. el: ".step1",
  245. tips: "这里是第一步的介绍~",
  246. next: "下一步",
  247. },
  248. {
  249. el: ".step2",
  250. tips: "这里是第二步的介绍~",
  251. next: "下一步",
  252. },
  253. {
  254. el: ".step3",
  255. tips: "这里是第三步的介绍~",
  256. next: "下一步",
  257. },
  258. {
  259. el: ".step4",
  260. tips: "这里是第四步的介绍~",
  261. next: "下一步",
  262. },
  263. {
  264. el: ".step5",
  265. tips: "这里是第五步的介绍~",
  266. next: "下一步",
  267. },
  268. {
  269. el: ".step6",
  270. tips: "这里是第六步的介绍~",
  271. next: "下一步",
  272. },
  273. {
  274. el: ".step7",
  275. tips: "最后一步啦~",
  276. next: "完成",
  277. },
  278. ],
  279. },
  280. windowHeight: uni.getWindowInfo().windowHeight,
  281. bannerList: [
  282. "../../static/dome/home-swper.png",
  283. "../../static/dome/home-swper.png",
  284. "../../static/dome/home-swper.png",
  285. ],
  286. cardList: [ ],
  287. list: [], // 瀑布流全部数据
  288. dataList: [],
  289. tabs: ["关注", "推荐", "探索"],
  290. currentTab: 1,
  291. currentTopicPage: 0,
  292. followList: [], // 关注列表数据
  293. recommendList: [], // 推荐列表数据
  294. exploreList: [], // 探索列表数据
  295. hotNewsList: [], // 热点新闻数据
  296. newsList: [], // 新闻列表数据
  297. followOffset: 0, // 关注列表偏移量
  298. recommendOffset: 0, // 推荐列表偏移量
  299. exploreOffset: 0, // 探索列表偏移量
  300. newsOffset: 0, // 新闻列表偏移量
  301. hasMoreFollow: true, // 是否有更多关注列表数据
  302. hasMoreRecommend: true, // 是否有更多推荐列表数据
  303. hasMoreExplore: true, // 是否有更多探索列表数据
  304. hasMoreNews: true, // 是否有更多新闻列表数据
  305. isLoadingFollow: false, // 是否正在加载关注列表
  306. isLoadingRecommend: false, // 是否正在加载推荐列表
  307. isLoadingExplore: false, // 是否正在加载探索列表
  308. isLoadingNews: false, // 是否正在加载新闻列表
  309. hotTopics: [],
  310. lhSelectCityFalg: false,
  311. hotCitys: [
  312. "杭州",
  313. "天津",
  314. "北京",
  315. "上海",
  316. "深圳",
  317. "广州",
  318. "成都",
  319. "重庆",
  320. "厦门",
  321. ],
  322. currentCity: "北京",
  323. windowHeight: "",
  324. weather: {
  325. city: "",
  326. weather: "",
  327. temp: "0℃",
  328. icon: 101,
  329. },
  330. updateHeightTimer: null,
  331. };
  332. },
  333. computed: {
  334. ...mapState('switchingModule', ['isTheTask']),
  335. ...mapState('rightsManagement', ['teenageMode','iscontentRecommendation']),
  336. ...mapGetters( 'rightsManagement', ['isContent']),
  337. getDayOfWeek() {
  338. const days = [
  339. "星期日",
  340. "星期一",
  341. "星期二",
  342. "星期三",
  343. "星期四",
  344. "星期五",
  345. "星期六",
  346. ];
  347. const today = new Date();
  348. const dayOfWeek = days[today.getDay()];
  349. return dayOfWeek;
  350. },
  351. currentList() {
  352. switch (this.currentTab) {
  353. case 0:
  354. return this.followList;
  355. case 1:
  356. return this.recommendList; // 使用专门的推荐列表
  357. case 2:
  358. return this.exploreList;
  359. default:
  360. return [];
  361. }
  362. },
  363. topicPages() {
  364. const pages = [];
  365. for (let i = 0; i < this.hotTopics.length; i += 4) {
  366. pages.push(this.hotTopics.slice(i, i + 4));
  367. }
  368. return pages;
  369. },
  370. },
  371. onLoad() {
  372. let that = this;
  373. // 计算出可用高度
  374. this.windowHeight = uni.getSystemInfoSync().windowHeight + "px";
  375. // 计算swiper默认高度
  376. const systemInfo = uni.getSystemInfoSync();
  377. this.swiperHeight = systemInfo.windowHeight * 0.6; // 初始设置为窗口高度的60%
  378. // 获取天气信息
  379. this.getWeather();
  380. // 初始化数据,确保首次加载正确
  381. this.$nextTick(() => {
  382. // 根据当前标签加载数据
  383. this.initialLoad();
  384. });
  385. },
  386. onShow() {
  387. console.log('teenageMode',this.teenageMode);
  388. console.log('iscontentRecommendation',this.iscontentRecommendation);
  389. console.log('isContent',this.isContent);
  390. if ( !this.isContent ) {
  391. this.tabs = ["关注"];
  392. this.currentTab = 0;
  393. this.queryList();
  394. } else {
  395. this.tabs = ["关注", "推荐", "探索"];
  396. // this.currentTab = 1;
  397. // 如果数据为空,加载初始数据
  398. if (this.recommendList.length === 0) {
  399. this.initialLoad();
  400. }
  401. }
  402. uni.$emit('check_update');
  403. },
  404. // 修改触底加载方法
  405. onReachBottom() {
  406. console.log('触底加载更多');
  407. // 根据当前标签页加载更多数据
  408. switch (this.currentTab) {
  409. case 0:
  410. if (this.hasMoreFollow && !this.isLoadingFollow) {
  411. this.loadFollowList();
  412. }
  413. break;
  414. case 1:
  415. if (this.hasMoreRecommend && !this.isLoadingRecommend) {
  416. this.loadRecommendList();
  417. }
  418. break;
  419. case 2:
  420. if (this.hasMoreNews && !this.isLoadingNews) {
  421. this.loadNewsList();
  422. }
  423. break;
  424. }
  425. },
  426. // 下拉刷新数据
  427. methods: {
  428. swipeRight() {
  429. let index = this.currentTab
  430. index--
  431. if (index < 0) {
  432. index = this.tabs.length - 1
  433. }
  434. this.switchTab(index)
  435. console.log('向右滑动')
  436. },
  437. swipeLeft() {
  438. let index = this.currentTab
  439. index++
  440. if (index > this.tabs.length - 1) {
  441. index = 0
  442. }
  443. this.switchTab(index)
  444. console.log('向左滑动')
  445. },
  446. getWeather(city) {
  447. uni.request({
  448. url: this.$apiHost + "/Index/getAreaInfo",
  449. data: {
  450. uuid: getApp().globalData.uuid,
  451. skey: getApp().globalData.skey,
  452. city: city || (this.currentCity == "北京" ? "" : this.currentCity),
  453. },
  454. header: {
  455. "content-type": "application/json",
  456. sign: getApp().globalData.headerSign,
  457. },
  458. success: (res) => {
  459. console.log(this.weather, "天气数据", res.data);
  460. if (res.data.data.city) {
  461. this.currentCity = res.data.data.city;
  462. this.weather = res.data.data;
  463. }
  464. },
  465. complete: () => { },
  466. fail: (e) => { },
  467. });
  468. },
  469. lhSelectCityFun() {
  470. this.lhSelectCityFalg = true;
  471. },
  472. // 选中事件
  473. City(city) {
  474. this.currentCity = city;
  475. setTimeout(() => {
  476. this.lhSelectCityFalg = false;
  477. }, 300);
  478. },
  479. closeLhSelectCityFun() {
  480. this.lhSelectCityFalg = false;
  481. },
  482. queryList() {
  483. // 根据当前标签刷新数据
  484. switch (this.currentTab) {
  485. case 0:
  486. // 重置关注列表
  487. this.followList = [];
  488. this.followOffset = 0;
  489. this.hasMoreFollow = true;
  490. this.loadFollowList();
  491. break;
  492. case 1:
  493. // 重置推荐列表
  494. this.recommendList = [];
  495. this.recommendOffset = 0;
  496. this.hasMoreRecommend = true;
  497. this.loadRecommendList();
  498. break;
  499. case 2:
  500. // 重置热点新闻和新闻列表
  501. this.hotNewsList = [];
  502. this.newsList = [];
  503. this.newsOffset = 0;
  504. this.hasMoreNews = true;
  505. // 加载热点新闻和新闻列表
  506. this.loadHotNews();
  507. this.loadNewsList();
  508. break;
  509. }
  510. },
  511. queryLists() {
  512. // 根据当前标签刷新数据
  513. switch (this.currentTab) {
  514. case 0:
  515. // 重置关注列表
  516. this.loadFollowList();
  517. break;
  518. case 1:
  519. // 重置推荐列表
  520. this.loadRecommendList();
  521. break;
  522. case 2:
  523. // 重置热点新闻和新闻列表
  524. // 加载热点新闻和新闻列表
  525. this.loadHotNews();
  526. this.loadNewsList();
  527. break;
  528. }
  529. // 第一次加载完成后,将标记设置为false
  530. this.isFirstLoad = false;
  531. },
  532. switchTab(index) {
  533. if (this.currentTab === index) return;
  534. this.currentTab = index;
  535. // 重置当前标签页的数据
  536. switch (index) {
  537. case 0:
  538. this.followList = [];
  539. this.followOffset = 0;
  540. this.hasMoreFollow = true;
  541. break;
  542. case 1:
  543. this.recommendList = [];
  544. this.recommendOffset = 0;
  545. this.hasMoreRecommend = true;
  546. break;
  547. case 2:
  548. this.newsList = [];
  549. this.hotTopics = [];
  550. this.newsOffset = 0;
  551. this.hasMoreNews = true;
  552. break;
  553. }
  554. // 加载新标签页的数据
  555. this.loadTabData(index);
  556. // 切换标签后更新swiper高度
  557. // 在切换标签时,先将高度设置为一个合适的默认值
  558. // 然后在数据加载完成后再动态调整
  559. const systemInfo = uni.getSystemInfoSync();
  560. this.swiperHeight = systemInfo.windowHeight * 0.6;
  561. },
  562. loadTabData(index) {
  563. switch (index) {
  564. case 0:
  565. this.loadFollowList();
  566. break;
  567. case 1:
  568. this.loadRecommendList();
  569. break;
  570. case 2:
  571. this.loadHotNews();
  572. this.loadNewsList();
  573. break;
  574. }
  575. },
  576. // 修改关注列表加载方法
  577. loadFollowList() {
  578. if (this.isLoadingFollow) return;
  579. this.isLoadingFollow = true;
  580. // 保存当前列表数据
  581. const currentList = [...this.followList];
  582. // offset设置为当前列表长度
  583. this.followOffset = currentList.length;
  584. console.log('请求关注列表数据,当前offset =', this.followOffset);
  585. uni.request({
  586. url: this.$apiHost + "/Work/getlist",
  587. data: {
  588. uuid: getApp().globalData.uuid,
  589. skey: getApp().globalData.skey,
  590. type: "attention",
  591. offset: this.followOffset,
  592. },
  593. header: {
  594. "content-type": "application/json",
  595. sign: getApp().globalData.headerSign,
  596. },
  597. success: (res) => {
  598. console.log("关注列表数据:", res.data);
  599. if (res.data.success == "yes" && res.data.list && res.data.list.length > 0) {
  600. // 追加新数据到列表
  601. this.followList = [...currentList, ...res.data.list];
  602. console.log('关注列表加载成功,当前列表长度:', this.followList.length);
  603. this.hasMoreFollow = res.data.list.length >= 20;
  604. } else {
  605. this.hasMoreFollow = false;
  606. this.showNoMoreDataToast("没有更多关注内容了");
  607. }
  608. // 使用 nextTick 确保数据更新后再通知组件
  609. this.$nextTick(() => {
  610. if (this.$refs.paging) {
  611. // 第一个参数需要是数组,将当前列表传入
  612. this.$refs.paging.complete(this.followList);
  613. }
  614. // 数据加载完成后更新swiper高度
  615. if (this.currentTab === 0) {
  616. // 使用setTimeout确保数据渲染完成后再更新高度
  617. setTimeout(() => {
  618. this.updateSwiperHeight();
  619. }, 300);
  620. setTimeout(() => {
  621. this.updateSwiperHeight();
  622. }, 650);
  623. }
  624. });
  625. },
  626. complete: () => {
  627. this.isLoadingFollow = false;
  628. },
  629. fail: (e) => {
  630. console.log("请求关注列表失败:", e);
  631. this.isLoadingFollow = false;
  632. if (this.$refs.paging) {
  633. // 加载失败时提供空数组
  634. this.$refs.paging.complete([]);
  635. }
  636. },
  637. });
  638. },
  639. // 修改推荐列表加载方法
  640. loadRecommendList() {
  641. if (this.isLoadingRecommend) return;
  642. this.isLoadingRecommend = true;
  643. // 保存当前列表数据
  644. const currentList = [...this.recommendList];
  645. // offset设置为当前列表长度
  646. this.recommendOffset = currentList.length;
  647. console.log('请求推荐列表数据,当前offset =', this.recommendOffset);
  648. uni.request({
  649. url: this.$apiHost + "/Work/getlist",
  650. data: {
  651. uuid: getApp().globalData.uuid,
  652. skey: getApp().globalData.skey,
  653. type: "recommend",
  654. offset: this.recommendOffset,
  655. },
  656. header: {
  657. "content-type": "application/json",
  658. sign: getApp().globalData.headerSign,
  659. },
  660. success: (res) => {
  661. console.log("推荐列表数据:", res.data);
  662. if (res.data.success == "yes" && res.data.list && res.data.list.length > 0) {
  663. // 追加新数据到列表
  664. this.recommendList = [...currentList, ...res.data.list];
  665. console.log('推荐列表加载成功,当前列表长度:', this.recommendList.length);
  666. this.hasMoreRecommend = res.data.list.length >= 20;
  667. } else {
  668. this.hasMoreRecommend = false;
  669. this.showNoMoreDataToast("没有更多推荐内容了");
  670. }
  671. this.$nextTick(() => {
  672. if (this.$refs.paging) {
  673. // 第一个参数需要是数组,将当前列表传入
  674. this.$refs.paging.complete(this.recommendList);
  675. }
  676. // 数据加载完成后更新swiper高度
  677. if (this.currentTab === 1) {
  678. setTimeout(() => {
  679. this.updateSwiperHeight();
  680. }, 300);
  681. setTimeout(() => {
  682. this.updateSwiperHeight();
  683. }, 650);
  684. }
  685. });
  686. },
  687. complete: () => {
  688. this.isLoadingRecommend = false;
  689. },
  690. fail: (e) => {
  691. console.log("请求推荐列表失败:", e);
  692. this.isLoadingRecommend = false;
  693. if (this.$refs.paging) {
  694. // 加载失败时提供空数组
  695. this.$refs.paging.complete([]);
  696. }
  697. },
  698. });
  699. },
  700. loadHotNews() {
  701. if (this.isLoadingExplore) return;
  702. this.isLoadingExplore = true;
  703. uni.request({
  704. url: this.$apiHost + "/Article/getlist",
  705. data: {
  706. uuid: getApp().globalData.uuid,
  707. skey: getApp().globalData.skey,
  708. type: "hot",
  709. },
  710. header: {
  711. "content-type": "application/json",
  712. sign: getApp().globalData.headerSign,
  713. },
  714. success: (res) => {
  715. console.log("热点新闻数据:", res.data);
  716. if (res.data.success == "yes" && res.data.list && res.data.list.length > 0) {
  717. this.hotNewsList = res.data.list;
  718. this.hotTopics = this.hotNewsList.map((item, index) => ({
  719. id: item.id,
  720. title: item.title || "热门话题",
  721. num_like: item.num_like || 0,
  722. isHot: index % 2 === 0,
  723. }));
  724. }
  725. },
  726. complete: () => {
  727. this.isLoadingExplore = false;
  728. },
  729. fail: (e) => {
  730. console.log("请求热点新闻失败:", e);
  731. this.isLoadingExplore = false;
  732. },
  733. });
  734. },
  735. // 修改新闻列表加载方法
  736. loadNewsList() {
  737. if (this.isLoadingNews) return;
  738. this.isLoadingNews = true;
  739. // 保存当前列表数据
  740. const currentList = [...this.newsList];
  741. // offset设置为当前列表长度
  742. this.newsOffset = currentList.length;
  743. console.log('请求新闻列表数据,当前offset =', this.newsOffset);
  744. uni.request({
  745. url: this.$apiHost + "/Article/getlist",
  746. data: {
  747. uuid: getApp().globalData.uuid,
  748. skey: getApp().globalData.skey,
  749. type: "list",
  750. offset: this.newsOffset,
  751. },
  752. header: {
  753. "content-type": "application/json",
  754. sign: getApp().globalData.headerSign,
  755. },
  756. success: (res) => {
  757. console.log("新闻列表数据:", res.data);
  758. if (res.data.success == "yes" && res.data.list && res.data.list.length > 0) {
  759. // 追加新数据到列表
  760. this.newsList = [...currentList, ...res.data.list];
  761. console.log('新闻列表加载成功,当前列表长度:', this.newsList.length);
  762. this.hasMoreNews = res.data.list.length >= 20;
  763. } else {
  764. this.hasMoreNews = false;
  765. this.showNoMoreDataToast("没有更多新闻内容了");
  766. }
  767. this.$nextTick(() => {
  768. if (this.$refs.paging) {
  769. // 第一个参数需要是数组,将当前列表传入
  770. this.$refs.paging.complete(this.newsList);
  771. }
  772. // 数据加载完成后更新swiper高度
  773. if (this.currentTab === 2) {
  774. setTimeout(() => {
  775. this.updateSwiperHeight();
  776. }, 300);
  777. setTimeout(() => {
  778. this.updateSwiperHeight();
  779. }, 650);
  780. }
  781. });
  782. },
  783. complete: () => {
  784. this.isLoadingNews = false;
  785. },
  786. fail: (e) => {
  787. console.log("请求新闻列表失败:", e);
  788. this.isLoadingNews = false;
  789. if (this.$refs.paging) {
  790. // 加载失败时提供空数组
  791. this.$refs.paging.complete([]);
  792. }
  793. },
  794. });
  795. },
  796. handleTopicPageChange(e) {
  797. this.currentTopicPage = e.detail.current;
  798. },
  799. formatItem(item) {
  800. console.log("item:", item);
  801. let img = "";
  802. if (item.images) {
  803. img = item.images.split("|")[0];
  804. }
  805. // 处理接口返回的数据,使其适配card组件
  806. return {
  807. id: item.id,
  808. allowEdit: false,
  809. nickname: item.nickname,
  810. avator: item.avator,
  811. num_like: item.num_like,
  812. num_view: item.num_view,
  813. image: img || item.img_url || item.image, // 优先使用images字段
  814. w: item.width,
  815. h: item.height,
  816. title: item.title || "",
  817. desc: item.desc || "",
  818. userID: item.userID || 0,
  819. backgroundColor: "#f6f6f6",
  820. };
  821. },
  822. goToArticleDetail(id) {
  823. if (!id) {
  824. uni.showToast({
  825. title: "文章ID不存在",
  826. icon: "none",
  827. });
  828. return;
  829. }
  830. // uni.$emit("check_login", () => {
  831. uni.navigateTo({
  832. url: "/pages/index/articleDetail?id=" + id,
  833. });
  834. // });
  835. },
  836. goWork(item) {
  837. console.log("skeylogin", "xxx");
  838. uni.$emit("check_login", () => {
  839. uni.navigateTo({
  840. url: "/pages/index/workDetail?id=" + item.id,
  841. });
  842. });
  843. },
  844. goToMake() {
  845. console.log("skeylogin", "xxx2");
  846. uni.$emit("check_login", () => {
  847. uni.navigateTo({
  848. // 生成个人形象
  849. // url: "/pages/make/make",
  850. url: "/pages/make/fabuArticle?id=-1",
  851. });
  852. });
  853. },
  854. goPage(page) {
  855. uni.$emit("check_login", () => {
  856. uni.navigateTo({
  857. url: page,
  858. });
  859. });
  860. },
  861. // 修改下拉刷新方法
  862. onRefresh() {
  863. console.log('下拉刷新开始');
  864. // 重置所有数据
  865. this.followList = [];
  866. this.recommendList = [];
  867. this.newsList = [];
  868. this.hotTopics = [];
  869. // 重置偏移量
  870. this.followOffset = 0;
  871. this.recommendOffset = 0;
  872. this.newsOffset = 0;
  873. // 重置加载状态
  874. this.hasMoreFollow = true;
  875. this.hasMoreRecommend = true;
  876. this.hasMoreNews = true;
  877. // 根据当前标签页加载数据
  878. this.loadTabData(this.currentTab);
  879. },
  880. // 下拉刷新恢复
  881. onRefresherRestore() {
  882. console.log('下拉刷新恢复');
  883. },
  884. // 处理z-paging的触底加载更多事件
  885. onZPagingLoadMore(pageNo, pageSize) {
  886. console.log('触底加载更多, 页码:', pageNo, '页大小:', pageSize);
  887. // 根据当前标签页加载更多数据
  888. switch (this.currentTab) {
  889. case 0:
  890. if (this.hasMoreFollow && !this.isLoadingFollow) {
  891. this.loadFollowList();
  892. } else if (!this.hasMoreFollow && !this.isLoadingFollow && this.followList.length > 0) {
  893. this.showNoMoreDataToast("没有更多关注内容了");
  894. // 通知组件加载完毕且没有更多数据
  895. this.$nextTick(() => {
  896. if (this.$refs.paging) {
  897. this.$refs.paging.complete(this.followList);
  898. }
  899. });
  900. } else if (this.followList.length === 0 && !this.isLoadingFollow) {
  901. this.showNoMoreDataToast("暂无关注内容");
  902. // 通知组件加载完毕且没有数据
  903. this.$nextTick(() => {
  904. if (this.$refs.paging) {
  905. this.$refs.paging.complete([]);
  906. }
  907. });
  908. }
  909. break;
  910. case 1:
  911. if (this.hasMoreRecommend && !this.isLoadingRecommend) {
  912. this.loadRecommendList();
  913. } else if (!this.hasMoreRecommend && !this.isLoadingRecommend && this.recommendList.length > 0) {
  914. this.showNoMoreDataToast("没有更多推荐内容了");
  915. // 通知组件加载完毕且没有更多数据
  916. this.$nextTick(() => {
  917. if (this.$refs.paging) {
  918. this.$refs.paging.complete(this.recommendList);
  919. }
  920. });
  921. } else if (this.recommendList.length === 0 && !this.isLoadingRecommend) {
  922. this.showNoMoreDataToast("暂无推荐内容");
  923. // 通知组件加载完毕且没有数据
  924. this.$nextTick(() => {
  925. if (this.$refs.paging) {
  926. this.$refs.paging.complete([]);
  927. }
  928. });
  929. }
  930. break;
  931. case 2:
  932. if (this.hasMoreNews && !this.isLoadingNews) {
  933. this.loadNewsList();
  934. } else if (!this.hasMoreNews && !this.isLoadingNews && this.newsList.length > 0) {
  935. this.showNoMoreDataToast("没有更多新闻内容了");
  936. // 通知组件加载完毕且没有更多数据
  937. this.$nextTick(() => {
  938. if (this.$refs.paging) {
  939. this.$refs.paging.complete(this.newsList);
  940. }
  941. });
  942. } else if (this.newsList.length === 0 && !this.isLoadingNews) {
  943. this.showNoMoreDataToast("暂无新闻内容");
  944. // 通知组件加载完毕且没有数据
  945. this.$nextTick(() => {
  946. if (this.$refs.paging) {
  947. this.$refs.paging.complete([]);
  948. }
  949. });
  950. }
  951. break;
  952. }
  953. },
  954. // 处理swiper的change事件
  955. handleTabChange(e) {
  956. const current = e.detail.current;
  957. this.switchTab(current);
  958. // 在tab切换后,延迟更新swiper高度
  959. // 切换标签页后,需要给一些时间让内容渲染,然后再更新高度
  960. setTimeout(() => {
  961. this.updateSwiperHeight();
  962. }, 300);
  963. },
  964. // 更新swiper高度方法
  965. updateSwiperHeight() {
  966. const query = uni.createSelectorQuery().in(this);
  967. // 根据当前选中的标签页查询内容高度
  968. let selector = '.follow-list';
  969. if (this.currentTab === 1) {
  970. selector = '.recommend-list';
  971. } else if (this.currentTab === 2) {
  972. selector = '.explore-list';
  973. }
  974. query.select(selector).boundingClientRect(data => {
  975. if (data) {
  976. // 设置最小高度,防止内容过少时swiper太小
  977. let minHeight = uni.getSystemInfoSync().windowHeight * 0.2; // 最小高度为窗口高度的40%
  978. this.swiperHeight = Math.max(data.height, minHeight);
  979. console.log('更新swiper高度:', this.swiperHeight, 'selector:', selector);
  980. }
  981. }).exec();
  982. },
  983. // 首次进入页面初始化数据
  984. initialLoad() {
  985. console.log('初始化数据加载...');
  986. // 根据当前标签页加载初始数据
  987. switch (this.currentTab) {
  988. case 0:
  989. // 重置关注列表
  990. this.followList = [];
  991. this.followOffset = 0;
  992. this.hasMoreFollow = true;
  993. this.loadFollowList();
  994. break;
  995. case 1:
  996. // 重置推荐列表
  997. this.recommendList = [];
  998. this.recommendOffset = 0;
  999. this.hasMoreRecommend = true;
  1000. this.loadRecommendList();
  1001. break;
  1002. case 2:
  1003. // 重置热点新闻和新闻列表
  1004. this.hotNewsList = [];
  1005. this.newsList = [];
  1006. this.newsOffset = 0;
  1007. this.hasMoreNews = true;
  1008. // 加载热点新闻和新闻列表
  1009. this.loadHotNews();
  1010. this.loadNewsList();
  1011. break;
  1012. }
  1013. },
  1014. // 显示没有更多数据的提示,带防抖处理
  1015. showNoMoreDataToast(message) {
  1016. return
  1017. // 如果已经有一个定时器在运行,先清除它
  1018. if (this.noMoreDataTimer) {
  1019. clearTimeout(this.noMoreDataTimer);
  1020. this.noMoreDataTimer = null;
  1021. }
  1022. // 设置新的定时器,防抖处理,1秒内不会重复显示提示
  1023. this.noMoreDataTimer = setTimeout(() => {
  1024. console.log(message);
  1025. uni.showToast({
  1026. title: message,
  1027. icon: 'none',
  1028. duration: 2000
  1029. });
  1030. this.noMoreDataTimer = null;
  1031. }, 1000);
  1032. },
  1033. onImageLoaded() {
  1034. // 图片加载完成后重新计算高度
  1035. // 使用延迟执行,确保所有图片都有时间加载完成
  1036. if (this.updateHeightTimer) {
  1037. clearTimeout(this.updateHeightTimer);
  1038. }
  1039. this.updateHeightTimer = setTimeout(() => {
  1040. this.updateSwiperHeight();
  1041. }, 300);
  1042. },
  1043. },
  1044. };
  1045. </script>
  1046. <style lang="scss">
  1047. @import "index.scss";
  1048. // 添加过渡效果样式
  1049. .fade-enter-active,
  1050. .fade-leave-active {
  1051. transition: opacity 0.3s;
  1052. }
  1053. .fade-enter,
  1054. .fade-leave-to {
  1055. opacity: 0;
  1056. }
  1057. // 确保列表项有最小高度,避免闪烁
  1058. .list-item {
  1059. min-height: 200rpx;
  1060. background: #fff;
  1061. margin-bottom: 20rpx;
  1062. border-radius: 12rpx;
  1063. overflow: hidden;
  1064. }
  1065. // swiper样式
  1066. .tab-content-swiper {
  1067. width: 100%;
  1068. transition: height 0.3s;
  1069. }
  1070. /* 确保内容可以正常显示 */
  1071. .swiper-item {
  1072. height: auto;
  1073. overflow: visible;
  1074. }
  1075. .follow-list,
  1076. .recommend-list,
  1077. .explore-list {
  1078. min-height: 300px;
  1079. }
  1080. </style>
  1081. <style>
  1082. @import "@/style/qweather-icons.css";
  1083. </style>