index.vue 28 KB

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