index.vue 28 KB

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