index.vue 33 KB

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