index.vue 34 KB

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