articleList.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <view>
  3. <view class="top-content">
  4. <!-- 搜索框 -->
  5. <view class="search-cont">
  6. <view class="inner">
  7. <image class="icon-search" src="/static/images/search.png" mode=""></image>
  8. <input type="text" v-model="keyword" placeholder="输入关键字搜索" confirm-type="search" @confirm="doSearch" placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
  9. </view>
  10. </view>
  11. <view class="cate-list">
  12. <!-- 关键字列表 -->
  13. <scroll-view scroll-x="true" >
  14. <view class="inner">
  15. <view v-for="(item,index) in cates" :key="index" :class="cateId == item.cateId?'item active':'item'" @click="choseCate(item)">
  16. {{ item.cateName }}
  17. </view>
  18. </view>
  19. </scroll-view>
  20. </view>
  21. </view>
  22. <mescroll-body top="192rpx" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  23. <view class="article-list">
  24. <view class="item" v-for="(item,index) in dataList" :key="index" @click="showDetail(item)">
  25. <view class="left">
  26. <view class="title ellipsis2">{{ item.title }}</view>
  27. <view class="info-box">
  28. <view class="readers">
  29. <view class="readings">
  30. <image class="eye" src="/static/images/eye.png" ></image>
  31. <text class="num">{{item.views}}</text>
  32. </view>
  33. </view>
  34. <view class="time">{{item.publishTime}}</view>
  35. </view>
  36. </view>
  37. <view class="right">
  38. <image :src="item.imageUrl" mode="aspectFill"></image>
  39. </view>
  40. </view>
  41. </view>
  42. </mescroll-body>
  43. </view>
  44. </template>
  45. <script>
  46. import {getArticleList,getArticleCateList} from '@/api/article.js'
  47. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  48. export default {
  49. mixins: [MescrollMixin],
  50. data() {
  51. return {
  52. cates:[],
  53. cateId:0,
  54. keyword: '',
  55. mescroll:null,
  56. downOption: { //下拉刷新
  57. use:true,
  58. auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
  59. },
  60. upOption: {
  61. onScroll:false,
  62. use: true, // 是否启用上拉加载; 默认true
  63. page: {
  64. pae: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  65. size: 10 // 每页数据的数量,默认10
  66. },
  67. noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  68. textNoMore:"已经到底了",
  69. empty: {
  70. icon:'https://cos.his.cdwjyyh.com/fs/20240423/cf4a86b913a04341bb44e34bb4d37aa2.png',
  71. tip: '暂无数据'
  72. }
  73. },
  74. dataList: []
  75. };
  76. },
  77. onShow() {
  78. this.getArticleCateList();
  79. },
  80. methods:{
  81. doSearch(){
  82. this.mescroll.resetUpScroll()
  83. },
  84. getArticleCateList(){
  85. var that=this;
  86. let data = {};
  87. getArticleCateList(data).then(
  88. res => {
  89. if(res.code==200){
  90. this.cates=res.data;
  91. }else{
  92. uni.showToast({
  93. icon:'none',
  94. title: "请求失败",
  95. });
  96. }
  97. },
  98. rej => {}
  99. );
  100. },
  101. mescrollInit(mescroll) {
  102. this.mescroll = mescroll;
  103. },
  104. /*下拉刷新的回调 */
  105. downCallback(mescroll) {
  106. mescroll.resetUpScroll()
  107. },
  108. upCallback(page) {
  109. //联网加载数据
  110. var that = this;
  111. var data = {
  112. keyword:this.keyword,
  113. cateId:this.cateId,
  114. pageNum: page.num,
  115. pageSize: page.size
  116. };
  117. getArticleList(data).then(res => {
  118. if(res.code==200){
  119. //设置列表数据
  120. if (page.num == 1) {
  121. that.dataList = res.data.list;
  122. } else {
  123. that.dataList = that.dataList.concat(res.data.list);
  124. }
  125. that.mescroll.endBySize(res.data.list.length, res.data.total);
  126. }else{
  127. uni.showToast({
  128. icon:'none',
  129. title: "请求失败",
  130. });
  131. that.dataList = null;
  132. that.mescroll.endErr();
  133. }
  134. });
  135. },
  136. // 关键词选择
  137. choseCate(item) {
  138. this.cateId = item.cateId;
  139. this.mescroll.resetUpScroll()
  140. },
  141. // 查看详情
  142. showDetail(item) {
  143. uni.navigateTo({
  144. url: './articleDetails?articleId=' + item.articleId
  145. })
  146. }
  147. }
  148. }
  149. </script>
  150. <style lang="scss">
  151. .top-content{
  152. width: 100%;
  153. position: fixed;
  154. top: 0;
  155. left: 0;
  156. z-index: 10;
  157. }
  158. .top-title{
  159. height: 88upx;
  160. line-height: 88upx;
  161. font-size: 42upx;
  162. font-family: Source Han Sans CN;
  163. font-weight: bold;
  164. color: #222222;
  165. padding-left: 41upx;
  166. background-color: #FFFFFF;
  167. }
  168. .search-cont{
  169. padding: 16upx 30upx;
  170. background-color: #FFFFFF;
  171. .inner{
  172. box-sizing: border-box;
  173. width: 100%;
  174. height: 72upx;
  175. background: #F7F7F7;
  176. border-radius: 36upx;
  177. display: flex;
  178. align-items: center;
  179. padding: 0 30upx;
  180. .icon-search{
  181. width: 28upx;
  182. height: 28upx;
  183. margin-right: 20upx;
  184. }
  185. input{
  186. height: 60upx;
  187. line-height: 60upx;
  188. flex: 1;
  189. }
  190. }
  191. }
  192. .cate-list{
  193. box-sizing: border-box;
  194. background: #fff;
  195. padding: 10upx 27upx;
  196. height: 100upx;
  197. .inner{
  198. display: flex;
  199. }
  200. .item{
  201. flex-shrink: 0;
  202. padding: 0 24upx;
  203. height: 64upx;
  204. line-height: 64upx;
  205. font-size: 28upx;
  206. font-family: PingFang SC;
  207. font-weight: 500;
  208. color: #018C39;
  209. background: #ffffff;
  210. border: 1px solid #018C39;
  211. border-radius: 32upx;
  212. margin: 0 20upx 20upx 0;
  213. &.active{
  214. color: #FFFFFF;
  215. background: #018C39;
  216. border: 1px solid #018C39;
  217. }
  218. }
  219. }
  220. .article-list{
  221. margin-top: 20upx;
  222. padding: 0 10upx;
  223. .item{
  224. width: 100%;
  225. box-sizing: border-box;
  226. height: 271upx;
  227. background: #FFFFFF;
  228. border-radius: 16upx;
  229. padding: 40upx 30upx;
  230. display: flex;
  231. align-items: center;
  232. justify-content: space-between;
  233. margin-bottom: 20upx;
  234. .left{
  235. flex: 1;
  236. padding-right: 40upx;
  237. height: 190upx;
  238. display: flex;
  239. flex-direction: column;
  240. justify-content: space-between;
  241. .title{
  242. font-size: 32upx;
  243. font-family: PingFang SC;
  244. font-weight: 500;
  245. color: #111111;
  246. line-height: 48upx;
  247. }
  248. .info-box{
  249. width: 100%;
  250. display: flex;
  251. align-items: center;
  252. justify-content: space-between;
  253. .readers{
  254. display: flex;
  255. align-items: center;
  256. .head-box{
  257. margin-right: 27upx;
  258. display: flex;
  259. align-items: center;
  260. .head{
  261. width: 48upx;
  262. height: 48upx;
  263. border-radius: 50%;
  264. overflow: hidden;
  265. box-shadow: 0 0 0 1px #fff;
  266. margin-right: -10upx;
  267. image{
  268. width: 100%;
  269. height: 100%;
  270. }
  271. }
  272. }
  273. .readings{
  274. display: flex;
  275. align-items: center;
  276. .eye{
  277. width: 26upx;
  278. height: 20upx;
  279. margin-right: 9upx;
  280. }
  281. .num{
  282. font-size: 24upx;
  283. font-family: PingFang SC;
  284. font-weight: 500;
  285. color: #999999;
  286. line-height: 1;
  287. }
  288. }
  289. }
  290. .time{
  291. font-size: 24upx;
  292. line-height: 1;
  293. font-family: PingFang SC;
  294. font-weight: 500;
  295. color: #999999;
  296. }
  297. }
  298. }
  299. .right{
  300. width: 250upx;
  301. height: 190upx;
  302. border-radius: 8upx;
  303. overflow: hidden;
  304. image{
  305. width: 100%;
  306. height: 100%;
  307. }
  308. }
  309. }
  310. }
  311. </style>