index.vue 11 KB

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