index.vue 9.2 KB

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