index.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  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> -->
  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="queryList" :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' }">
  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" @click="lhSelectCityFun">
  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. <!-- 根据当前标签显示不同样式的列表 -->
  100. <!-- 关注列表 - 类似my.vue -->
  101. <view v-show="currentTab === 0" class="follow-list">
  102. <block v-if="followList.length > 0">
  103. <w-waterfall :data="followList">
  104. <template v-slot:content="{ item, width }">
  105. <card :item="formatItem(item)" :width="width" :custom-style="{ background: '#fff' }"
  106. textColor="#000">
  107. </card>
  108. </template>
  109. </w-waterfall>
  110. </block>
  111. <view class="no-data" v-else-if="!isLoadingFollow">
  112. <text>暂无关注数据</text>
  113. </view>
  114. </view>
  115. <!-- 推荐列表 - 瀑布流样式 -->
  116. <template>
  117. <w-waterfall v-show="currentTab === 1 && recommendList.length > 0" :data="recommendList">
  118. <template v-slot:content="{ item, width }">
  119. <card :item="formatItem(item)" :width="width" :custom-style="{ background: '#fff' }"
  120. textColor="#000">
  121. </card>
  122. </template>
  123. </w-waterfall>
  124. <view class="no-data"
  125. v-if=" currentTab === 1 && recommendList.length === 0 && !isLoadingRecommend ">
  126. <text>暂无推荐数据</text>
  127. </view>
  128. </template>
  129. <!-- 探索列表 - 热点新闻已经有现成的热搜资讯组件,只需添加新闻列表 -->
  130. <template>
  131. <view v-if="currentTab === 2" class="hot-topics">
  132. <view class="hot-topics-header">
  133. <image class="hot-topics-title" src="@/static/home/hot-topics-title.png" mode=""></image>
  134. </view>
  135. <swiper class="hot-topics-swiper" :current="currentTopicPage" @change="handleTopicPageChange">
  136. <swiper-item v-for="(page, pageIndex) in topicPages" :key="pageIndex">
  137. <view class="hot-topics-list">
  138. <view v-for="(topic, index) in page" :key="index" class="topic-item"
  139. @click="goToArticleDetail(topic.id)">
  140. <view class="hot-topics-left">
  141. <image v-if="pageIndex * 4 + index == 0" src="@/static/icon/icon-first.png"
  142. class="topic-index topic-index-img" mode=""></image>
  143. <image v-else-if="pageIndex * 4 + index == 1"
  144. src="@/static/icon/icon-second.png" class="topic-index topic-index-img"
  145. mode=""></image>
  146. <image v-else-if="pageIndex * 4 + index == 2"
  147. src="@/static/icon/icon-third.png" class="topic-index topic-index-img"
  148. mode=""></image>
  149. <text v-else class="topic-index">{{
  150. pageIndex * 4 + index + 1
  151. }}</text>
  152. <view class="topic-content toe">
  153. {{ topic.title }}
  154. </view>
  155. <image v-if="topic.isHot" src="@/static/icon/icon-hot.png" class="hot-tag"
  156. mode=""></image>
  157. </view>
  158. <text class="topic-participants">{{ topic.num_like }}人正在热议</text>
  159. </view>
  160. </view>
  161. </swiper-item>
  162. </swiper>
  163. <view class="indicator-dots">
  164. <view v-for="i in 2" :key="i" :class="['dot', currentTopicPage === i - 1 ? 'active' : '']">
  165. </view>
  166. </view>
  167. </view>
  168. <view v-show="currentTab === 2 && newsList.length > 0" class="news-list">
  169. <w-waterfall v-show="currentTab === 2 && newsList.length > 0" :data="newsList">
  170. <template v-slot:content="{ item, width }">
  171. <card :item="formatItem(item)" :width="width" goLink="/pages/index/articleDetail?id="
  172. :custom-style="{ background: '#fff' }" textColor="#000"></card>
  173. </template>
  174. </w-waterfall>
  175. </view>
  176. <view class="no-data" v-if="currentTab === 2 && newsList.length === 0 && !isLoadingNews">
  177. <text>暂无新闻数据</text>
  178. </view>
  179. </template>
  180. </z-paging-cell>
  181. <view class="blankHeight"></view>
  182. </z-paging>
  183. <tabbar-vue :tabbars="tabbars" :currentIndex="0" ref="tabbar"></tabbar-vue>
  184. <!-- 添加浮动按钮 -->
  185. <view v-if="currentTab === 2" class="float-btn" @click="goToMake">
  186. <image src="/static/home/release-btn.png" class="float-btn-icon"></image>
  187. </view>
  188. <!-- <novice-guidance :step="step"></novice-guidance> -->
  189. <lhSelectCity style="height: 100vh" class="lhSelectCity" :currentCity="currentCity" :windowHeight="windowHeight"
  190. :hotCitys="hotCitys" @onSelect="City" v-if="lhSelectCityFalg"
  191. @closeLhSelectCityFun="closeLhSelectCityFun()" />
  192. <wu-app-update></wu-app-update>
  193. </view>
  194. </template>
  195. <script>
  196. import sortble from "@/components/sortble/sortble.vue";
  197. import tabbarVue from "@/components/tabbar/tabbar.vue";
  198. import pageNavbar from "@/components/page-navbar/page-navbar.vue";
  199. import wWaterfall from "@/components/w-waterfall/w-waterfall.vue";
  200. import tabbar from "@/mixins/tabbar";
  201. import card from "@/components/card/card.vue";
  202. import lhSelectCity from "@/components/lh-select-city/index.vue";
  203. import {
  204. getStorage,
  205. setStorage,
  206. removeStorage
  207. } from "@/common/util.js";
  208. // import noviceGuidance from "@/components/novice-guidance/index.vue";
  209. export default {
  210. components: {
  211. sortble,
  212. tabbarVue,
  213. pageNavbar,
  214. wWaterfall,
  215. lhSelectCity,
  216. card,
  217. // noviceGuidance
  218. },
  219. mixins: [tabbar],
  220. data() {
  221. return {
  222. step: {
  223. name: "workbenchSet5",
  224. guideList: [{
  225. el: ".step1",
  226. tips: "这里是第一步的介绍~",
  227. next: "下一步",
  228. },
  229. {
  230. el: ".step2",
  231. tips: "这里是第二步的介绍~",
  232. next: "下一步",
  233. },
  234. {
  235. el: ".step3",
  236. tips: "这里是第三步的介绍~",
  237. next: "下一步",
  238. },
  239. {
  240. el: ".step4",
  241. tips: "这里是第四步的介绍~",
  242. next: "下一步",
  243. },
  244. {
  245. el: ".step5",
  246. tips: "这里是第五步的介绍~",
  247. next: "下一步",
  248. },
  249. {
  250. el: ".step6",
  251. tips: "这里是第六步的介绍~",
  252. next: "下一步",
  253. },
  254. {
  255. el: ".step7",
  256. tips: "最后一步啦~",
  257. next: "完成",
  258. },
  259. ],
  260. },
  261. windowHeight: uni.getWindowInfo().windowHeight,
  262. bannerList: [
  263. "../../static/dome/home-swper.png",
  264. "../../static/dome/home-swper.png",
  265. "../../static/dome/home-swper.png",
  266. ],
  267. cardList: [{
  268. img: "/static/img/img-1.png",
  269. bgimg: "/static/image/bg-2.png",
  270. },
  271. {
  272. img: "/static/img/img-3.png",
  273. bgimg: "/static/image/bg-3.png",
  274. },
  275. {
  276. img: "/static/img/img-2.png",
  277. bgimg: "/static/image/bg-1.png",
  278. },
  279. ],
  280. list: [], // 瀑布流全部数据
  281. dataList: [],
  282. tabs: ["关注", "推荐", "探索"],
  283. currentTab: 1,
  284. currentTopicPage: 0,
  285. followList: [], // 关注列表数据
  286. recommendList: [], // 推荐列表数据
  287. exploreList: [], // 探索列表数据
  288. hotNewsList: [], // 热点新闻数据
  289. newsList: [], // 新闻列表数据
  290. followOffset: 0, // 关注列表偏移量
  291. recommendOffset: 0, // 推荐列表偏移量
  292. exploreOffset: 0, // 探索列表偏移量
  293. newsOffset: 0, // 新闻列表偏移量
  294. hasMoreFollow: true, // 是否有更多关注列表数据
  295. hasMoreRecommend: true, // 是否有更多推荐列表数据
  296. hasMoreExplore: true, // 是否有更多探索列表数据
  297. hasMoreNews: true, // 是否有更多新闻列表数据
  298. isLoadingFollow: false, // 是否正在加载关注列表
  299. isLoadingRecommend: false, // 是否正在加载推荐列表
  300. isLoadingExplore: false, // 是否正在加载探索列表
  301. isLoadingNews: false, // 是否正在加载新闻列表
  302. hotTopics: [],
  303. lhSelectCityFalg: false,
  304. hotCitys: [
  305. "杭州",
  306. "天津",
  307. "北京",
  308. "上海",
  309. "深圳",
  310. "广州",
  311. "成都",
  312. "重庆",
  313. "厦门",
  314. ],
  315. currentCity: "北京",
  316. windowHeight: "",
  317. weather: {
  318. city: "",
  319. weather: "",
  320. temp: "0℃",
  321. icon: 101,
  322. },
  323. isContentRecommendation: true,
  324. };
  325. },
  326. computed: {
  327. getDayOfWeek() {
  328. const days = [
  329. "星期日",
  330. "星期一",
  331. "星期二",
  332. "星期三",
  333. "星期四",
  334. "星期五",
  335. "星期六",
  336. ];
  337. const today = new Date();
  338. const dayOfWeek = days[today.getDay()];
  339. return dayOfWeek;
  340. },
  341. currentList() {
  342. switch (this.currentTab) {
  343. case 0:
  344. return this.followList;
  345. case 1:
  346. return this.recommendList; // 使用专门的推荐列表
  347. case 2:
  348. return this.exploreList;
  349. default:
  350. return [];
  351. }
  352. },
  353. topicPages() {
  354. const pages = [];
  355. for (let i = 0; i < this.hotTopics.length; i += 4) {
  356. pages.push(this.hotTopics.slice(i, i + 4));
  357. }
  358. return pages;
  359. },
  360. },
  361. onLoad() {
  362. let that = this;
  363. // 计算出可用高度
  364. this.windowHeight = uni.getSystemInfoSync().windowHeight + "px";
  365. // 不在onLoad中直接加载数据,避免与z-paging组件重复请求
  366. // 让z-paging组件通过queryList方法控制数据加载
  367. this.getWeather();
  368. this.queryList();
  369. },
  370. onShow() {
  371. var isContentRecommendation = getStorage("isContentRecommendation");
  372. console.log(isContentRecommendation, "isContentRecommendation");
  373. if (isContentRecommendation != "false") {
  374. isContentRecommendation = true;
  375. } else {
  376. isContentRecommendation = false;
  377. }
  378. this.isContentRecommendation = isContentRecommendation;
  379. if (isContentRecommendation == false) {
  380. this.tabs = ["关注"];
  381. this.currentTab = 0;
  382. this.queryList();
  383. } else {
  384. this.tabs = ["关注", "推荐", "探索"];
  385. this.currentTab = 1;
  386. }
  387. uni.$emit('check_update');
  388. },
  389. // 修改触底加载方法
  390. onReachBottom() {
  391. console.log('触底加载更多');
  392. // 根据当前标签页加载更多数据
  393. switch (this.currentTab) {
  394. case 0:
  395. if (this.hasMoreFollow && !this.isLoadingFollow) {
  396. this.loadFollowList();
  397. }
  398. break;
  399. case 1:
  400. if (this.hasMoreRecommend && !this.isLoadingRecommend) {
  401. this.loadRecommendList();
  402. }
  403. break;
  404. case 2:
  405. if (this.hasMoreNews && !this.isLoadingNews) {
  406. this.loadNewsList();
  407. }
  408. break;
  409. }
  410. },
  411. // 下拉刷新数据
  412. methods: {
  413. getWeather(city) {
  414. uni.request({
  415. url: this.$apiHost + "/Index/getAreaInfo",
  416. data: {
  417. uuid: getApp().globalData.uuid,
  418. skey: getApp().globalData.skey,
  419. city: city || (this.currentCity == "北京" ? "" : this.currentCity),
  420. },
  421. header: {
  422. "content-type": "application/json",
  423. sign: getApp().globalData.headerSign,
  424. },
  425. success: (res) => {
  426. console.log(this.weather, "天气数据", res.data);
  427. if (res.data.city) {
  428. this.currentCity = res.data.city;
  429. this.weather = res.data;
  430. }
  431. },
  432. complete: () => {},
  433. fail: (e) => {},
  434. });
  435. },
  436. lhSelectCityFun() {
  437. this.lhSelectCityFalg = true;
  438. },
  439. // 选中事件
  440. City(city) {
  441. this.currentCity = city;
  442. setTimeout(() => {
  443. this.lhSelectCityFalg = false;
  444. }, 300);
  445. },
  446. closeLhSelectCityFun() {
  447. this.lhSelectCityFalg = false;
  448. },
  449. queryList() {
  450. // 根据当前标签刷新数据
  451. switch (this.currentTab) {
  452. case 0:
  453. // 重置关注列表
  454. this.followList = [];
  455. this.followOffset = 0;
  456. this.hasMoreFollow = true;
  457. this.loadFollowList();
  458. break;
  459. case 1:
  460. // 重置推荐列表
  461. this.recommendList = [];
  462. this.recommendOffset = 0;
  463. this.hasMoreRecommend = true;
  464. this.loadRecommendList();
  465. break;
  466. case 2:
  467. // 重置热点新闻和新闻列表
  468. this.hotNewsList = [];
  469. this.newsList = [];
  470. this.newsOffset = 0;
  471. this.hasMoreNews = true;
  472. // 加载热点新闻和新闻列表
  473. this.loadHotNews();
  474. this.loadNewsList();
  475. break;
  476. }
  477. },
  478. switchTab(index) {
  479. if (this.currentTab === index) return;
  480. this.currentTab = index;
  481. // 重置当前标签页的数据
  482. switch (index) {
  483. case 0:
  484. this.followList = [];
  485. this.followOffset = 0;
  486. this.hasMoreFollow = true;
  487. break;
  488. case 1:
  489. this.recommendList = [];
  490. this.recommendOffset = 0;
  491. this.hasMoreRecommend = true;
  492. break;
  493. case 2:
  494. this.newsList = [];
  495. this.hotTopics = [];
  496. this.newsOffset = 0;
  497. this.hasMoreNews = true;
  498. break;
  499. }
  500. // 加载新标签页的数据
  501. this.loadTabData(index);
  502. },
  503. loadTabData(index) {
  504. switch (index) {
  505. case 0:
  506. this.loadFollowList();
  507. break;
  508. case 1:
  509. this.loadRecommendList();
  510. break;
  511. case 2:
  512. this.loadHotNews();
  513. this.loadNewsList();
  514. break;
  515. }
  516. },
  517. // 修改关注列表加载方法
  518. loadFollowList() {
  519. if (this.isLoadingFollow) return;
  520. this.isLoadingFollow = true;
  521. // 保存当前列表数据
  522. const currentList = [...this.followList];
  523. uni.request({
  524. url: this.$apiHost + "/Work/getlist",
  525. data: {
  526. uuid: getApp().globalData.uuid,
  527. skey: getApp().globalData.skey,
  528. type: "attention",
  529. offset: this.followOffset,
  530. },
  531. header: {
  532. "content-type": "application/json",
  533. sign: getApp().globalData.headerSign,
  534. },
  535. success: (res) => {
  536. console.log("关注列表数据:", res.data);
  537. if (res.data.success == "yes" && res.data.list && res.data.list.length > 0) {
  538. // 使用 Vue.set 确保响应式更新
  539. if (this.followOffset === 0) {
  540. this.followList = res.data.list;
  541. } else {
  542. // 使用 Vue.set 更新数组,避免数据闪烁
  543. this.followList = currentList.concat(res.data.list);
  544. }
  545. this.followOffset += res.data.list.length;
  546. this.hasMoreFollow = res.data.list.length >= 20;
  547. } else {
  548. this.hasMoreFollow = false;
  549. }
  550. // 使用 nextTick 确保数据更新后再通知组件
  551. this.$nextTick(() => {
  552. if (this.$refs.paging) {
  553. this.$refs.paging.complete(this.followList);
  554. }
  555. });
  556. },
  557. complete: () => {
  558. this.isLoadingFollow = false;
  559. },
  560. fail: (e) => {
  561. console.log("请求关注列表失败:", e);
  562. this.isLoadingFollow = false;
  563. if (this.$refs.paging) {
  564. this.$refs.paging.complete(false);
  565. }
  566. },
  567. });
  568. },
  569. // 修改推荐列表加载方法
  570. loadRecommendList() {
  571. if (this.isLoadingRecommend) return;
  572. this.isLoadingRecommend = true;
  573. // 保存当前列表数据
  574. const currentList = [...this.recommendList];
  575. uni.request({
  576. url: this.$apiHost + "/Work/getlist",
  577. data: {
  578. uuid: getApp().globalData.uuid,
  579. skey: getApp().globalData.skey,
  580. type: "recommend",
  581. offset: this.recommendOffset,
  582. },
  583. header: {
  584. "content-type": "application/json",
  585. sign: getApp().globalData.headerSign,
  586. },
  587. success: (res) => {
  588. console.log("推荐列表数据:", res.data);
  589. if (res.data.success == "yes" && res.data.list && res.data.list.length > 0) {
  590. if (this.recommendOffset === 0) {
  591. this.recommendList = res.data.list;
  592. } else {
  593. this.recommendList = currentList.concat(res.data.list);
  594. }
  595. this.recommendOffset += res.data.list.length;
  596. this.hasMoreRecommend = res.data.list.length >= 20;
  597. } else {
  598. this.hasMoreRecommend = false;
  599. }
  600. this.$nextTick(() => {
  601. if (this.$refs.paging) {
  602. this.$refs.paging.complete(this.recommendList);
  603. }
  604. });
  605. },
  606. complete: () => {
  607. this.isLoadingRecommend = false;
  608. },
  609. fail: (e) => {
  610. console.log("请求推荐列表失败:", e);
  611. this.isLoadingRecommend = false;
  612. if (this.$refs.paging) {
  613. this.$refs.paging.complete(false);
  614. }
  615. },
  616. });
  617. },
  618. loadHotNews() {
  619. if (this.isLoadingExplore) return;
  620. this.isLoadingExplore = true;
  621. uni.request({
  622. url: this.$apiHost + "/Article/getlist",
  623. data: {
  624. uuid: getApp().globalData.uuid,
  625. skey: getApp().globalData.skey,
  626. type: "hot",
  627. },
  628. header: {
  629. "content-type": "application/json",
  630. sign: getApp().globalData.headerSign,
  631. },
  632. success: (res) => {
  633. console.log("热点新闻数据:", res.data);
  634. if (res.data.success == "yes" && res.data.list && res.data.list.length > 0) {
  635. this.hotNewsList = res.data.list;
  636. this.hotTopics = this.hotNewsList.map((item, index) => ({
  637. id: item.id,
  638. title: item.title || "热门话题",
  639. num_like: item.num_like || 0,
  640. isHot: index % 2 === 0,
  641. }));
  642. }
  643. },
  644. complete: () => {
  645. this.isLoadingExplore = false;
  646. },
  647. fail: (e) => {
  648. console.log("请求热点新闻失败:", e);
  649. this.isLoadingExplore = false;
  650. },
  651. });
  652. },
  653. // 修改新闻列表加载方法
  654. loadNewsList() {
  655. if (this.isLoadingNews) return;
  656. this.isLoadingNews = true;
  657. // 保存当前列表数据
  658. const currentList = [...this.newsList];
  659. uni.request({
  660. url: this.$apiHost + "/Article/getlist",
  661. data: {
  662. uuid: getApp().globalData.uuid,
  663. skey: getApp().globalData.skey,
  664. type: "list",
  665. offset: this.newsOffset,
  666. },
  667. header: {
  668. "content-type": "application/json",
  669. sign: getApp().globalData.headerSign,
  670. },
  671. success: (res) => {
  672. console.log("新闻列表数据:", res.data);
  673. if (res.data.success == "yes" && res.data.list && res.data.list.length > 0) {
  674. if (this.newsOffset === 0) {
  675. this.newsList = res.data.list;
  676. } else {
  677. this.newsList = currentList.concat(res.data.list);
  678. }
  679. this.newsOffset += res.data.list.length;
  680. this.hasMoreNews = res.data.list.length >= 20;
  681. } else {
  682. this.hasMoreNews = false;
  683. }
  684. this.$nextTick(() => {
  685. if (this.$refs.paging) {
  686. this.$refs.paging.complete(this.newsList);
  687. }
  688. });
  689. },
  690. complete: () => {
  691. this.isLoadingNews = false;
  692. },
  693. fail: (e) => {
  694. console.log("请求新闻列表失败:", e);
  695. this.isLoadingNews = false;
  696. if (this.$refs.paging) {
  697. this.$refs.paging.complete(false);
  698. }
  699. },
  700. });
  701. },
  702. handleTopicPageChange(e) {
  703. this.currentTopicPage = e.detail.current;
  704. },
  705. formatItem(item) {
  706. console.log("item:", item);
  707. let img = "";
  708. if (item.images) {
  709. img = item.images.split("|")[0];
  710. }
  711. // 处理接口返回的数据,使其适配card组件
  712. return {
  713. id: item.id,
  714. allowEdit: false,
  715. nickname: item.nickname,
  716. avator: item.avator,
  717. num_like: item.num_like,
  718. num_view: item.num_view,
  719. image: img || item.img_url || item.image, // 优先使用images字段
  720. w: item.width,
  721. h: item.height,
  722. title: item.title || "",
  723. desc: item.desc || "",
  724. userID: item.userID || 0,
  725. backgroundColor: "#f6f6f6",
  726. };
  727. },
  728. downloadAndProcessImage(imageUrl, width = 10, height = 10) {
  729. return new Promise((resolve, reject) => {
  730. uni.downloadFile({
  731. url: imageUrl,
  732. success: (downloadResult) => {
  733. if (downloadResult.statusCode === 200) {
  734. const tempFilePath = downloadResult.tempFilePath;
  735. const ctx = uni.createCanvasContext("myCanvas", this);
  736. ctx.drawImage(tempFilePath, 0, 0, width, height);
  737. ctx.draw(false, () => {
  738. uni.canvasGetImageData({
  739. canvasId: "myCanvas",
  740. x: 0,
  741. y: 0,
  742. width: width,
  743. height: height,
  744. success: (res) => {
  745. const data = res.data;
  746. let r = 0,
  747. g = 0,
  748. b = 0;
  749. for (let i = 0; i < data.length; i +=
  750. 4) {
  751. r += data[i];
  752. g += data[i + 1];
  753. b += data[i + 2];
  754. }
  755. const count = width * height;
  756. r = Math.floor(r / count);
  757. g = Math.floor(g / count);
  758. b = Math.floor(b / count);
  759. resolve({
  760. r,
  761. g,
  762. b,
  763. });
  764. },
  765. fail: (err) => {
  766. reject(err);
  767. },
  768. });
  769. });
  770. } else {
  771. reject(new Error("下载图像失败"));
  772. }
  773. },
  774. fail: (err) => {
  775. reject(err);
  776. },
  777. });
  778. });
  779. },
  780. goToArticleDetail(id) {
  781. if (!id) {
  782. uni.showToast({
  783. title: "文章ID不存在",
  784. icon: "none",
  785. });
  786. return;
  787. }
  788. // uni.$emit("check_login", () => {
  789. uni.navigateTo({
  790. url: "/pages/index/articleDetail?id=" + id,
  791. });
  792. // });
  793. },
  794. goWork(item) {
  795. console.log("skeylogin", "xxx");
  796. uni.$emit("check_login", () => {
  797. uni.navigateTo({
  798. url: "/pages/index/workDetail?id=" + item.id,
  799. });
  800. });
  801. },
  802. goToMake() {
  803. console.log("skeylogin", "xxx2");
  804. uni.$emit("check_login", () => {
  805. uni.navigateTo({
  806. // 生成个人形象
  807. // url: "/pages/make/make",
  808. url: "/pages/make/fabuArticle?id=-1",
  809. });
  810. });
  811. },
  812. goPage(page) {
  813. uni.$emit("check_login", () => {
  814. uni.navigateTo({
  815. url: page,
  816. });
  817. });
  818. },
  819. // 修改下拉刷新方法
  820. onRefresh() {
  821. console.log('下拉刷新开始');
  822. // 重置所有数据
  823. this.followList = [];
  824. this.recommendList = [];
  825. this.newsList = [];
  826. this.hotTopics = [];
  827. // 重置偏移量
  828. this.followOffset = 0;
  829. this.recommendOffset = 0;
  830. this.newsOffset = 0;
  831. // 重置加载状态
  832. this.hasMoreFollow = true;
  833. this.hasMoreRecommend = true;
  834. this.hasMoreNews = true;
  835. // 根据当前标签页加载数据
  836. this.loadTabData(this.currentTab);
  837. },
  838. // 下拉刷新恢复
  839. onRefresherRestore() {
  840. console.log('下拉刷新恢复');
  841. },
  842. },
  843. };
  844. </script>
  845. <style lang="scss">
  846. @import "index.scss";
  847. // 添加过渡效果样式
  848. .fade-enter-active,
  849. .fade-leave-active {
  850. transition: opacity 0.3s;
  851. }
  852. .fade-enter,
  853. .fade-leave-to {
  854. opacity: 0;
  855. }
  856. // 确保列表项有最小高度,避免闪烁
  857. .list-item {
  858. min-height: 200rpx;
  859. background: #fff;
  860. margin-bottom: 20rpx;
  861. border-radius: 12rpx;
  862. overflow: hidden;
  863. }
  864. </style>
  865. <style>
  866. @import "@/style/qweather-icons.css";
  867. </style>