index.vue 33 KB

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