list.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view class="wrap">
  3. <view class="header">
  4. <view v-for="item,index in allData.type" :key="index" @tap="changeActive(item,index)" :class="['header_item',current == index?'current':'']">{{item.name}}
  5. <view class="line"></view>
  6. </view>
  7. </view>
  8. <view class="list">
  9. <view v-for="item,index in allData.detail" :key="index" class="list_item" @tap="toDetail(item)">
  10. <view class="news_title">{{item.name}}</view>
  11. <view :class="['image','clear',item.imgs.length == 1?'one':'no_one']">
  12. <image v-for="item,index in item.imgs" :key="index" :src="url + item"></image>
  13. </view>
  14. <view class="news_tag clear">
  15. <view class="news_tag_lf">{{item.tag}} <view class="list_ban" v-if="item.isAd == 1">广告</view></view>
  16. <view class="news_tag_rg">{{item.date}}</view>
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import api from "../../../api.js";
  24. let app = getApp();
  25. export default {
  26. data() {
  27. return {
  28. url:app.globalData.url,
  29. current:0,//导航栏默认选中
  30. id:'',//导航栏对应查询id
  31. allData:null,
  32. }
  33. },
  34. mounted() {
  35. this.getData();
  36. },
  37. methods: {
  38. //加载数据
  39. getData(){
  40. api.getNewsList().then((res)=>{
  41. console.log(res);
  42. this.allData = res.data.data;
  43. })
  44. },
  45. //切换查询数据
  46. getItem(){
  47. let data = {
  48. typeId:this.id
  49. }
  50. api.getNewsItem(data).then((res)=>{
  51. // console.log(res);
  52. this.allData.detail = res.data.data.detail;
  53. })
  54. },
  55. //导航栏点击
  56. changeActive(item,index){
  57. this.current = index;
  58. this.id = item.id;
  59. this.getItem();
  60. },
  61. //跳转详情
  62. toDetail(item){
  63. uni.navigateTo({
  64. url:"/components/news/detail/detail?id=" + item.id
  65. })
  66. }
  67. }
  68. }
  69. </script>
  70. <style scoped>
  71. .clear:after{
  72. content: "";
  73. display: block;
  74. clear: both;
  75. }
  76. .header{
  77. width:100%;
  78. height:86rpx;
  79. line-height: 86rpx;
  80. border-top:1px solid #f2f2f2;
  81. border-bottom:1px solid #f2f2f2;
  82. display: flex;
  83. }
  84. .header_item{
  85. flex: 1;
  86. font-size: 30rpx;
  87. color:#222222;
  88. text-align: center;
  89. position: relative;
  90. }
  91. .line{
  92. width:38rpx;
  93. height:4rpx;
  94. background:linear-gradient(270deg,rgba(254,107,21,1) 0%,rgba(254,163,48,1) 100%);
  95. position: absolute;
  96. bottom:0rpx;
  97. left:50%;
  98. transform: translateX(-50%);
  99. display: none;
  100. }
  101. .current{
  102. background:linear-gradient(270deg, rgba(254,107,21,1) 0%, rgba(254,163,48,1) 100%);
  103. -webkit-background-clip:text;
  104. color:transparent;
  105. font-size: 34rpx;
  106. font-weight: bold;
  107. }
  108. .active .line{
  109. display: block;
  110. }
  111. .list{
  112. width:100%;
  113. overflow: hidden;
  114. padding:0 30rpx 100rpx;
  115. box-sizing: border-box;
  116. }
  117. .list_item{
  118. width:100%;
  119. padding-bottom: 26rpx;
  120. border-bottom:1px solid #f2f2f2;
  121. }
  122. .news_title{
  123. font-size: 32rpx;
  124. color:#2a2a2a;
  125. margin:22rpx 0 14rpx 0;
  126. }
  127. .one image{
  128. display: block;
  129. width:100%;
  130. height:380rpx;
  131. }
  132. .no_one image{
  133. display: block;
  134. width:218rpx;
  135. height:144rpx;
  136. margin-right: 18rpx;
  137. float:left;
  138. }
  139. .no_one image:last-child{
  140. margin-right: 0;
  141. }
  142. .news_tag{
  143. width:100%;
  144. margin-top:12rpx;
  145. font-size: 24rpx;
  146. color:#999999;
  147. }
  148. .news_tag_lf{
  149. float:left;
  150. }
  151. .news_tag_rg{
  152. float:right;
  153. }
  154. .list_ban{
  155. display: inline-block;
  156. font-size:24rpx;
  157. background:linear-gradient(270deg, rgba(254,107,21,1) 0%, rgba(254,163,48,1) 100%);
  158. -webkit-background-clip:text;
  159. color:transparent;
  160. margin-left: 10rpx;
  161. }
  162. </style>