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. onLoad: async function() {
  116. const that = this;
  117. that.searchToken();
  118. await that.searchOther();
  119. },
  120. onShow: async function(e) {
  121. const that = this;
  122. that.clearPage();
  123. await that.search();
  124. },
  125. onPullDownRefresh: async function() {
  126. const that = this;
  127. that.clearPage();
  128. await that.search();
  129. uni.stopPullDownRefresh();
  130. },
  131. methods: {
  132. searchToken() {
  133. const that = this;
  134. try {
  135. const res = uni.getStorageSync('token');
  136. if (res) that.$set(that, `user`, res);
  137. } catch (e) {
  138. uni.showToast({
  139. title: err.errmsg,
  140. icon: 'error',
  141. duration: 2000
  142. });
  143. }
  144. },
  145. // 查询
  146. async search() {
  147. const that = this;
  148. let info = {
  149. skip: that.skip,
  150. limit: that.limit,
  151. is_use: '0',
  152. status: '1',
  153. type: that.tabs.active,
  154. }
  155. if (that.user._id) info.user = that.user._id
  156. let res;
  157. res = await that.$api(`/article/article`, 'GET', {
  158. ...info,
  159. });
  160. if (res.errcode == '0') {
  161. let list = [...that.list, ...res.data];
  162. that.$set(that, `list`, list);
  163. that.$set(that, `total`, res.total)
  164. } else {
  165. uni.showToast({
  166. title: res.errmsg,
  167. icon: 'none'
  168. })
  169. }
  170. },
  171. // 点击模块
  172. toChange(item) {
  173. console.log(item)
  174. },
  175. // 查看更多公告
  176. toMore() {
  177. console.log('公告')
  178. },
  179. // 查看详情
  180. toInfo(item) {
  181. uni.navigateTo({
  182. url: `/pagesHome/article/index?id=${item.id||item._id}`
  183. })
  184. },
  185. // 点赞/取消点赞
  186. async toLike(item) {
  187. const that = this;
  188. let res;
  189. if (item.is_like == false) {
  190. const form = {
  191. user: that.user._id,
  192. source: item._id,
  193. type: '0',
  194. create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
  195. }
  196. res = await that.$api(`/like`, 'POST', form);
  197. } else res = await that.$api(`/like/${item.like}`, 'DELETE', {})
  198. if (res.errcode == '0') {
  199. that.clearPage();
  200. that.search()
  201. }
  202. },
  203. // 查询其他信息
  204. async searchOther() {
  205. const that = this;
  206. let res;
  207. // 基本设置
  208. res = await that.$api(`/config`, 'GET', {});
  209. if (res.errcode == '0') {
  210. that.$set(that, `imgList`, res.data.file);
  211. that.$set(that, `config`, res.data);
  212. }
  213. //模块
  214. res = await that.$api(`/module`, 'GET', {
  215. is_use: '0'
  216. });
  217. if (res.errcode == '0') {
  218. const data = res.data.reduce((acc, cur, i) => {
  219. if (i % 10 === 0) acc.push([cur]); // 新增一个小数组
  220. else acc[acc.length - 1].push(cur); // 将当前元素加入最后一个小数组中
  221. return acc;
  222. }, []);
  223. that.$set(that, `moduleList`, data);
  224. }
  225. // 公告
  226. res = await that.$api(`/notice`, 'GET', {
  227. is_use: '0',
  228. limit: 1
  229. });
  230. if (res.errcode == '0') that.$set(that, `content`, res.data[0].name);
  231. // 查询状态
  232. res = await that.$api(`/dictData`, 'GET', {
  233. type: 'home_tabs',
  234. is_use: '0',
  235. })
  236. if (res.errcode == '0') {
  237. const menu = res.data.map((item) => {
  238. return {
  239. title: item.label,
  240. active: item.value
  241. }
  242. })
  243. that.$set(that.tabs, `menu`, menu)
  244. }
  245. // 广告
  246. res = await that.$api(`/advert`, 'GET', {
  247. is_use: '0'
  248. });
  249. if (res.errcode == '0') that.$set(that, `advertList`, res.data);
  250. },
  251. // 选择选项卡
  252. tabsChange(e) {
  253. const that = this;
  254. that.$set(that.tabs, `active`, e.active)
  255. that.clearPage();
  256. that.search()
  257. },
  258. // 分页
  259. toPage(e) {
  260. const that = this;
  261. let list = that.list;
  262. let limit = that.limit;
  263. if (that.total > list.length) {
  264. uni.showLoading({
  265. title: '加载中',
  266. mask: true
  267. })
  268. let page = that.page + 1;
  269. that.$set(that, `page`, page)
  270. let skip = page * limit;
  271. that.$set(that, `skip`, skip)
  272. that.search();
  273. uni.hideLoading();
  274. } else that.$set(that, `is_bottom`, true)
  275. },
  276. // 触底
  277. toScroll(e) {
  278. const that = this;
  279. let up = that.scrollTop;
  280. that.$set(that, `scrollTop`, e.detail.scrollTop);
  281. let num = Math.sign(up - e.detail.scrollTop);
  282. if (num == 1) that.$set(that, `is_bottom`, false);
  283. },
  284. // 清空列表
  285. clearPage() {
  286. const that = this;
  287. that.$set(that, `list`, [])
  288. that.$set(that, `skip`, 0)
  289. that.$set(that, `limit`, 6)
  290. that.$set(that, `page`, 0)
  291. }
  292. },
  293. }
  294. </script>
  295. <style lang="scss" scoped>
  296. .main {
  297. .one {
  298. padding: 0 0 2vw 0;
  299. .swiper {
  300. height: 70vw;
  301. .list {
  302. .image {
  303. width: 100%;
  304. height: 100%;
  305. }
  306. }
  307. }
  308. }
  309. .bottom {
  310. position: absolute;
  311. top: 65vw;
  312. left: 0;
  313. right: 0;
  314. background-color: var(--mainColor);
  315. border-radius: 20px;
  316. padding: 2vw 0 0 0;
  317. .two {
  318. .swiper {
  319. height: 50vw;
  320. .swiper-item {
  321. display: flex;
  322. flex-direction: column;
  323. flex-wrap: wrap;
  324. .list {
  325. display: flex;
  326. flex-direction: column;
  327. justify-content: space-between;
  328. align-items: center;
  329. width: 20vw;
  330. padding: 1vw 0 0 0;
  331. .image {
  332. width: 14vw;
  333. height: 14vw;
  334. border-radius: 14vw;
  335. }
  336. .text {
  337. font-size: var(--font14Size);
  338. margin-top: 5px;
  339. color: var(--f85Color);
  340. }
  341. }
  342. }
  343. }
  344. }
  345. .thr {
  346. padding: 0 2vw;
  347. }
  348. .four {
  349. padding: 2vw;
  350. }
  351. .five {
  352. background-color: var(--footColor);
  353. .tabsList {
  354. position: relative;
  355. width: 100vw;
  356. height: 80vh;
  357. .pubuBox {
  358. padding: 2vw;
  359. }
  360. .pubuItem {
  361. column-count: 2;
  362. column-gap: 2vw;
  363. }
  364. .list {
  365. box-sizing: border-box;
  366. border-radius: 2vw;
  367. overflow: hidden;
  368. background-color: var(--mainColor);
  369. break-inside: avoid;
  370. /*避免在元素内部插入分页符*/
  371. box-sizing: border-box;
  372. margin-bottom: 2vw;
  373. }
  374. .list image {
  375. width: 100%;
  376. }
  377. .title {
  378. padding: 2vw;
  379. .title_1 {
  380. font-size: var(--font14Size);
  381. line-height: 4vw;
  382. text-overflow: -o-ellipsis-lastline;
  383. overflow: hidden;
  384. text-overflow: ellipsis;
  385. display: -webkit-box;
  386. -webkit-line-clamp: 2;
  387. line-clamp: 2;
  388. -webkit-box-orient: vertical;
  389. min-height: 6vw;
  390. max-height: 20vw;
  391. }
  392. .title_2 {
  393. display: flex;
  394. justify-content: space-between;
  395. font-size: var(--font12Size);
  396. color: var(--f69Color);
  397. padding: 1vw 0;
  398. .right {
  399. display: flex;
  400. align-items: center;
  401. text:first-child {
  402. padding: 0 1vw 0 0;
  403. }
  404. }
  405. }
  406. }
  407. }
  408. }
  409. }
  410. }
  411. .scroll-view {
  412. position: absolute;
  413. top: 0;
  414. left: 0;
  415. right: 0;
  416. bottom: 0;
  417. .list-scroll-view {
  418. display: flex;
  419. flex-direction: column;
  420. }
  421. }
  422. .is_bottom {
  423. width: 100%;
  424. text-align: center;
  425. text {
  426. padding: 2vw 0;
  427. display: inline-block;
  428. color: var(--f85Color);
  429. font-size: var(--font14Size);
  430. }
  431. }
  432. </style>