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