index.vue 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  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. image: "../../static/home/home-swper2.png",
  289. url: `/pages/webview/index?url=https://e.zhichao.art/web/czgy.php&title=创作公约`,
  290. },
  291. ],
  292. cardList: [],
  293. list: [], // 瀑布流全部数据
  294. dataList: [],
  295. tabs: ["关注", "推荐", "探索"],
  296. currentTab: 1,
  297. currentTopicPage: 0,
  298. followList: [], // 关注列表数据
  299. recommendList: [], // 推荐列表数据
  300. exploreList: [], // 探索列表数据
  301. hotNewsList: [], // 热点新闻数据
  302. newsList: [], // 新闻列表数据
  303. followOffset: 0, // 关注列表偏移量
  304. recommendOffset: 0, // 推荐列表偏移量
  305. exploreOffset: 0, // 探索列表偏移量
  306. newsOffset: 0, // 新闻列表偏移量
  307. hasMoreFollow: true, // 是否有更多关注列表数据
  308. hasMoreRecommend: true, // 是否有更多推荐列表数据
  309. hasMoreExplore: true, // 是否有更多探索列表数据
  310. hasMoreNews: true, // 是否有更多新闻列表数据
  311. isLoadingFollow: false, // 是否正在加载关注列表
  312. isLoadingRecommend: false, // 是否正在加载推荐列表
  313. isLoadingExplore: false, // 是否正在加载探索列表
  314. isLoadingNews: false, // 是否正在加载新闻列表
  315. hotTopics: [],
  316. lhSelectCityFalg: false,
  317. hotCitys: [
  318. "杭州",
  319. "天津",
  320. "北京",
  321. "上海",
  322. "深圳",
  323. "广州",
  324. "成都",
  325. "重庆",
  326. "厦门",
  327. ],
  328. currentCity: "北京",
  329. windowHeight: "",
  330. weather: {
  331. city: "",
  332. weather: "",
  333. temp: "0℃",
  334. icon: 101,
  335. },
  336. updateHeightTimer: null,
  337. };
  338. },
  339. computed: {
  340. ...mapState('switchingModule', ['isTheTask']),
  341. ...mapState('rightsManagement', ['teenageMode', 'iscontentRecommendation']),
  342. ...mapGetters('rightsManagement', ['isContent']),
  343. getDayOfWeek() {
  344. const days = [
  345. "星期日",
  346. "星期一",
  347. "星期二",
  348. "星期三",
  349. "星期四",
  350. "星期五",
  351. "星期六",
  352. ];
  353. const today = new Date();
  354. const dayOfWeek = days[today.getDay()];
  355. return dayOfWeek;
  356. },
  357. currentList() {
  358. switch (this.currentTab) {
  359. case 0:
  360. return this.followList;
  361. case 1:
  362. return this.recommendList; // 使用专门的推荐列表
  363. case 2:
  364. return this.exploreList;
  365. default:
  366. return [];
  367. }
  368. },
  369. topicPages() {
  370. const pages = [];
  371. for (let i = 0; i < this.hotTopics.length; i += 4) {
  372. pages.push(this.hotTopics.slice(i, i + 4));
  373. }
  374. return pages;
  375. },
  376. },
  377. onLoad() {
  378. let that = this;
  379. // 计算出可用高度
  380. this.windowHeight = uni.getSystemInfoSync().windowHeight + "px";
  381. // 计算swiper默认高度
  382. const systemInfo = uni.getSystemInfoSync();
  383. this.swiperHeight = systemInfo.windowHeight * 0.6; // 初始设置为窗口高度的60%
  384. // 获取天气信息
  385. this.getWeather();
  386. // 初始化数据,确保首次加载正确
  387. this.$nextTick(() => {
  388. // 根据当前标签加载数据
  389. this.initialLoad();
  390. });
  391. },
  392. onShow() {
  393. console.log('teenageMode', this.teenageMode);
  394. console.log('iscontentRecommendation', this.iscontentRecommendation);
  395. console.log('isContent', this.isContent);
  396. if (!this.isContent) {
  397. this.tabs = ["关注"];
  398. this.currentTab = 0;
  399. this.queryList();
  400. } else {
  401. this.tabs = ["关注", "推荐", "探索"];
  402. // this.currentTab = 1;
  403. // 如果数据为空,加载初始数据
  404. if (this.recommendList.length === 0) {
  405. this.initialLoad();
  406. }
  407. }
  408. uni.$emit('check_update');
  409. },
  410. // 修改触底加载方法
  411. onReachBottom() {
  412. console.log('触底加载更多');
  413. // 根据当前标签页加载更多数据
  414. switch (this.currentTab) {
  415. case 0:
  416. if (this.hasMoreFollow && !this.isLoadingFollow) {
  417. this.loadFollowList();
  418. }
  419. break;
  420. case 1:
  421. if (this.hasMoreRecommend && !this.isLoadingRecommend) {
  422. this.loadRecommendList();
  423. }
  424. break;
  425. case 2:
  426. if (this.hasMoreNews && !this.isLoadingNews) {
  427. this.loadNewsList();
  428. }
  429. break;
  430. }
  431. },
  432. // 下拉刷新数据
  433. methods: {
  434. swipeRight() {
  435. let index = this.currentTab
  436. index--
  437. if (index < 0) {
  438. index = this.tabs.length - 1
  439. }
  440. this.switchTab(index)
  441. console.log('向右滑动')
  442. },
  443. swipeLeft() {
  444. let index = this.currentTab
  445. index++
  446. if (index > this.tabs.length - 1) {
  447. index = 0
  448. }
  449. this.switchTab(index)
  450. console.log('向左滑动')
  451. },
  452. getWeather(city) {
  453. uni.request({
  454. url: this.$apiHost + "/Index/getAreaInfo",
  455. data: {
  456. uuid: getApp().globalData.uuid,
  457. skey: getApp().globalData.skey,
  458. city: city || (this.currentCity == "北京" ? "" : this.currentCity),
  459. },
  460. header: {
  461. "content-type": "application/json",
  462. sign: getApp().globalData.headerSign,
  463. },
  464. success: (res) => {
  465. console.log(this.weather, "天气数据", res.data);
  466. if (res.data.data.city) {
  467. this.currentCity = res.data.data.city;
  468. this.weather = res.data.data;
  469. }
  470. },
  471. complete: () => { },
  472. fail: (e) => { },
  473. });
  474. },
  475. lhSelectCityFun() {
  476. this.lhSelectCityFalg = true;
  477. },
  478. // 选中事件
  479. City(city) {
  480. this.currentCity = city;
  481. setTimeout(() => {
  482. this.lhSelectCityFalg = false;
  483. }, 300);
  484. },
  485. closeLhSelectCityFun() {
  486. this.lhSelectCityFalg = false;
  487. },
  488. queryList() {
  489. // 根据当前标签刷新数据
  490. switch (this.currentTab) {
  491. case 0:
  492. // 重置关注列表
  493. this.followList = [];
  494. this.followOffset = 0;
  495. this.hasMoreFollow = true;
  496. this.loadFollowList();
  497. break;
  498. case 1:
  499. // 重置推荐列表
  500. this.recommendList = [];
  501. this.recommendOffset = 0;
  502. this.hasMoreRecommend = true;
  503. this.loadRecommendList();
  504. break;
  505. case 2:
  506. // 重置热点新闻和新闻列表
  507. this.hotNewsList = [];
  508. this.newsList = [];
  509. this.newsOffset = 0;
  510. this.hasMoreNews = true;
  511. // 加载热点新闻和新闻列表
  512. this.loadHotNews();
  513. this.loadNewsList();
  514. break;
  515. }
  516. },
  517. queryLists() {
  518. // 根据当前标签刷新数据
  519. switch (this.currentTab) {
  520. case 0:
  521. // 重置关注列表
  522. this.loadFollowList();
  523. break;
  524. case 1:
  525. // 重置推荐列表
  526. this.loadRecommendList();
  527. break;
  528. case 2:
  529. // 重置热点新闻和新闻列表
  530. // 加载热点新闻和新闻列表
  531. this.loadHotNews();
  532. this.loadNewsList();
  533. break;
  534. }
  535. // 第一次加载完成后,将标记设置为false
  536. this.isFirstLoad = false;
  537. },
  538. switchTab(index) {
  539. if (this.currentTab === index) return;
  540. this.currentTab = index;
  541. // 重置当前标签页的数据
  542. switch (index) {
  543. case 0:
  544. this.followList = [];
  545. this.followOffset = 0;
  546. this.hasMoreFollow = true;
  547. break;
  548. case 1:
  549. this.recommendList = [];
  550. this.recommendOffset = 0;
  551. this.hasMoreRecommend = true;
  552. break;
  553. case 2:
  554. this.newsList = [];
  555. this.hotTopics = [];
  556. this.newsOffset = 0;
  557. this.hasMoreNews = true;
  558. break;
  559. }
  560. // 加载新标签页的数据
  561. this.loadTabData(index);
  562. // 切换标签后更新swiper高度
  563. // 在切换标签时,先将高度设置为一个合适的默认值
  564. // 然后在数据加载完成后再动态调整
  565. const systemInfo = uni.getSystemInfoSync();
  566. this.swiperHeight = systemInfo.windowHeight * 0.6;
  567. },
  568. loadTabData(index) {
  569. switch (index) {
  570. case 0:
  571. this.loadFollowList();
  572. break;
  573. case 1:
  574. this.loadRecommendList();
  575. break;
  576. case 2:
  577. this.loadHotNews();
  578. this.loadNewsList();
  579. break;
  580. }
  581. },
  582. // 修改关注列表加载方法
  583. loadFollowList() {
  584. if (this.isLoadingFollow) return;
  585. this.isLoadingFollow = true;
  586. // 保存当前列表数据
  587. const currentList = [...this.followList];
  588. // offset设置为当前列表长度
  589. this.followOffset = currentList.length;
  590. console.log('请求关注列表数据,当前offset =', this.followOffset);
  591. uni.request({
  592. url: this.$apiHost + "/Work/getlist",
  593. data: {
  594. uuid: getApp().globalData.uuid,
  595. skey: getApp().globalData.skey,
  596. type: "attention",
  597. offset: this.followOffset,
  598. },
  599. header: {
  600. "content-type": "application/json",
  601. sign: getApp().globalData.headerSign,
  602. },
  603. success: (res) => {
  604. console.log("关注列表数据:", res.data);
  605. if (res.data.success == "yes" && res.data.list && res.data.list.length > 0) {
  606. // 追加新数据到列表
  607. this.followList = [...currentList, ...res.data.list];
  608. console.log('关注列表加载成功,当前列表长度:', this.followList.length);
  609. this.hasMoreFollow = res.data.list.length >= 20;
  610. } else {
  611. this.hasMoreFollow = false;
  612. this.showNoMoreDataToast("没有更多关注内容了");
  613. }
  614. // 使用 nextTick 确保数据更新后再通知组件
  615. this.$nextTick(() => {
  616. if (this.$refs.paging) {
  617. // 第一个参数需要是数组,将当前列表传入
  618. this.$refs.paging.complete(this.followList);
  619. }
  620. // 数据加载完成后更新swiper高度
  621. if (this.currentTab === 0) {
  622. // 使用setTimeout确保数据渲染完成后再更新高度
  623. setTimeout(() => {
  624. this.updateSwiperHeight();
  625. }, 300);
  626. setTimeout(() => {
  627. this.updateSwiperHeight();
  628. }, 650);
  629. }
  630. });
  631. },
  632. complete: () => {
  633. this.isLoadingFollow = false;
  634. },
  635. fail: (e) => {
  636. console.log("请求关注列表失败:", e);
  637. this.isLoadingFollow = false;
  638. if (this.$refs.paging) {
  639. // 加载失败时提供空数组
  640. this.$refs.paging.complete([]);
  641. }
  642. },
  643. });
  644. },
  645. // 修改推荐列表加载方法
  646. loadRecommendList() {
  647. if (this.isLoadingRecommend) return;
  648. this.isLoadingRecommend = true;
  649. // 保存当前列表数据
  650. const currentList = [...this.recommendList];
  651. // offset设置为当前列表长度
  652. this.recommendOffset = currentList.length;
  653. console.log('请求推荐列表数据,当前offset =', this.recommendOffset);
  654. uni.request({
  655. url: this.$apiHost + "/Work/getlist",
  656. data: {
  657. uuid: getApp().globalData.uuid,
  658. skey: getApp().globalData.skey,
  659. type: "recommend",
  660. offset: this.recommendOffset,
  661. },
  662. header: {
  663. "content-type": "application/json",
  664. sign: getApp().globalData.headerSign,
  665. },
  666. success: (res) => {
  667. console.log("推荐列表数据:", res.data);
  668. if (res.data.success == "yes" && res.data.list && res.data.list.length > 0) {
  669. // 追加新数据到列表
  670. this.recommendList = [...currentList, ...res.data.list];
  671. console.log('推荐列表加载成功,当前列表长度:', this.recommendList.length);
  672. this.hasMoreRecommend = res.data.list.length >= 20;
  673. } else {
  674. this.hasMoreRecommend = false;
  675. this.showNoMoreDataToast("没有更多推荐内容了");
  676. }
  677. this.$nextTick(() => {
  678. if (this.$refs.paging) {
  679. // 第一个参数需要是数组,将当前列表传入
  680. this.$refs.paging.complete(this.recommendList);
  681. }
  682. // 数据加载完成后更新swiper高度
  683. if (this.currentTab === 1) {
  684. setTimeout(() => {
  685. this.updateSwiperHeight();
  686. }, 300);
  687. setTimeout(() => {
  688. this.updateSwiperHeight();
  689. }, 650);
  690. }
  691. });
  692. },
  693. complete: () => {
  694. this.isLoadingRecommend = false;
  695. },
  696. fail: (e) => {
  697. console.log("请求推荐列表失败:", e);
  698. this.isLoadingRecommend = false;
  699. if (this.$refs.paging) {
  700. // 加载失败时提供空数组
  701. this.$refs.paging.complete([]);
  702. }
  703. },
  704. });
  705. },
  706. loadHotNews() {
  707. if (this.isLoadingExplore) return;
  708. this.isLoadingExplore = true;
  709. uni.request({
  710. url: this.$apiHost + "/Article/getlist",
  711. data: {
  712. uuid: getApp().globalData.uuid,
  713. skey: getApp().globalData.skey,
  714. type: "hot",
  715. },
  716. header: {
  717. "content-type": "application/json",
  718. sign: getApp().globalData.headerSign,
  719. },
  720. success: (res) => {
  721. console.log("热点新闻数据:", res.data);
  722. if (res.data.success == "yes" && res.data.list && res.data.list.length > 0) {
  723. this.hotNewsList = res.data.list;
  724. this.hotTopics = this.hotNewsList.map((item, index) => ({
  725. id: item.id,
  726. title: item.title || "热门话题",
  727. num_like: item.num_like || 0,
  728. isHot: index % 2 === 0,
  729. }));
  730. }
  731. },
  732. complete: () => {
  733. this.isLoadingExplore = false;
  734. },
  735. fail: (e) => {
  736. console.log("请求热点新闻失败:", e);
  737. this.isLoadingExplore = false;
  738. },
  739. });
  740. },
  741. // 修改新闻列表加载方法
  742. loadNewsList() {
  743. if (this.isLoadingNews) return;
  744. this.isLoadingNews = true;
  745. // 保存当前列表数据
  746. const currentList = [...this.newsList];
  747. // offset设置为当前列表长度
  748. this.newsOffset = currentList.length;
  749. console.log('请求新闻列表数据,当前offset =', this.newsOffset);
  750. uni.request({
  751. url: this.$apiHost + "/Article/getlist",
  752. data: {
  753. uuid: getApp().globalData.uuid,
  754. skey: getApp().globalData.skey,
  755. type: "list",
  756. offset: this.newsOffset,
  757. },
  758. header: {
  759. "content-type": "application/json",
  760. sign: getApp().globalData.headerSign,
  761. },
  762. success: (res) => {
  763. console.log("新闻列表数据:", res.data);
  764. if (res.data.success == "yes" && res.data.list && res.data.list.length > 0) {
  765. // 追加新数据到列表
  766. this.newsList = [...currentList, ...res.data.list];
  767. console.log('新闻列表加载成功,当前列表长度:', this.newsList.length);
  768. this.hasMoreNews = res.data.list.length >= 20;
  769. } else {
  770. this.hasMoreNews = false;
  771. this.showNoMoreDataToast("没有更多新闻内容了");
  772. }
  773. this.$nextTick(() => {
  774. if (this.$refs.paging) {
  775. // 第一个参数需要是数组,将当前列表传入
  776. this.$refs.paging.complete(this.newsList);
  777. }
  778. // 数据加载完成后更新swiper高度
  779. if (this.currentTab === 2) {
  780. setTimeout(() => {
  781. this.updateSwiperHeight();
  782. }, 300);
  783. setTimeout(() => {
  784. this.updateSwiperHeight();
  785. }, 650);
  786. }
  787. });
  788. },
  789. complete: () => {
  790. this.isLoadingNews = false;
  791. },
  792. fail: (e) => {
  793. console.log("请求新闻列表失败:", e);
  794. this.isLoadingNews = false;
  795. if (this.$refs.paging) {
  796. // 加载失败时提供空数组
  797. this.$refs.paging.complete([]);
  798. }
  799. },
  800. });
  801. },
  802. handleTopicPageChange(e) {
  803. this.currentTopicPage = e.detail.current;
  804. },
  805. formatItem(item) {
  806. // console.log("item:", item);
  807. let img = "";
  808. if (item.images) {
  809. img = item.images.split("|")[0];
  810. }
  811. // 处理接口返回的数据,使其适配card组件
  812. return {
  813. id: item.id,
  814. allowEdit: false,
  815. nickname: item.nickname,
  816. avator: item.avator,
  817. num_like: item.num_like,
  818. num_view: item.num_view,
  819. image: img || item.img_url || item.image, // 优先使用images字段
  820. w: item.width,
  821. h: item.height,
  822. title: item.title || "",
  823. desc: item.desc || "",
  824. userID: item.userID || 0,
  825. backgroundColor: "#f6f6f6",
  826. };
  827. },
  828. goToArticleDetail(id) {
  829. if (!id) {
  830. uni.showToast({
  831. title: "文章ID不存在",
  832. icon: "none",
  833. });
  834. return;
  835. }
  836. // uni.$emit("check_login", () => {
  837. uni.navigateTo({
  838. url: "/pages/index/articleDetail?id=" + id,
  839. });
  840. // });
  841. },
  842. goWork(item) {
  843. console.log("skeylogin", "xxx");
  844. uni.$emit("check_login", () => {
  845. uni.navigateTo({
  846. url: "/pages/index/workDetail?id=" + item.id,
  847. });
  848. });
  849. },
  850. goToMake() {
  851. console.log("skeylogin", "xxx2");
  852. uni.$emit("check_login", () => {
  853. uni.navigateTo({
  854. // 生成个人形象
  855. // url: "/pages/make/make",
  856. url: "/pages/make/fabuArticle?id=-1",
  857. });
  858. });
  859. },
  860. goPage(page) {
  861. uni.$emit("check_login", () => {
  862. uni.navigateTo({
  863. url: page,
  864. });
  865. });
  866. },
  867. // 修改下拉刷新方法
  868. onRefresh() {
  869. console.log('下拉刷新开始');
  870. // 重置所有数据
  871. this.followList = [];
  872. this.recommendList = [];
  873. this.newsList = [];
  874. this.hotTopics = [];
  875. // 重置偏移量
  876. this.followOffset = 0;
  877. this.recommendOffset = 0;
  878. this.newsOffset = 0;
  879. // 重置加载状态
  880. this.hasMoreFollow = true;
  881. this.hasMoreRecommend = true;
  882. this.hasMoreNews = true;
  883. // 根据当前标签页加载数据
  884. this.loadTabData(this.currentTab);
  885. },
  886. // 下拉刷新恢复
  887. onRefresherRestore() {
  888. console.log('下拉刷新恢复');
  889. },
  890. // 处理z-paging的触底加载更多事件
  891. onZPagingLoadMore(pageNo, pageSize) {
  892. console.log('触底加载更多, 页码:', pageNo, '页大小:', pageSize);
  893. // 根据当前标签页加载更多数据
  894. switch (this.currentTab) {
  895. case 0:
  896. if (this.hasMoreFollow && !this.isLoadingFollow) {
  897. this.loadFollowList();
  898. } else if (!this.hasMoreFollow && !this.isLoadingFollow && this.followList.length > 0) {
  899. this.showNoMoreDataToast("没有更多关注内容了");
  900. // 通知组件加载完毕且没有更多数据
  901. this.$nextTick(() => {
  902. if (this.$refs.paging) {
  903. this.$refs.paging.complete(this.followList);
  904. }
  905. });
  906. } else if (this.followList.length === 0 && !this.isLoadingFollow) {
  907. this.showNoMoreDataToast("暂无关注内容");
  908. // 通知组件加载完毕且没有数据
  909. this.$nextTick(() => {
  910. if (this.$refs.paging) {
  911. this.$refs.paging.complete([]);
  912. }
  913. });
  914. }
  915. break;
  916. case 1:
  917. if (this.hasMoreRecommend && !this.isLoadingRecommend) {
  918. this.loadRecommendList();
  919. } else if (!this.hasMoreRecommend && !this.isLoadingRecommend && this.recommendList.length > 0) {
  920. this.showNoMoreDataToast("没有更多推荐内容了");
  921. // 通知组件加载完毕且没有更多数据
  922. this.$nextTick(() => {
  923. if (this.$refs.paging) {
  924. this.$refs.paging.complete(this.recommendList);
  925. }
  926. });
  927. } else if (this.recommendList.length === 0 && !this.isLoadingRecommend) {
  928. this.showNoMoreDataToast("暂无推荐内容");
  929. // 通知组件加载完毕且没有数据
  930. this.$nextTick(() => {
  931. if (this.$refs.paging) {
  932. this.$refs.paging.complete([]);
  933. }
  934. });
  935. }
  936. break;
  937. case 2:
  938. if (this.hasMoreNews && !this.isLoadingNews) {
  939. this.loadNewsList();
  940. } else if (!this.hasMoreNews && !this.isLoadingNews && this.newsList.length > 0) {
  941. this.showNoMoreDataToast("没有更多新闻内容了");
  942. // 通知组件加载完毕且没有更多数据
  943. this.$nextTick(() => {
  944. if (this.$refs.paging) {
  945. this.$refs.paging.complete(this.newsList);
  946. }
  947. });
  948. } else if (this.newsList.length === 0 && !this.isLoadingNews) {
  949. this.showNoMoreDataToast("暂无新闻内容");
  950. // 通知组件加载完毕且没有数据
  951. this.$nextTick(() => {
  952. if (this.$refs.paging) {
  953. this.$refs.paging.complete([]);
  954. }
  955. });
  956. }
  957. break;
  958. }
  959. },
  960. // 处理swiper的change事件
  961. handleTabChange(e) {
  962. const current = e.detail.current;
  963. this.switchTab(current);
  964. // 在tab切换后,延迟更新swiper高度
  965. // 切换标签页后,需要给一些时间让内容渲染,然后再更新高度
  966. setTimeout(() => {
  967. this.updateSwiperHeight();
  968. }, 300);
  969. },
  970. // 更新swiper高度方法
  971. updateSwiperHeight() {
  972. const query = uni.createSelectorQuery().in(this);
  973. // 根据当前选中的标签页查询内容高度
  974. let selector = '.follow-list';
  975. if (this.currentTab === 1) {
  976. selector = '.recommend-list';
  977. } else if (this.currentTab === 2) {
  978. selector = '.explore-list';
  979. }
  980. query.select(selector).boundingClientRect(data => {
  981. if (data) {
  982. // 设置最小高度,防止内容过少时swiper太小
  983. let minHeight = uni.getSystemInfoSync().windowHeight * 0.2; // 最小高度为窗口高度的40%
  984. this.swiperHeight = Math.max(data.height, minHeight);
  985. console.log('更新swiper高度:', this.swiperHeight, 'selector:', selector);
  986. }
  987. }).exec();
  988. },
  989. // 首次进入页面初始化数据
  990. initialLoad() {
  991. console.log('初始化数据加载...');
  992. // 根据当前标签页加载初始数据
  993. switch (this.currentTab) {
  994. case 0:
  995. // 重置关注列表
  996. this.followList = [];
  997. this.followOffset = 0;
  998. this.hasMoreFollow = true;
  999. this.loadFollowList();
  1000. break;
  1001. case 1:
  1002. // 重置推荐列表
  1003. this.recommendList = [];
  1004. this.recommendOffset = 0;
  1005. this.hasMoreRecommend = true;
  1006. this.loadRecommendList();
  1007. break;
  1008. case 2:
  1009. // 重置热点新闻和新闻列表
  1010. this.hotNewsList = [];
  1011. this.newsList = [];
  1012. this.newsOffset = 0;
  1013. this.hasMoreNews = true;
  1014. // 加载热点新闻和新闻列表
  1015. this.loadHotNews();
  1016. this.loadNewsList();
  1017. break;
  1018. }
  1019. },
  1020. // 显示没有更多数据的提示,带防抖处理
  1021. showNoMoreDataToast(message) {
  1022. return
  1023. // 如果已经有一个定时器在运行,先清除它
  1024. if (this.noMoreDataTimer) {
  1025. clearTimeout(this.noMoreDataTimer);
  1026. this.noMoreDataTimer = null;
  1027. }
  1028. // 设置新的定时器,防抖处理,1秒内不会重复显示提示
  1029. this.noMoreDataTimer = setTimeout(() => {
  1030. console.log(message);
  1031. uni.showToast({
  1032. title: message,
  1033. icon: 'none',
  1034. duration: 2000
  1035. });
  1036. this.noMoreDataTimer = null;
  1037. }, 1000);
  1038. },
  1039. onImageLoaded() {
  1040. // 图片加载完成后重新计算高度
  1041. // 使用延迟执行,确保所有图片都有时间加载完成
  1042. if (this.updateHeightTimer) {
  1043. clearTimeout(this.updateHeightTimer);
  1044. }
  1045. this.updateHeightTimer = setTimeout(() => {
  1046. this.updateSwiperHeight();
  1047. }, 300);
  1048. },
  1049. handleBannerClick(index) {
  1050. const item = this.bannerList[index];
  1051. console.log(111,index,item);
  1052. if (item && item.url) {
  1053. uni.navigateTo({
  1054. url: item.url
  1055. });
  1056. }
  1057. },
  1058. },
  1059. };
  1060. </script>
  1061. <style lang="scss">
  1062. @import "index.scss";
  1063. // 添加过渡效果样式
  1064. .fade-enter-active,
  1065. .fade-leave-active {
  1066. transition: opacity 0.3s;
  1067. }
  1068. .fade-enter,
  1069. .fade-leave-to {
  1070. opacity: 0;
  1071. }
  1072. // 确保列表项有最小高度,避免闪烁
  1073. .list-item {
  1074. min-height: 200rpx;
  1075. background: #fff;
  1076. margin-bottom: 20rpx;
  1077. border-radius: 12rpx;
  1078. overflow: hidden;
  1079. }
  1080. // swiper样式
  1081. .tab-content-swiper {
  1082. width: 100%;
  1083. transition: height 0.3s;
  1084. }
  1085. /* 确保内容可以正常显示 */
  1086. .swiper-item {
  1087. height: auto;
  1088. overflow: visible;
  1089. }
  1090. .follow-list,
  1091. .recommend-list,
  1092. .explore-list {
  1093. min-height: 300px;
  1094. }
  1095. </style>
  1096. <style>
  1097. @import "@/style/qweather-icons.css";
  1098. </style>