index.vue 31 KB

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