index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <view class="main">
  3. <view class="one">
  4. <swiper class="swiper" circular :indicator-dots="true" indicator-color="#F5F5F5"
  5. indicator-active-color="#ffffff" :autoplay="true" :interval="3000" :duration="1000">
  6. <swiper-item class="list" v-for="(item,index) in imgList" :key="index">
  7. <image class="image" :src="item.url" mode="">
  8. </image>
  9. </swiper-item>
  10. </swiper>
  11. </view>
  12. <view class="bottom">
  13. <view class="two">
  14. <swiper class="swiper" circular :indicator-dots="true" indicator-color="#F5F5F5"
  15. indicator-active-color="#007AFF" :autoplay="false">
  16. <swiper-item class="swiper-item" v-for="(item,index) in moduleList" :key="index">
  17. <view class="list" v-for="(as,indexs) in item" :key="indexs" @tap="toChange(as)">
  18. <image class="image" :src="as.url&&as.url.length>0?as.url[0].url:''" mode="aspectFill">
  19. </image>
  20. <text class="text">{{ as.name }}</text>
  21. </view>
  22. </swiper-item>
  23. </swiper>
  24. </view>
  25. <view class="thr">
  26. <uni-notice-bar speed='50' showGetMore='true' moreText='更多' @getmore="toMore" show-icon scrollable
  27. :text="content" />
  28. </view>
  29. <view class="four" v-if="advertList.length>0">
  30. <swiper class="swiper" circular :indicator-dots="true" indicator-color="#F5F5F5"
  31. indicator-active-color="#007AFF" :autoplay="false">
  32. <swiper-item class="swiper-item" v-for="(item,index) in advertList" :key="index">
  33. <view class="list" v-for="(as,indexs) in item" :key="indexs" @tap="toChange(as)">
  34. <image class="image" :src="as.url&&as.url.length>0?as.url[0].url:''" mode="aspectFill">
  35. </image>
  36. <text class="text">{{ as.name }}</text>
  37. </view>
  38. </swiper-item>
  39. </swiper>
  40. </view>
  41. <view class="five">
  42. <tabs :tabs="tabs" @tabsChange="tabsChange">
  43. <view class="tabsList">
  44. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  45. <view class="list-scroll-view">
  46. <!-- 瀑布流布局列表 -->
  47. <view class="pubuBox">
  48. <view class="pubuItem">
  49. <view class="list" v-for="(item, index) in list" :key="index"
  50. @tap="toInfo(item)">
  51. <image :src="item.file&&item.file.length>0?item.file[0].url:''"
  52. mode="widthFix">
  53. </image>
  54. <view class="title"> <!-- 这是没有高度的父盒子(下半部分) -->
  55. <view class="title_1">{{ item.title ||'暂无'}}</view>
  56. <view class="title_2">
  57. <view class="left">
  58. {{item.contact_name||'暂无昵称'}}
  59. </view>
  60. <view class="right" @tap.stop="toLike(item)">
  61. <text v-if="item.is_like" class="iconfont icon-aixin1"></text>
  62. <text v-else class="iconfont icon-aixin"></text>
  63. {{item.like_num||'0'}}
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. <view class="is_bottom" v-if="is_bottom">
  71. <text>{{config.bottom_title||'到底了!'}}</text>
  72. </view>
  73. </view>
  74. </scroll-view>
  75. </view>
  76. </tabs>
  77. </view>
  78. </view>
  79. </view>
  80. </template>
  81. <script>
  82. import moment from 'moment';
  83. import tabs from '../../components/tabs/index.vue';
  84. export default {
  85. components: {
  86. tabs
  87. },
  88. data() {
  89. return {
  90. user: {},
  91. config: {},
  92. // 轮播图
  93. imgList: [],
  94. // 模块
  95. moduleList: [],
  96. // 广告
  97. advertList: [],
  98. // 公告内容
  99. content: '',
  100. tabs: {
  101. active: '0',
  102. bgColor: '#ffffff',
  103. menu: []
  104. },
  105. list: [],
  106. total: 0,
  107. skip: 0,
  108. limit: 6,
  109. page: 0,
  110. // 数据是否触底
  111. is_bottom: false,
  112. scrollTop: 0,
  113. }
  114. },
  115. onShow: async function(e) {
  116. const that = this;
  117. that.searchToken();
  118. await that.searchOther();
  119. that.clearPage();
  120. await that.search();
  121. },
  122. onPullDownRefresh: async function() {
  123. const that = this;
  124. await that.searchOther();
  125. that.clearPage();
  126. await that.search();
  127. uni.stopPullDownRefresh();
  128. },
  129. methods: {
  130. searchToken() {
  131. const that = this;
  132. try {
  133. const res = uni.getStorageSync('token');
  134. if (res) that.$set(that, `user`, res);
  135. } catch (e) {
  136. uni.showToast({
  137. title: err.errmsg,
  138. icon: 'error',
  139. duration: 2000
  140. });
  141. }
  142. },
  143. // 查询
  144. async search() {
  145. const that = this;
  146. let info = {
  147. skip: that.skip,
  148. limit: that.limit,
  149. is_use: '0',
  150. status: '1',
  151. type: that.tabs.active,
  152. }
  153. if (that.user._id) info.user = that.user._id
  154. let res;
  155. res = await that.$api(`/article/article`, 'GET', {
  156. ...info,
  157. });
  158. if (res.errcode == '0') {
  159. let list = [...that.list, ...res.data];
  160. that.$set(that, `list`, list);
  161. that.$set(that, `total`, res.total)
  162. } else {
  163. uni.showToast({
  164. title: res.errmsg,
  165. icon: 'none'
  166. })
  167. }
  168. },
  169. // 点击模块
  170. toChange(item) {
  171. uni.navigateTo({
  172. url: `${item.route}?title=${item.name}&type=${item.type}`,
  173. })
  174. },
  175. // 查看更多公告
  176. toMore() {
  177. uni.navigateTo({
  178. url: `/pagesHome/notice/index`,
  179. })
  180. },
  181. // 查看详情
  182. toInfo(item) {
  183. uni.navigateTo({
  184. url: `/pagesHome/article/index?id=${item.id||item._id}`
  185. })
  186. },
  187. // 点赞/取消点赞
  188. async toLike(item) {
  189. const that = this;
  190. let res;
  191. if (item.is_like == false) {
  192. const form = {
  193. user: that.user._id,
  194. source: item._id,
  195. source_type: "article",
  196. type: '0',
  197. create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
  198. }
  199. res = await that.$api(`/like`, 'POST', form);
  200. } else res = await that.$api(`/like/${item.like}`, 'DELETE', {})
  201. if (res.errcode == '0') {
  202. that.clearPage();
  203. that.search()
  204. }
  205. },
  206. // 查询其他信息
  207. async searchOther() {
  208. const that = this;
  209. let res;
  210. // 基本设置
  211. res = await that.$api(`/config`, 'GET', {});
  212. if (res.errcode == '0') {
  213. that.$set(that, `imgList`, res.data.file);
  214. that.$set(that, `config`, res.data);
  215. }
  216. //模块
  217. res = await that.$api(`/module`, 'GET', {
  218. is_use: '0'
  219. });
  220. if (res.errcode == '0') {
  221. const data = res.data.reduce((acc, cur, i) => {
  222. if (i % 10 === 0) acc.push([cur]); // 新增一个小数组
  223. else acc[acc.length - 1].push(cur); // 将当前元素加入最后一个小数组中
  224. return acc;
  225. }, []);
  226. that.$set(that, `moduleList`, data);
  227. }
  228. // 公告
  229. res = await that.$api(`/notice`, 'GET', {
  230. is_use: '0',
  231. limit: 1
  232. });
  233. if (res.errcode == '0') that.$set(that, `content`, res.data[0].name);
  234. // 查询状态
  235. res = await that.$api(`/dictData`, 'GET', {
  236. type: 'home_tabs',
  237. is_use: '0',
  238. })
  239. if (res.errcode == '0') {
  240. const menu = res.data.map((item) => {
  241. return {
  242. title: item.label,
  243. active: item.value
  244. }
  245. })
  246. that.$set(that.tabs, `menu`, menu)
  247. }
  248. // 广告
  249. res = await that.$api(`/advert`, 'GET', {
  250. is_use: '0'
  251. });
  252. if (res.errcode == '0') that.$set(that, `advertList`, res.data);
  253. },
  254. // 选择选项卡
  255. tabsChange(e) {
  256. const that = this;
  257. that.$set(that.tabs, `active`, e.active)
  258. that.clearPage();
  259. that.search()
  260. },
  261. // 分页
  262. toPage(e) {
  263. const that = this;
  264. let list = that.list;
  265. let limit = that.limit;
  266. if (that.total > list.length) {
  267. uni.showLoading({
  268. title: '加载中',
  269. mask: true
  270. })
  271. let page = that.page + 1;
  272. that.$set(that, `page`, page)
  273. let skip = page * limit;
  274. that.$set(that, `skip`, skip)
  275. that.search();
  276. uni.hideLoading();
  277. } else that.$set(that, `is_bottom`, true)
  278. },
  279. // 触底
  280. toScroll(e) {
  281. const that = this;
  282. let up = that.scrollTop;
  283. that.$set(that, `scrollTop`, e.detail.scrollTop);
  284. let num = Math.sign(up - e.detail.scrollTop);
  285. if (num == 1) that.$set(that, `is_bottom`, false);
  286. },
  287. // 清空列表
  288. clearPage() {
  289. const that = this;
  290. that.$set(that, `list`, [])
  291. that.$set(that, `skip`, 0)
  292. that.$set(that, `limit`, 6)
  293. that.$set(that, `page`, 0)
  294. }
  295. },
  296. }
  297. </script>
  298. <style lang="scss" scoped>
  299. .main {
  300. .one {
  301. padding: 0 0 2vw 0;
  302. .swiper {
  303. height: 70vw;
  304. .list {
  305. .image {
  306. width: 100%;
  307. height: 100%;
  308. }
  309. }
  310. }
  311. }
  312. .bottom {
  313. position: absolute;
  314. top: 65vw;
  315. left: 0;
  316. right: 0;
  317. background-color: var(--mainColor);
  318. border-radius: 20px;
  319. padding: 2vw 0 0 0;
  320. .two {
  321. .swiper {
  322. height: 48vw;
  323. margin: 2vw 0 0 0;
  324. .swiper-item {
  325. display: flex;
  326. flex-wrap: wrap;
  327. .list {
  328. display: flex;
  329. flex-direction: column;
  330. align-items: center;
  331. width: 20vw;
  332. .image {
  333. width: 14vw;
  334. height: 14vw;
  335. border-radius: 14vw;
  336. }
  337. .text {
  338. font-size: var(--font14Size);
  339. margin-top: 5px;
  340. color: var(--f85Color);
  341. }
  342. }
  343. }
  344. }
  345. }
  346. .thr {
  347. padding: 0 2vw;
  348. }
  349. .four {
  350. padding: 2vw;
  351. }
  352. .five {
  353. background-color: var(--footColor);
  354. .tabsList {
  355. position: relative;
  356. width: 100vw;
  357. height: 80vh;
  358. .pubuBox {
  359. padding: 2vw;
  360. }
  361. .pubuItem {
  362. column-count: 2;
  363. column-gap: 2vw;
  364. }
  365. .list {
  366. box-sizing: border-box;
  367. border-radius: 2vw;
  368. overflow: hidden;
  369. background-color: var(--mainColor);
  370. break-inside: avoid;
  371. /*避免在元素内部插入分页符*/
  372. box-sizing: border-box;
  373. margin-bottom: 2vw;
  374. }
  375. .list image {
  376. width: 100%;
  377. }
  378. .title {
  379. padding: 2vw;
  380. .title_1 {
  381. font-size: var(--font14Size);
  382. line-height: 4vw;
  383. text-overflow: -o-ellipsis-lastline;
  384. overflow: hidden;
  385. text-overflow: ellipsis;
  386. display: -webkit-box;
  387. -webkit-line-clamp: 2;
  388. line-clamp: 2;
  389. -webkit-box-orient: vertical;
  390. min-height: 6vw;
  391. max-height: 20vw;
  392. }
  393. .title_2 {
  394. display: flex;
  395. justify-content: space-between;
  396. font-size: var(--font12Size);
  397. color: var(--f69Color);
  398. padding: 1vw 0;
  399. .right {
  400. display: flex;
  401. align-items: center;
  402. text:first-child {
  403. padding: 0 1vw 0 0;
  404. }
  405. }
  406. }
  407. }
  408. }
  409. }
  410. }
  411. }
  412. .scroll-view {
  413. position: absolute;
  414. top: 0;
  415. left: 0;
  416. right: 0;
  417. bottom: 0;
  418. .list-scroll-view {
  419. display: flex;
  420. flex-direction: column;
  421. }
  422. }
  423. .is_bottom {
  424. width: 100%;
  425. text-align: center;
  426. text {
  427. padding: 2vw 0;
  428. display: inline-block;
  429. color: var(--f85Color);
  430. font-size: var(--font14Size);
  431. }
  432. }
  433. </style>