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