index.vue 27 KB

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