index copy.vue 27 KB

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