articleList.vue 7.2 KB

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