index copy.vue 28 KB

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