index.vue 11 KB

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