index.vue 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  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. ],
  284. cardList: [ ],
  285. list: [], // 瀑布流全部数据
  286. dataList: [],
  287. tabs: ["关注", "推荐", "探索"],
  288. currentTab: 1,
  289. currentTopicPage: 0,
  290. followList: [], // 关注列表数据
  291. recommendList: [], // 推荐列表数据
  292. exploreList: [], // 探索列表数据
  293. hotNewsList: [], // 热点新闻数据
  294. newsList: [], // 新闻列表数据
  295. followOffset: 0, // 关注列表偏移量
  296. recommendOffset: 0, // 推荐列表偏移量
  297. exploreOffset: 0, // 探索列表偏移量
  298. newsOffset: 0, // 新闻列表偏移量
  299. hasMoreFollow: true, // 是否有更多关注列表数据
  300. hasMoreRecommend: true, // 是否有更多推荐列表数据
  301. hasMoreExplore: true, // 是否有更多探索列表数据
  302. hasMoreNews: true, // 是否有更多新闻列表数据
  303. isLoadingFollow: false, // 是否正在加载关注列表
  304. isLoadingRecommend: false, // 是否正在加载推荐列表
  305. isLoadingExplore: false, // 是否正在加载探索列表
  306. isLoadingNews: false, // 是否正在加载新闻列表
  307. hotTopics: [],
  308. lhSelectCityFalg: false,
  309. hotCitys: [
  310. "杭州",
  311. "天津",
  312. "北京",
  313. "上海",
  314. "深圳",
  315. "广州",
  316. "成都",
  317. "重庆",
  318. "厦门",
  319. ],
  320. currentCity: "北京",
  321. windowHeight: "",
  322. weather: {
  323. city: "",
  324. weather: "",
  325. temp: "0℃",
  326. icon: 101,
  327. },
  328. updateHeightTimer: null,
  329. };
  330. },
  331. computed: {
  332. ...mapState('switchingModule', ['isTheTask']),
  333. ...mapState('rightsManagement', ['teenageMode','iscontentRecommendation']),
  334. ...mapGetters( 'rightsManagement', ['isContent']),
  335. getDayOfWeek() {
  336. const days = [
  337. "星期日",
  338. "星期一",
  339. "星期二",
  340. "星期三",
  341. "星期四",
  342. "星期五",
  343. "星期六",
  344. ];
  345. const today = new Date();
  346. const dayOfWeek = days[today.getDay()];
  347. return dayOfWeek;
  348. },
  349. currentList() {
  350. switch (this.currentTab) {
  351. case 0:
  352. return this.followList;
  353. case 1:
  354. return this.recommendList; // 使用专门的推荐列表
  355. case 2:
  356. return this.exploreList;
  357. default:
  358. return [];
  359. }
  360. },
  361. topicPages() {
  362. const pages = [];
  363. for (let i = 0; i < this.hotTopics.length; i += 4) {
  364. pages.push(this.hotTopics.slice(i, i + 4));
  365. }
  366. return pages;
  367. },
  368. },
  369. onLoad() {
  370. let that = this;
  371. // 计算出可用高度
  372. this.windowHeight = uni.getSystemInfoSync().windowHeight + "px";
  373. // 计算swiper默认高度
  374. const systemInfo = uni.getSystemInfoSync();
  375. this.swiperHeight = systemInfo.windowHeight * 0.6; // 初始设置为窗口高度的60%
  376. // 获取天气信息
  377. this.getWeather();
  378. // 初始化数据,确保首次加载正确
  379. this.$nextTick(() => {
  380. // 根据当前标签加载数据
  381. this.initialLoad();
  382. });
  383. },
  384. onShow() {
  385. console.log('teenageMode',this.teenageMode);
  386. console.log('iscontentRecommendation',this.iscontentRecommendation);
  387. console.log('isContent',this.isContent);
  388. if ( !this.isContent ) {
  389. this.tabs = ["关注"];
  390. this.currentTab = 0;
  391. this.queryList();
  392. } else {
  393. this.tabs = ["关注", "推荐", "探索"];
  394. // this.currentTab = 1;
  395. // 如果数据为空,加载初始数据
  396. if (this.recommendList.length === 0) {
  397. this.initialLoad();
  398. }
  399. }
  400. uni.$emit('check_update');
  401. },
  402. // 修改触底加载方法
  403. onReachBottom() {
  404. console.log('触底加载更多');
  405. // 根据当前标签页加载更多数据
  406. switch (this.currentTab) {
  407. case 0:
  408. if (this.hasMoreFollow && !this.isLoadingFollow) {
  409. this.loadFollowList();
  410. }
  411. break;
  412. case 1:
  413. if (this.hasMoreRecommend && !this.isLoadingRecommend) {
  414. this.loadRecommendList();
  415. }
  416. break;
  417. case 2:
  418. if (this.hasMoreNews && !this.isLoadingNews) {
  419. this.loadNewsList();
  420. }
  421. break;
  422. }
  423. },
  424. // 下拉刷新数据
  425. methods: {
  426. swipeRight() {
  427. let index = this.currentTab
  428. index--
  429. if (index < 0) {
  430. index = this.tabs.length - 1
  431. }
  432. this.switchTab(index)
  433. console.log('向右滑动')
  434. },
  435. swipeLeft() {
  436. let index = this.currentTab
  437. index++
  438. if (index > this.tabs.length - 1) {
  439. index = 0
  440. }
  441. this.switchTab(index)
  442. console.log('向左滑动')
  443. },
  444. getWeather(city) {
  445. uni.request({
  446. url: this.$apiHost + "/Index/getAreaInfo",
  447. data: {
  448. uuid: getApp().globalData.uuid,
  449. skey: getApp().globalData.skey,
  450. city: city || (this.currentCity == "北京" ? "" : this.currentCity),
  451. },
  452. header: {
  453. "content-type": "application/json",
  454. sign: getApp().globalData.headerSign,
  455. },
  456. success: (res) => {
  457. console.log(this.weather, "天气数据", res.data);
  458. if (res.data.data.city) {
  459. this.currentCity = res.data.data.city;
  460. this.weather = res.data.data;
  461. }
  462. },
  463. complete: () => { },
  464. fail: (e) => { },
  465. });
  466. },
  467. lhSelectCityFun() {
  468. this.lhSelectCityFalg = true;
  469. },
  470. // 选中事件
  471. City(city) {
  472. this.currentCity = city;
  473. setTimeout(() => {
  474. this.lhSelectCityFalg = false;
  475. }, 300);
  476. },
  477. closeLhSelectCityFun() {
  478. this.lhSelectCityFalg = false;
  479. },
  480. queryList() {
  481. // 根据当前标签刷新数据
  482. switch (this.currentTab) {
  483. case 0:
  484. // 重置关注列表
  485. this.followList = [];
  486. this.followOffset = 0;
  487. this.hasMoreFollow = true;
  488. this.loadFollowList();
  489. break;
  490. case 1:
  491. // 重置推荐列表
  492. this.recommendList = [];
  493. this.recommendOffset = 0;
  494. this.hasMoreRecommend = true;
  495. this.loadRecommendList();
  496. break;
  497. case 2:
  498. // 重置热点新闻和新闻列表
  499. this.hotNewsList = [];
  500. this.newsList = [];
  501. this.newsOffset = 0;
  502. this.hasMoreNews = true;
  503. // 加载热点新闻和新闻列表
  504. this.loadHotNews();
  505. this.loadNewsList();
  506. break;
  507. }
  508. },
  509. queryLists() {
  510. // 根据当前标签刷新数据
  511. switch (this.currentTab) {
  512. case 0:
  513. // 重置关注列表
  514. this.loadFollowList();
  515. break;
  516. case 1:
  517. // 重置推荐列表
  518. this.loadRecommendList();
  519. break;
  520. case 2:
  521. // 重置热点新闻和新闻列表
  522. // 加载热点新闻和新闻列表
  523. this.loadHotNews();
  524. this.loadNewsList();
  525. break;
  526. }
  527. // 第一次加载完成后,将标记设置为false
  528. this.isFirstLoad = false;
  529. },
  530. switchTab(index) {
  531. if (this.currentTab === index) return;
  532. this.currentTab = index;
  533. // 重置当前标签页的数据
  534. switch (index) {
  535. case 0:
  536. this.followList = [];
  537. this.followOffset = 0;
  538. this.hasMoreFollow = true;
  539. break;
  540. case 1:
  541. this.recommendList = [];
  542. this.recommendOffset = 0;
  543. this.hasMoreRecommend = true;
  544. break;
  545. case 2:
  546. this.newsList = [];
  547. this.hotTopics = [];
  548. this.newsOffset = 0;
  549. this.hasMoreNews = true;
  550. break;
  551. }
  552. // 加载新标签页的数据
  553. this.loadTabData(index);
  554. // 切换标签后更新swiper高度
  555. // 在切换标签时,先将高度设置为一个合适的默认值
  556. // 然后在数据加载完成后再动态调整
  557. const systemInfo = uni.getSystemInfoSync();
  558. this.swiperHeight = systemInfo.windowHeight * 0.6;
  559. },
  560. loadTabData(index) {
  561. switch (index) {
  562. case 0:
  563. this.loadFollowList();
  564. break;
  565. case 1:
  566. this.loadRecommendList();
  567. break;
  568. case 2:
  569. this.loadHotNews();
  570. this.loadNewsList();
  571. break;
  572. }
  573. },
  574. // 修改关注列表加载方法
  575. loadFollowList() {
  576. if (this.isLoadingFollow) return;
  577. this.isLoadingFollow = true;
  578. // 保存当前列表数据
  579. const currentList = [...this.followList];
  580. // offset设置为当前列表长度
  581. this.followOffset = currentList.length;
  582. console.log('请求关注列表数据,当前offset =', this.followOffset);
  583. uni.request({
  584. url: this.$apiHost + "/Work/getlist",
  585. data: {
  586. uuid: getApp().globalData.uuid,
  587. skey: getApp().globalData.skey,
  588. type: "attention",
  589. offset: this.followOffset,
  590. },
  591. header: {
  592. "content-type": "application/json",
  593. sign: getApp().globalData.headerSign,
  594. },
  595. success: (res) => {
  596. console.log("关注列表数据:", res.data);
  597. if (res.data.success == "yes" && res.data.list && res.data.list.length > 0) {
  598. // 追加新数据到列表
  599. this.followList = [...currentList, ...res.data.list];
  600. console.log('关注列表加载成功,当前列表长度:', this.followList.length);
  601. this.hasMoreFollow = res.data.list.length >= 20;
  602. } else {
  603. this.hasMoreFollow = false;
  604. this.showNoMoreDataToast("没有更多关注内容了");
  605. }
  606. // 使用 nextTick 确保数据更新后再通知组件
  607. this.$nextTick(() => {
  608. if (this.$refs.paging) {
  609. // 第一个参数需要是数组,将当前列表传入
  610. this.$refs.paging.complete(this.followList);
  611. }
  612. // 数据加载完成后更新swiper高度
  613. if (this.currentTab === 0) {
  614. // 使用setTimeout确保数据渲染完成后再更新高度
  615. setTimeout(() => {
  616. this.updateSwiperHeight();
  617. }, 300);
  618. setTimeout(() => {
  619. this.updateSwiperHeight();
  620. }, 650);
  621. }
  622. });
  623. },
  624. complete: () => {
  625. this.isLoadingFollow = false;
  626. },
  627. fail: (e) => {
  628. console.log("请求关注列表失败:", e);
  629. this.isLoadingFollow = false;
  630. if (this.$refs.paging) {
  631. // 加载失败时提供空数组
  632. this.$refs.paging.complete([]);
  633. }
  634. },
  635. });
  636. },
  637. // 修改推荐列表加载方法
  638. loadRecommendList() {
  639. if (this.isLoadingRecommend) return;
  640. this.isLoadingRecommend = true;
  641. // 保存当前列表数据
  642. const currentList = [...this.recommendList];
  643. // offset设置为当前列表长度
  644. this.recommendOffset = currentList.length;
  645. console.log('请求推荐列表数据,当前offset =', this.recommendOffset);
  646. uni.request({
  647. url: this.$apiHost + "/Work/getlist",
  648. data: {
  649. uuid: getApp().globalData.uuid,
  650. skey: getApp().globalData.skey,
  651. type: "recommend",
  652. offset: this.recommendOffset,
  653. },
  654. header: {
  655. "content-type": "application/json",
  656. sign: getApp().globalData.headerSign,
  657. },
  658. success: (res) => {
  659. console.log("推荐列表数据:", res.data);
  660. if (res.data.success == "yes" && res.data.list && res.data.list.length > 0) {
  661. // 追加新数据到列表
  662. this.recommendList = [...currentList, ...res.data.list];
  663. console.log('推荐列表加载成功,当前列表长度:', this.recommendList.length);
  664. this.hasMoreRecommend = res.data.list.length >= 20;
  665. } else {
  666. this.hasMoreRecommend = false;
  667. this.showNoMoreDataToast("没有更多推荐内容了");
  668. }
  669. this.$nextTick(() => {
  670. if (this.$refs.paging) {
  671. // 第一个参数需要是数组,将当前列表传入
  672. this.$refs.paging.complete(this.recommendList);
  673. }
  674. // 数据加载完成后更新swiper高度
  675. if (this.currentTab === 1) {
  676. setTimeout(() => {
  677. this.updateSwiperHeight();
  678. }, 300);
  679. setTimeout(() => {
  680. this.updateSwiperHeight();
  681. }, 650);
  682. }
  683. });
  684. },
  685. complete: () => {
  686. this.isLoadingRecommend = false;
  687. },
  688. fail: (e) => {
  689. console.log("请求推荐列表失败:", e);
  690. this.isLoadingRecommend = false;
  691. if (this.$refs.paging) {
  692. // 加载失败时提供空数组
  693. this.$refs.paging.complete([]);
  694. }
  695. },
  696. });
  697. },
  698. loadHotNews() {
  699. if (this.isLoadingExplore) return;
  700. this.isLoadingExplore = true;
  701. uni.request({
  702. url: this.$apiHost + "/Article/getlist",
  703. data: {
  704. uuid: getApp().globalData.uuid,
  705. skey: getApp().globalData.skey,
  706. type: "hot",
  707. },
  708. header: {
  709. "content-type": "application/json",
  710. sign: getApp().globalData.headerSign,
  711. },
  712. success: (res) => {
  713. console.log("热点新闻数据:", res.data);
  714. if (res.data.success == "yes" && res.data.list && res.data.list.length > 0) {
  715. this.hotNewsList = res.data.list;
  716. this.hotTopics = this.hotNewsList.map((item, index) => ({
  717. id: item.id,
  718. title: item.title || "热门话题",
  719. num_like: item.num_like || 0,
  720. isHot: index % 2 === 0,
  721. }));
  722. }
  723. },
  724. complete: () => {
  725. this.isLoadingExplore = false;
  726. },
  727. fail: (e) => {
  728. console.log("请求热点新闻失败:", e);
  729. this.isLoadingExplore = false;
  730. },
  731. });
  732. },
  733. // 修改新闻列表加载方法
  734. loadNewsList() {
  735. if (this.isLoadingNews) return;
  736. this.isLoadingNews = true;
  737. // 保存当前列表数据
  738. const currentList = [...this.newsList];
  739. // offset设置为当前列表长度
  740. this.newsOffset = currentList.length;
  741. console.log('请求新闻列表数据,当前offset =', this.newsOffset);
  742. uni.request({
  743. url: this.$apiHost + "/Article/getlist",
  744. data: {
  745. uuid: getApp().globalData.uuid,
  746. skey: getApp().globalData.skey,
  747. type: "list",
  748. offset: this.newsOffset,
  749. },
  750. header: {
  751. "content-type": "application/json",
  752. sign: getApp().globalData.headerSign,
  753. },
  754. success: (res) => {
  755. console.log("新闻列表数据:", res.data);
  756. if (res.data.success == "yes" && res.data.list && res.data.list.length > 0) {
  757. // 追加新数据到列表
  758. this.newsList = [...currentList, ...res.data.list];
  759. console.log('新闻列表加载成功,当前列表长度:', this.newsList.length);
  760. this.hasMoreNews = res.data.list.length >= 20;
  761. } else {
  762. this.hasMoreNews = false;
  763. this.showNoMoreDataToast("没有更多新闻内容了");
  764. }
  765. this.$nextTick(() => {
  766. if (this.$refs.paging) {
  767. // 第一个参数需要是数组,将当前列表传入
  768. this.$refs.paging.complete(this.newsList);
  769. }
  770. // 数据加载完成后更新swiper高度
  771. if (this.currentTab === 2) {
  772. setTimeout(() => {
  773. this.updateSwiperHeight();
  774. }, 300);
  775. setTimeout(() => {
  776. this.updateSwiperHeight();
  777. }, 650);
  778. }
  779. });
  780. },
  781. complete: () => {
  782. this.isLoadingNews = false;
  783. },
  784. fail: (e) => {
  785. console.log("请求新闻列表失败:", e);
  786. this.isLoadingNews = false;
  787. if (this.$refs.paging) {
  788. // 加载失败时提供空数组
  789. this.$refs.paging.complete([]);
  790. }
  791. },
  792. });
  793. },
  794. handleTopicPageChange(e) {
  795. this.currentTopicPage = e.detail.current;
  796. },
  797. formatItem(item) {
  798. console.log("item:", item);
  799. let img = "";
  800. if (item.images) {
  801. img = item.images.split("|")[0];
  802. }
  803. // 处理接口返回的数据,使其适配card组件
  804. return {
  805. id: item.id,
  806. allowEdit: false,
  807. nickname: item.nickname,
  808. avator: item.avator,
  809. num_like: item.num_like,
  810. num_view: item.num_view,
  811. image: img || item.img_url || item.image, // 优先使用images字段
  812. w: item.width,
  813. h: item.height,
  814. title: item.title || "",
  815. desc: item.desc || "",
  816. userID: item.userID || 0,
  817. backgroundColor: "#f6f6f6",
  818. };
  819. },
  820. goToArticleDetail(id) {
  821. if (!id) {
  822. uni.showToast({
  823. title: "文章ID不存在",
  824. icon: "none",
  825. });
  826. return;
  827. }
  828. // uni.$emit("check_login", () => {
  829. uni.navigateTo({
  830. url: "/pages/index/articleDetail?id=" + id,
  831. });
  832. // });
  833. },
  834. goWork(item) {
  835. console.log("skeylogin", "xxx");
  836. uni.$emit("check_login", () => {
  837. uni.navigateTo({
  838. url: "/pages/index/workDetail?id=" + item.id,
  839. });
  840. });
  841. },
  842. goToMake() {
  843. console.log("skeylogin", "xxx2");
  844. uni.$emit("check_login", () => {
  845. uni.navigateTo({
  846. // 生成个人形象
  847. // url: "/pages/make/make",
  848. url: "/pages/make/fabuArticle?id=-1",
  849. });
  850. });
  851. },
  852. goPage(page) {
  853. uni.$emit("check_login", () => {
  854. uni.navigateTo({
  855. url: page,
  856. });
  857. });
  858. },
  859. // 修改下拉刷新方法
  860. onRefresh() {
  861. console.log('下拉刷新开始');
  862. // 重置所有数据
  863. this.followList = [];
  864. this.recommendList = [];
  865. this.newsList = [];
  866. this.hotTopics = [];
  867. // 重置偏移量
  868. this.followOffset = 0;
  869. this.recommendOffset = 0;
  870. this.newsOffset = 0;
  871. // 重置加载状态
  872. this.hasMoreFollow = true;
  873. this.hasMoreRecommend = true;
  874. this.hasMoreNews = true;
  875. // 根据当前标签页加载数据
  876. this.loadTabData(this.currentTab);
  877. },
  878. // 下拉刷新恢复
  879. onRefresherRestore() {
  880. console.log('下拉刷新恢复');
  881. },
  882. // 处理z-paging的触底加载更多事件
  883. onZPagingLoadMore(pageNo, pageSize) {
  884. console.log('触底加载更多, 页码:', pageNo, '页大小:', pageSize);
  885. // 根据当前标签页加载更多数据
  886. switch (this.currentTab) {
  887. case 0:
  888. if (this.hasMoreFollow && !this.isLoadingFollow) {
  889. this.loadFollowList();
  890. } else if (!this.hasMoreFollow && !this.isLoadingFollow && this.followList.length > 0) {
  891. this.showNoMoreDataToast("没有更多关注内容了");
  892. // 通知组件加载完毕且没有更多数据
  893. this.$nextTick(() => {
  894. if (this.$refs.paging) {
  895. this.$refs.paging.complete(this.followList);
  896. }
  897. });
  898. } else if (this.followList.length === 0 && !this.isLoadingFollow) {
  899. this.showNoMoreDataToast("暂无关注内容");
  900. // 通知组件加载完毕且没有数据
  901. this.$nextTick(() => {
  902. if (this.$refs.paging) {
  903. this.$refs.paging.complete([]);
  904. }
  905. });
  906. }
  907. break;
  908. case 1:
  909. if (this.hasMoreRecommend && !this.isLoadingRecommend) {
  910. this.loadRecommendList();
  911. } else if (!this.hasMoreRecommend && !this.isLoadingRecommend && this.recommendList.length > 0) {
  912. this.showNoMoreDataToast("没有更多推荐内容了");
  913. // 通知组件加载完毕且没有更多数据
  914. this.$nextTick(() => {
  915. if (this.$refs.paging) {
  916. this.$refs.paging.complete(this.recommendList);
  917. }
  918. });
  919. } else if (this.recommendList.length === 0 && !this.isLoadingRecommend) {
  920. this.showNoMoreDataToast("暂无推荐内容");
  921. // 通知组件加载完毕且没有数据
  922. this.$nextTick(() => {
  923. if (this.$refs.paging) {
  924. this.$refs.paging.complete([]);
  925. }
  926. });
  927. }
  928. break;
  929. case 2:
  930. if (this.hasMoreNews && !this.isLoadingNews) {
  931. this.loadNewsList();
  932. } else if (!this.hasMoreNews && !this.isLoadingNews && this.newsList.length > 0) {
  933. this.showNoMoreDataToast("没有更多新闻内容了");
  934. // 通知组件加载完毕且没有更多数据
  935. this.$nextTick(() => {
  936. if (this.$refs.paging) {
  937. this.$refs.paging.complete(this.newsList);
  938. }
  939. });
  940. } else if (this.newsList.length === 0 && !this.isLoadingNews) {
  941. this.showNoMoreDataToast("暂无新闻内容");
  942. // 通知组件加载完毕且没有数据
  943. this.$nextTick(() => {
  944. if (this.$refs.paging) {
  945. this.$refs.paging.complete([]);
  946. }
  947. });
  948. }
  949. break;
  950. }
  951. },
  952. // 处理swiper的change事件
  953. handleTabChange(e) {
  954. const current = e.detail.current;
  955. this.switchTab(current);
  956. // 在tab切换后,延迟更新swiper高度
  957. // 切换标签页后,需要给一些时间让内容渲染,然后再更新高度
  958. setTimeout(() => {
  959. this.updateSwiperHeight();
  960. }, 300);
  961. },
  962. // 更新swiper高度方法
  963. updateSwiperHeight() {
  964. const query = uni.createSelectorQuery().in(this);
  965. // 根据当前选中的标签页查询内容高度
  966. let selector = '.follow-list';
  967. if (this.currentTab === 1) {
  968. selector = '.recommend-list';
  969. } else if (this.currentTab === 2) {
  970. selector = '.explore-list';
  971. }
  972. query.select(selector).boundingClientRect(data => {
  973. if (data) {
  974. // 设置最小高度,防止内容过少时swiper太小
  975. let minHeight = uni.getSystemInfoSync().windowHeight * 0.2; // 最小高度为窗口高度的40%
  976. this.swiperHeight = Math.max(data.height, minHeight);
  977. console.log('更新swiper高度:', this.swiperHeight, 'selector:', selector);
  978. }
  979. }).exec();
  980. },
  981. // 首次进入页面初始化数据
  982. initialLoad() {
  983. console.log('初始化数据加载...');
  984. // 根据当前标签页加载初始数据
  985. switch (this.currentTab) {
  986. case 0:
  987. // 重置关注列表
  988. this.followList = [];
  989. this.followOffset = 0;
  990. this.hasMoreFollow = true;
  991. this.loadFollowList();
  992. break;
  993. case 1:
  994. // 重置推荐列表
  995. this.recommendList = [];
  996. this.recommendOffset = 0;
  997. this.hasMoreRecommend = true;
  998. this.loadRecommendList();
  999. break;
  1000. case 2:
  1001. // 重置热点新闻和新闻列表
  1002. this.hotNewsList = [];
  1003. this.newsList = [];
  1004. this.newsOffset = 0;
  1005. this.hasMoreNews = true;
  1006. // 加载热点新闻和新闻列表
  1007. this.loadHotNews();
  1008. this.loadNewsList();
  1009. break;
  1010. }
  1011. },
  1012. // 显示没有更多数据的提示,带防抖处理
  1013. showNoMoreDataToast(message) {
  1014. return
  1015. // 如果已经有一个定时器在运行,先清除它
  1016. if (this.noMoreDataTimer) {
  1017. clearTimeout(this.noMoreDataTimer);
  1018. this.noMoreDataTimer = null;
  1019. }
  1020. // 设置新的定时器,防抖处理,1秒内不会重复显示提示
  1021. this.noMoreDataTimer = setTimeout(() => {
  1022. console.log(message);
  1023. uni.showToast({
  1024. title: message,
  1025. icon: 'none',
  1026. duration: 2000
  1027. });
  1028. this.noMoreDataTimer = null;
  1029. }, 1000);
  1030. },
  1031. onImageLoaded() {
  1032. // 图片加载完成后重新计算高度
  1033. // 使用延迟执行,确保所有图片都有时间加载完成
  1034. if (this.updateHeightTimer) {
  1035. clearTimeout(this.updateHeightTimer);
  1036. }
  1037. this.updateHeightTimer = setTimeout(() => {
  1038. this.updateSwiperHeight();
  1039. }, 300);
  1040. },
  1041. },
  1042. };
  1043. </script>
  1044. <style lang="scss">
  1045. @import "index.scss";
  1046. // 添加过渡效果样式
  1047. .fade-enter-active,
  1048. .fade-leave-active {
  1049. transition: opacity 0.3s;
  1050. }
  1051. .fade-enter,
  1052. .fade-leave-to {
  1053. opacity: 0;
  1054. }
  1055. // 确保列表项有最小高度,避免闪烁
  1056. .list-item {
  1057. min-height: 200rpx;
  1058. background: #fff;
  1059. margin-bottom: 20rpx;
  1060. border-radius: 12rpx;
  1061. overflow: hidden;
  1062. }
  1063. // swiper样式
  1064. .tab-content-swiper {
  1065. width: 100%;
  1066. transition: height 0.3s;
  1067. }
  1068. /* 确保内容可以正常显示 */
  1069. .swiper-item {
  1070. height: auto;
  1071. overflow: visible;
  1072. }
  1073. .follow-list,
  1074. .recommend-list,
  1075. .explore-list {
  1076. min-height: 300px;
  1077. }
  1078. </style>
  1079. <style>
  1080. @import "@/style/qweather-icons.css";
  1081. </style>