index.vue 28 KB

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