story.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view class="content">
  3. <!-- 头部导航 -->
  4. <view class="nav-bar flex">
  5. <view class="nav-item" v-for="(item,index) in navList" :key="index"
  6. :class="{'active': currentIndex == index}" @click="navClick(index)">
  7. {{item.tit}}
  8. </view>
  9. </view>
  10. <!-- 分类列表 -->
  11. <swiper :duration="400" class="swiper-wrapper" :style="{'height': height}" :current="currentIndex"
  12. @change="swiperChange">
  13. <swiper-item v-for="(navitem,navindex) in navList">
  14. <scroll-view scroll-y="true" :style="{'height': height}" class="scroll-wrapper">
  15. <view class="list" v-for="(item,index) in navitem.list"
  16. @click="navTo('/pages/story/storyDetail?id=' + item.id)">
  17. <template v-if="index == 0">
  18. <view class="list-top-tit clamp2">{{item.title}}</view>
  19. <image :src="item.image_input[0]" mode="" class="list-top-img"></image>
  20. <view class="list-top-time">
  21. 更新时间: {{item.add_time}}
  22. </view>
  23. </template>
  24. <template v-else>
  25. <view class="list-scend">
  26. <image :src="item.image_input[0]" mode="" class="list-img"></image>
  27. <view class="list-info">
  28. <view class="list-tit clamp">{{item.title}}</view>
  29. <view class="list-time">
  30. 更新时间: {{item.add_time}}
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. </view>
  36. <uni-load-more :status="navitem.loadingType" v-if="navitem.loaded"></uni-load-more>
  37. </scroll-view>
  38. </swiper-item>
  39. </swiper>
  40. </view>
  41. </template>
  42. <script>
  43. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  44. import {
  45. article,
  46. details
  47. } from '@/api/index.js'
  48. export default {
  49. components: {
  50. uniLoadMore
  51. },
  52. onReady(res) {
  53. var _this = this;
  54. uni.getSystemInfo({
  55. success: resu => {
  56. const query = uni.createSelectorQuery();
  57. query.select('.swiper-wrapper').boundingClientRect();
  58. query.exec(function(res) {
  59. console.log(res, 'ddddddddddddd');
  60. _this.height = resu.windowHeight - res[0].top + 'px';
  61. console.log('打印页面的剩余高度', _this.height);
  62. });
  63. },
  64. fail: res => {}
  65. });
  66. },
  67. data() {
  68. return {
  69. height: '', //swiper 高度
  70. currentIndex: 0, //当前头部导航位置
  71. navList: [{
  72. cid: 1,
  73. tit: '公司简介',
  74. list: [],
  75. page: 1,
  76. limit: 10,
  77. loadingType: 'more'
  78. },
  79. {
  80. cid: 2,
  81. tit: '产品简介',
  82. list: [],
  83. page: 1,
  84. limit: 10,
  85. loadingType: 'more'
  86. },
  87. {
  88. cid: 3,
  89. tit: '案例分享',
  90. list: [],
  91. page: 1,
  92. limit: 10,
  93. loadingType: 'more'
  94. }
  95. ]
  96. }
  97. },
  98. onLoad() {
  99. this.getData('tabChange')
  100. },
  101. methods: {
  102. //跳转详情
  103. navTo(url) {
  104. console.log(url)
  105. uni.navigateTo({
  106. url: url
  107. })
  108. },
  109. navClick(index) {
  110. this.currentIndex = index
  111. },
  112. swiperChange(e) {
  113. console.log(e, 'swiperChange')
  114. this.currentIndex = e.detail.current
  115. this.getData('tabChange')
  116. },
  117. getData(source) {
  118. let obj = this
  119. let index = this.currentIndex;
  120. let navItem = this.navList[index];
  121. if (source === 'tabChange' && navItem.loaded === true) {
  122. //tab切换只有第一次需要加载数据
  123. return;
  124. }
  125. if (navItem.loadingType === 'loading') {
  126. //防止重复加载
  127. return;
  128. }
  129. if (navItem.loadingType === 'noMore') {
  130. //防止重复加载
  131. return;
  132. }
  133. if (source == 'tabChange') {
  134. uni.showLoading({
  135. title: "加载中...",
  136. mask: true
  137. })
  138. }
  139. navItem.loadingType = 'loading';
  140. article({
  141. page: navItem.page,
  142. limit: navItem.limit
  143. }, navItem.cid).then(({
  144. data
  145. }) => {
  146. if (source == 'tabChange' && navItem.loaded != false) {
  147. uni.hideLoading()
  148. }
  149. console.log(data)
  150. let list = data.map(item => {
  151. return item
  152. })
  153. navItem.list = navItem.list.concat(list);
  154. if (navItem.limit == data.length) {
  155. //判断是否还有数据, 有改为 more, 没有改为noMore
  156. navItem.loadingType = 'more';
  157. navItem.page++;
  158. } else {
  159. //判断是否还有数据, 有改为 more, 没有改为noMore
  160. navItem.loadingType = 'noMore';
  161. }
  162. this.$set(navItem, 'loaded', true);
  163. })
  164. }
  165. }
  166. }
  167. </script>
  168. <style lang="scss" scoped>
  169. page {
  170. height: 100%;
  171. background-color: #eee;
  172. padding-top: 20rpx;
  173. }
  174. .content {
  175. height: 100%;
  176. background-color: #fff;
  177. .nav-bar {
  178. line-height: 86rpx;
  179. font-size: 32rpx;
  180. font-family: PingFang SC;
  181. font-weight: bold;
  182. color: #333333;
  183. justify-content: space-around;
  184. border-bottom: #E0E0E0 1px solid;
  185. .active {
  186. color: #3F7C1F;
  187. border-bottom: 3rpx solid #3F7C1F;
  188. }
  189. .nav-item {
  190. // flex-grow: 1;
  191. text-align: center;
  192. }
  193. }
  194. }
  195. .swiper-wrapper {
  196. background-color: #fff;
  197. .scroll-wrapper {
  198. padding: 0 22rpx 0 23rpx;
  199. }
  200. .list {
  201. padding: 18rpx 0;
  202. border-bottom: 1px solid #E0E0E0;
  203. .list-top-tit {
  204. font-size: 32rpx;
  205. font-family: PingFang SC;
  206. font-weight: bold;
  207. color: #333333;
  208. line-height: 42rpx;
  209. }
  210. .list-top-img {
  211. margin-top: 15rpx;
  212. width: 705rpx;
  213. height: 399rpx;
  214. background-color: #999;
  215. }
  216. .list-top-time {
  217. font-size: 26rpx;
  218. font-family: PingFang SC;
  219. font-weight: 500;
  220. color: #999999;
  221. line-height: 32rpx;
  222. }
  223. .list-scend {
  224. display: flex;
  225. .list-img {
  226. flex-shrink: 0;
  227. background-color: #999;
  228. width: 224rpx;
  229. height: 160rpx;
  230. }
  231. .list-info {
  232. padding: 10rpx 0 19rpx 23rpx;
  233. position: relative;
  234. .list-tit {
  235. width: 420rpx;
  236. font-size: 32rpx;
  237. font-family: PingFang SC;
  238. font-weight: bold;
  239. color: #333333;
  240. line-height: 32px;
  241. }
  242. .list-time {
  243. font-size: 28rpx;
  244. font-family: PingFang SC;
  245. font-weight: 500;
  246. color: #666666;
  247. line-height: 32rpx;
  248. position: absolute;
  249. bottom: 19rpx;
  250. }
  251. }
  252. }
  253. }
  254. }
  255. </style>