index.vue 34 KB

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