articleList.vue 7.4 KB

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