index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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="false" :interval="3000" :duration="1000">
  6. <swiper-item class="list" v-for="(item,index) in imgList" :key="index">
  7. <image class="image"
  8. v-if="item.url.indexOf('gif') != -1 || item.url.indexOf('jpg') != -1 || item.url.indexOf('png') != -1 || item.url.indexOf('jpeg') !=-1"
  9. :src="item.url" mode=""></image>
  10. <video class="image" :autoplay='false' :show-fullscreen-btn="false" :loop="false" controls v-else
  11. :src="item.url"></video>
  12. </swiper-item>
  13. </swiper>
  14. </view>
  15. <view class="bottom">
  16. <view class="two">
  17. <swiper class="swiper" circular :indicator-dots="true" indicator-color="#F5F5F5"
  18. indicator-active-color="#007AFF" :autoplay="false">
  19. <swiper-item class="swiper-item" v-for="(item,index) in moduleList" :key="index">
  20. <view class="list" v-for="(as,indexs) in item" :key="indexs" @tap="toChange(as)">
  21. <image class="image" :src="as.url&&as.url.length>0?as.url[0].url:''" mode="aspectFill">
  22. </image>
  23. <text class="text">{{ as.name }}</text>
  24. </view>
  25. </swiper-item>
  26. </swiper>
  27. </view>
  28. <view class="thr">
  29. <uni-notice-bar speed='50' showGetMore='true' moreText='更多' @getmore="toMore" show-icon scrollable
  30. :text="content" />
  31. </view>
  32. <view class="four" v-if="advertList.length>0">
  33. <swiper class="swiper" circular :indicator-dots="true" indicator-color="#F5F5F5"
  34. indicator-active-color="#007AFF" :autoplay="false">
  35. <swiper-item class="swiper-item" v-for="(item,index) in advertList" :key="index">
  36. <view class="list" v-for="(as,indexs) in item" :key="indexs" @tap="toChange(as)">
  37. <image class="image" :src="as.url&&as.url.length>0?as.url[0].url:''" mode="aspectFill">
  38. </image>
  39. <text class="text">{{ as.name }}</text>
  40. </view>
  41. </swiper-item>
  42. </swiper>
  43. </view>
  44. <view class="five">
  45. <tabs :tabs="tabs" @tabsChange="tabsChange">
  46. <view class="tabsList">
  47. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  48. <view class="list-scroll-view">
  49. <!-- 瀑布流布局列表 -->
  50. <view class="pubuBox">
  51. <view class="pubuItem">
  52. <view class="list" v-for="(item, index) in list" :key="index"
  53. @tap="toInfo(item)">
  54. <image :src="item.file&&item.file.length>0?item.file[0].url:''"
  55. mode="widthFix">
  56. </image>
  57. <view class="title"> <!-- 这是没有高度的父盒子(下半部分) -->
  58. <view class="title_1">{{ item.title ||'暂无'}}</view>
  59. <view class="title_2">
  60. <view class="left">
  61. {{item.contact_name||'暂无昵称'}}
  62. </view>
  63. <view class="right" @tap.stop="toLike(item)">
  64. <text v-if="item.is_like" class="iconfont icon-aixin1"></text>
  65. <text v-else class="iconfont icon-aixin"></text>
  66. {{item.like_num||'0'}}
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. <view class="is_bottom" v-if="is_bottom">
  74. <text>{{config.bottom_title||'到底了!'}}</text>
  75. </view>
  76. </view>
  77. </scroll-view>
  78. </view>
  79. </tabs>
  80. </view>
  81. </view>
  82. </view>
  83. </template>
  84. <script>
  85. import moment from 'moment';
  86. import tabs from '../../components/tabs/index.vue';
  87. export default {
  88. components: {
  89. tabs
  90. },
  91. data() {
  92. return {
  93. user: {},
  94. config: {},
  95. // 轮播图
  96. imgList: [],
  97. // 模块
  98. moduleList: [],
  99. // 广告
  100. advertList: [],
  101. // 公告内容
  102. content: '',
  103. tabs: {
  104. active: '0',
  105. bgColor: '#ffffff',
  106. menu: []
  107. },
  108. list: [],
  109. total: 0,
  110. skip: 0,
  111. limit: 6,
  112. page: 0,
  113. // 数据是否触底
  114. is_bottom: false,
  115. scrollTop: 0,
  116. }
  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. await that.searchOther();
  128. that.clearPage();
  129. await that.search();
  130. uni.stopPullDownRefresh();
  131. },
  132. methods: {
  133. searchToken() {
  134. const that = this;
  135. try {
  136. const res = uni.getStorageSync('token');
  137. if (res) that.$set(that, `user`, res);
  138. } catch (e) {
  139. uni.showToast({
  140. title: err.errmsg,
  141. icon: 'error',
  142. duration: 2000
  143. });
  144. }
  145. },
  146. // 查询
  147. async search() {
  148. const that = this;
  149. let info = {
  150. skip: that.skip,
  151. limit: that.limit,
  152. is_use: '0',
  153. status: '1',
  154. type: that.tabs.active,
  155. }
  156. if (that.user._id) info.user = that.user._id
  157. let res;
  158. res = await that.$api(`/article/article`, 'GET', {
  159. ...info,
  160. });
  161. if (res.errcode == '0') {
  162. let list = [...that.list, ...res.data];
  163. that.$set(that, `list`, list);
  164. that.$set(that, `total`, res.total)
  165. } else {
  166. uni.showToast({
  167. title: res.errmsg,
  168. icon: 'none'
  169. })
  170. }
  171. },
  172. // 点击模块
  173. toChange(item) {
  174. uni.navigateTo({
  175. url: `${item.route}?title=${item.name}&type=${item.type}`,
  176. })
  177. },
  178. // 查看更多公告
  179. toMore() {
  180. uni.navigateTo({
  181. url: `/pagesHome/notice/index`,
  182. })
  183. },
  184. // 查看详情
  185. toInfo(item) {
  186. uni.navigateTo({
  187. url: `/pagesHome/article/index?id=${item.id||item._id}`
  188. })
  189. },
  190. // 点赞/取消点赞
  191. async toLike(item) {
  192. const that = this;
  193. let res;
  194. if (item.is_like == false) {
  195. const form = {
  196. user: that.user._id,
  197. source: item._id,
  198. source_type: "article",
  199. type: '0',
  200. create_time: moment().format('YYYY-MM-DD HH:mm:ss'),
  201. }
  202. res = await that.$api(`/like`, 'POST', form);
  203. } else res = await that.$api(`/like/${item.like}`, 'DELETE', {})
  204. if (res.errcode == '0') {
  205. that.clearPage();
  206. that.search()
  207. }
  208. },
  209. // 查询其他信息
  210. async searchOther() {
  211. const that = this;
  212. let res;
  213. // 基本设置
  214. res = await that.$api(`/config`, 'GET', {});
  215. if (res.errcode == '0') {
  216. that.$set(that, `imgList`, [...res.data.video, ...res.data.file]);
  217. that.$set(that, `config`, res.data);
  218. }
  219. //模块
  220. res = await that.$api(`/module`, 'GET', {
  221. is_use: '0'
  222. });
  223. if (res.errcode == '0') {
  224. const data = res.data.reduce((acc, cur, i) => {
  225. if (i % 10 === 0) acc.push([cur]); // 新增一个小数组
  226. else acc[acc.length - 1].push(cur); // 将当前元素加入最后一个小数组中
  227. return acc;
  228. }, []);
  229. that.$set(that, `moduleList`, data);
  230. }
  231. // 公告
  232. res = await that.$api(`/notice`, 'GET', {
  233. is_use: '0',
  234. limit: 1
  235. });
  236. if (res.errcode == '0') that.$set(that, `content`, res.data[0].name);
  237. // 查询状态
  238. res = await that.$api(`/dictData`, 'GET', {
  239. type: 'home_tabs',
  240. is_use: '0',
  241. })
  242. if (res.errcode == '0') {
  243. const menu = res.data.map((item) => {
  244. return {
  245. title: item.label,
  246. active: item.value
  247. }
  248. })
  249. that.$set(that.tabs, `menu`, menu)
  250. }
  251. // 广告
  252. res = await that.$api(`/advert`, 'GET', {
  253. is_use: '0'
  254. });
  255. if (res.errcode == '0') that.$set(that, `advertList`, res.data);
  256. },
  257. // 选择选项卡
  258. tabsChange(e) {
  259. const that = this;
  260. that.$set(that.tabs, `active`, e.active)
  261. that.clearPage();
  262. that.search()
  263. },
  264. // 分页
  265. toPage(e) {
  266. const that = this;
  267. let list = that.list;
  268. let limit = that.limit;
  269. if (that.total > list.length) {
  270. uni.showLoading({
  271. title: '加载中',
  272. mask: true
  273. })
  274. let page = that.page + 1;
  275. that.$set(that, `page`, page)
  276. let skip = page * limit;
  277. that.$set(that, `skip`, skip)
  278. that.search();
  279. uni.hideLoading();
  280. } else that.$set(that, `is_bottom`, true)
  281. },
  282. // 触底
  283. toScroll(e) {
  284. const that = this;
  285. let up = that.scrollTop;
  286. that.$set(that, `scrollTop`, e.detail.scrollTop);
  287. let num = Math.sign(up - e.detail.scrollTop);
  288. if (num == 1) that.$set(that, `is_bottom`, false);
  289. },
  290. // 清空列表
  291. clearPage() {
  292. const that = this;
  293. that.$set(that, `list`, [])
  294. that.$set(that, `skip`, 0)
  295. that.$set(that, `limit`, 6)
  296. that.$set(that, `page`, 0)
  297. }
  298. },
  299. }
  300. </script>
  301. <style lang="scss" scoped>
  302. .main {
  303. .one {
  304. padding: 0 0 2vw 0;
  305. .swiper {
  306. height: 70vw;
  307. .list {
  308. .image {
  309. width: 100%;
  310. height: 100%;
  311. }
  312. }
  313. }
  314. }
  315. .bottom {
  316. position: absolute;
  317. top: 65vw;
  318. left: 0;
  319. right: 0;
  320. background-color: var(--mainColor);
  321. border-radius: 20px;
  322. padding: 2vw 0 0 0;
  323. .two {
  324. .swiper {
  325. height: 48vw;
  326. margin: 2vw 0 0 0;
  327. .swiper-item {
  328. display: flex;
  329. flex-wrap: wrap;
  330. .list {
  331. display: flex;
  332. flex-direction: column;
  333. align-items: center;
  334. width: 20vw;
  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>