index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <view>
  3. <view class="top-content">
  4. <!-- 这里是状态栏 -->
  5. <view class="status_bar" :style="{height: statusBarHeight}"></view>
  6. <view class="top-title">健康百科</view>
  7. <!-- 搜索框 -->
  8. <view class="search-cont">
  9. <view class="inner">
  10. <image class="icon-search" src="https://kntobs.jnmyunl.com/shop/images/search.png" mode=""></image>
  11. <input type="text" v-model="searchValue" placeholder="输入关键字搜索" confirm-type="search" @confirm="doSearch" placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
  12. </view>
  13. </view>
  14. <view class="keyword-list">
  15. <!-- 关键字列表 -->
  16. <scroll-view scroll-x="true" >
  17. <view class="inner">
  18. <view v-for="(item,index) in cates" :key="index" :class="choseCateId == item.cateId?'item active':'item'" @click="choseCate(item)">
  19. {{ item.cateName }}
  20. </view>
  21. </view>
  22. </scroll-view>
  23. </view>
  24. </view>
  25. <!-- 知识列表 -->
  26. <mescroll-body :top="top" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  27. <view class="know-list">
  28. <view class="item" v-for="(item,index) in dataList" :key="index" @click="showDetail(item)">
  29. <view class="left">
  30. <view class="title ellipsis2">{{ item.title }}</view>
  31. <view class="info-box">
  32. <view class="readers">
  33. <view class="head-box" v-if="item.viewsList!=null&&item.viewsList.length>0">
  34. <view class="head" v-for="(subitem,j) in item.viewsList" :key="j" v-if="subitem!=null">
  35. <image :src="subitem.avatar==null?'https://kntobs.jnmyunl.com/shop/images/detault_head.jpg':subitem.avatar" mode=""></image>
  36. </view>
  37. </view>
  38. <view class="readings">
  39. <image class="eye" src="https://kntobs.jnmyunl.com/shop/images/eye.png" ></image>
  40. <text class="num">{{item.views}}</text>
  41. </view>
  42. </view>
  43. <view class="time">{{item.publishTime}}</view>
  44. </view>
  45. </view>
  46. <view class="right">
  47. <image :src="item.imageUrl" mode="aspectFill"></image>
  48. </view>
  49. </view>
  50. </view>
  51. </mescroll-body>
  52. <!-- <tabbar :actindex="1"></tabbar> -->
  53. </view>
  54. </template>
  55. <script>
  56. import {getArticleCate,getArticleList} from '@/api/article'
  57. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  58. export default {
  59. mixins: [MescrollMixin],
  60. data() {
  61. return {
  62. top:'0px',
  63. cates:[],
  64. choseCateId:0,
  65. // 状态栏的高度
  66. statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
  67. searchValue: '',
  68. mescroll:null,
  69. // 上拉加载的配置
  70. downOption:{
  71. },
  72. upOption: {
  73. onScroll:true,
  74. use: true, // 是否启用上拉加载; 默认true
  75. page: {
  76. num: 1, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  77. size: 10 // 每页数据的数量,默认10
  78. },
  79. noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  80. empty: {
  81. icon:'https://kntobs.jnmyunl.com/shop/images/no_data.png',
  82. tip: '暂无数据'
  83. },
  84. textNoMore:'已经到底了'
  85. },
  86. // 列表数据
  87. dataList: [],
  88. };
  89. },
  90. onShow() {
  91. this.getArticleCate();
  92. var that=this;
  93. setTimeout(function(){
  94. let query = uni.createSelectorQuery().select(".top-content");
  95.     query.boundingClientRect(function(data) { //data - 各种参数
  96.       console.log(data.height) // 获取元素宽度
  97. that.top=data.height+"px";
  98.    }).exec()
  99. },500);
  100. // let info1 = uni.createSelectorQuery().select(".keyword-list");
  101. //     info1.boundingClientRect(function(data) { //data - 各种参数
  102. //       console.log(data.height) // 获取元素宽度
  103. //    }).exec()
  104. },
  105. methods:{
  106. doSearch(){
  107. console.log(this.searchValue)
  108. this.mescroll.resetUpScroll()
  109. },
  110. getArticleCate(){
  111. var that=this;
  112. let data = {};
  113. getArticleCate(data).then(
  114. res => {
  115. if(res.code==200){
  116. this.cates=res.data;
  117. }else{
  118. uni.showToast({
  119. icon:'none',
  120. title: "请求失败",
  121. });
  122. }
  123. },
  124. rej => {}
  125. );
  126. },
  127. mescrollInit(mescroll) {
  128. this.mescroll = mescroll;
  129. },
  130. /*下拉刷新的回调 */
  131. downCallback(mescroll) {
  132. mescroll.resetUpScroll()
  133. },
  134. upCallback(page) {
  135. //联网加载数据
  136. console.log('-----',page)
  137. var that = this;
  138. var data = {
  139. keyword:this.searchValue,
  140. cateId:this.choseCateId,
  141. page: 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.choseCateId = item.cateId;
  166. this.mescroll.resetUpScroll()
  167. },
  168. // 查看详情
  169. showDetail(item) {
  170. uni.navigateTo({
  171. url: './detail?articleId=' + item.articleId
  172. })
  173. }
  174. }
  175. }
  176. </script>
  177. <style lang="scss">
  178. .status_bar {
  179. width: 100%;
  180. background-color: #FFFFFF;
  181. }
  182. .top-content{
  183. width: 100%;
  184. position: fixed;
  185. top: 0;
  186. left: 0;
  187. z-index: 10;
  188. }
  189. .top-title{
  190. height: 88upx;
  191. line-height: 88upx;
  192. font-size: 42upx;
  193. font-family: Source Han Sans CN;
  194. font-weight: bold;
  195. color: #222222;
  196. padding-left: 41upx;
  197. background-color: #FFFFFF;
  198. }
  199. .search-cont{
  200. padding: 16upx 30upx;
  201. background-color: #FFFFFF;
  202. .inner{
  203. box-sizing: border-box;
  204. width: 100%;
  205. height: 72upx;
  206. background: #F7F7F7;
  207. border-radius: 36upx;
  208. display: flex;
  209. align-items: center;
  210. padding: 0 30upx;
  211. .icon-search{
  212. width: 28upx;
  213. height: 28upx;
  214. margin-right: 20upx;
  215. }
  216. input{
  217. height: 60upx;
  218. line-height: 60upx;
  219. flex: 1;
  220. }
  221. }
  222. }
  223. .keyword-list{
  224. box-sizing: border-box;
  225. background: #fff;
  226. padding: 10upx 27upx;
  227. height: 100upx;
  228. .inner{
  229. display: flex;
  230. }
  231. .item{
  232. flex-shrink: 0;
  233. padding: 0 24upx;
  234. height: 64upx;
  235. line-height: 64upx;
  236. font-size: 28upx;
  237. font-family: PingFang SC;
  238. font-weight: 500;
  239. color: #2BC7B9;
  240. background: #F5FFFE;
  241. border: 1px solid #2BC7B9;
  242. border-radius: 32upx;
  243. margin: 0 20upx 20upx 0;
  244. &.active{
  245. color: #FFFFFF;
  246. background: #2BC7B9;
  247. border: 1px solid #2BC7B9;
  248. }
  249. }
  250. }
  251. .know-list{
  252. margin-top: 20upx;
  253. padding: 0 10upx;
  254. .item{
  255. box-sizing: border-box;
  256. height: 271upx;
  257. background: #FFFFFF;
  258. border-radius: 16upx;
  259. padding: 40upx 30upx;
  260. display: flex;
  261. align-items: center;
  262. justify-content: space-between;
  263. margin-bottom: 20upx;
  264. .left{
  265. flex: 1;
  266. padding-right: 40upx;
  267. height: 190upx;
  268. display: flex;
  269. flex-direction: column;
  270. justify-content: space-between;
  271. .title{
  272. font-size: 32upx;
  273. font-family: PingFang SC;
  274. font-weight: 500;
  275. color: #111111;
  276. line-height: 48upx;
  277. }
  278. .info-box{
  279. width: 100%;
  280. display: flex;
  281. align-items: center;
  282. justify-content: space-between;
  283. .readers{
  284. display: flex;
  285. align-items: center;
  286. .head-box{
  287. margin-right: 27upx;
  288. display: flex;
  289. align-items: center;
  290. .head{
  291. width: 48upx;
  292. height: 48upx;
  293. border-radius: 50%;
  294. overflow: hidden;
  295. box-shadow: 0 0 0 1px #fff;
  296. margin-right: -10upx;
  297. image{
  298. width: 100%;
  299. height: 100%;
  300. }
  301. }
  302. }
  303. .readings{
  304. display: flex;
  305. align-items: center;
  306. .eye{
  307. width: 26upx;
  308. height: 20upx;
  309. margin-right: 9upx;
  310. }
  311. .num{
  312. font-size: 24upx;
  313. font-family: PingFang SC;
  314. font-weight: 500;
  315. color: #999999;
  316. line-height: 1;
  317. }
  318. }
  319. }
  320. .time{
  321. font-size: 24upx;
  322. line-height: 1;
  323. font-family: PingFang SC;
  324. font-weight: 500;
  325. color: #999999;
  326. }
  327. }
  328. }
  329. .right{
  330. width: 250upx;
  331. height: 190upx;
  332. border-radius: 8upx;
  333. overflow: hidden;
  334. image{
  335. width: 100%;
  336. height: 100%;
  337. }
  338. }
  339. }
  340. }
  341. </style>