index.vue 28 KB

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