story.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. navItem.loadingType = 'loading';
  134. article({
  135. page: navItem.page,
  136. limit: navItem.limit
  137. }, navItem.cid).then(({
  138. data
  139. }) => {
  140. console.log(data)
  141. let list = data.map(item => {
  142. return item
  143. })
  144. navItem.list = navItem.list.concat(list);
  145. if (navItem.limit == data.length) {
  146. //判断是否还有数据, 有改为 more, 没有改为noMore
  147. navItem.loadingType = 'more';
  148. navItem.page++;
  149. } else {
  150. //判断是否还有数据, 有改为 more, 没有改为noMore
  151. navItem.loadingType = 'noMore';
  152. }
  153. this.$set(navItem, 'loaded', true);
  154. })
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss" scoped>
  160. page {
  161. height: 100%;
  162. background-color: #eee;
  163. padding-top: 20rpx;
  164. }
  165. .content {
  166. height: 100%;
  167. background-color: #fff;
  168. .nav-bar {
  169. line-height: 86rpx;
  170. font-size: 32rpx;
  171. font-family: PingFang SC;
  172. font-weight: bold;
  173. color: #333333;
  174. justify-content: space-around;
  175. border-bottom: #E0E0E0 1px solid;
  176. .active {
  177. color: #3F7C1F;
  178. border-bottom: 3rpx solid #3F7C1F;
  179. }
  180. .nav-item {
  181. // flex-grow: 1;
  182. text-align: center;
  183. }
  184. }
  185. }
  186. .swiper-wrapper {
  187. background-color: #fff;
  188. .scroll-wrapper {
  189. padding: 0 22rpx 0 23rpx;
  190. }
  191. .list {
  192. padding: 18rpx 0;
  193. border-bottom: 1px solid #E0E0E0;
  194. .list-top-tit {
  195. font-size: 32rpx;
  196. font-family: PingFang SC;
  197. font-weight: bold;
  198. color: #333333;
  199. line-height: 42rpx;
  200. }
  201. .list-top-img {
  202. margin-top: 15rpx;
  203. width: 705rpx;
  204. height: 399rpx;
  205. background-color: #999;
  206. }
  207. .list-top-time {
  208. font-size: 26rpx;
  209. font-family: PingFang SC;
  210. font-weight: 500;
  211. color: #999999;
  212. line-height: 32rpx;
  213. }
  214. .list-scend {
  215. display: flex;
  216. .list-img {
  217. flex-shrink: 0;
  218. background-color: #999;
  219. width: 224rpx;
  220. height: 160rpx;
  221. }
  222. .list-info {
  223. padding: 10rpx 0 19rpx 23rpx;
  224. position: relative;
  225. .list-tit {
  226. width: 420rpx;
  227. font-size: 32rpx;
  228. font-family: PingFang SC;
  229. font-weight: bold;
  230. color: #333333;
  231. line-height: 32px;
  232. }
  233. .list-time {
  234. font-size: 28rpx;
  235. font-family: PingFang SC;
  236. font-weight: 500;
  237. color: #666666;
  238. line-height: 32rpx;
  239. position: absolute;
  240. bottom: 19rpx;
  241. }
  242. }
  243. }
  244. }
  245. }
  246. </style>