index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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">
  35. <image v-if="subitem!=null" :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. console.log(this.searchValue)
  107. this.mescroll.resetUpScroll()
  108. },
  109. getArticleCate(){
  110. var that=this;
  111. let data = {};
  112. getArticleCate(data).then(
  113. res => {
  114. if(res.code==200){
  115. this.cates=res.data;
  116. }else{
  117. uni.showToast({
  118. icon:'none',
  119. title: "请求失败",
  120. });
  121. }
  122. },
  123. rej => {}
  124. );
  125. },
  126. mescrollInit(mescroll) {
  127. this.mescroll = mescroll;
  128. },
  129. /*下拉刷新的回调 */
  130. downCallback(mescroll) {
  131. mescroll.resetUpScroll()
  132. },
  133. upCallback(page) {
  134. //联网加载数据
  135. var that = this;
  136. var data = {
  137. keyword:this.searchValue,
  138. cateId:this.choseCateId,
  139. page: page.num,
  140. pageSize: page.size
  141. };
  142. getArticleList(data).then(res => {
  143. if(res.code==200){
  144. //设置列表数据
  145. if (page.num == 1) {
  146. that.dataList = res.data.list;
  147. } else {
  148. that.dataList = that.dataList.concat(res.data.list);
  149. }
  150. that.mescroll.endBySize(res.data.list.length, res.data.total);
  151. }else{
  152. uni.showToast({
  153. icon:'none',
  154. title: "请求失败",
  155. });
  156. that.dataList = null;
  157. that.mescroll.endErr();
  158. }
  159. });
  160. },
  161. // 关键词选择
  162. choseCate(item) {
  163. this.choseCateId = item.cateId;
  164. this.mescroll.resetUpScroll()
  165. },
  166. // 查看详情
  167. showDetail(item) {
  168. uni.navigateTo({
  169. url: './detail?articleId=' + item.articleId
  170. })
  171. }
  172. }
  173. }
  174. </script>
  175. <style lang="scss">
  176. .status_bar {
  177. width: 100%;
  178. background-color: #FFFFFF;
  179. }
  180. .top-content{
  181. width: 100%;
  182. position: fixed;
  183. top: 0;
  184. left: 0;
  185. z-index: 10;
  186. }
  187. .top-title{
  188. height: 88upx;
  189. line-height: 88upx;
  190. font-size: 42upx;
  191. font-family: Source Han Sans CN;
  192. font-weight: bold;
  193. color: #222222;
  194. padding-left: 41upx;
  195. background-color: #FFFFFF;
  196. }
  197. .search-cont{
  198. padding: 16upx 30upx;
  199. background-color: #FFFFFF;
  200. .inner{
  201. box-sizing: border-box;
  202. width: 100%;
  203. height: 72upx;
  204. background: #F7F7F7;
  205. border-radius: 36upx;
  206. display: flex;
  207. align-items: center;
  208. padding: 0 30upx;
  209. .icon-search{
  210. width: 28upx;
  211. height: 28upx;
  212. margin-right: 20upx;
  213. }
  214. input{
  215. height: 60upx;
  216. line-height: 60upx;
  217. flex: 1;
  218. }
  219. }
  220. }
  221. .keyword-list{
  222. box-sizing: border-box;
  223. background: #fff;
  224. padding: 10upx 27upx;
  225. height: 100upx;
  226. .inner{
  227. display: flex;
  228. }
  229. .item{
  230. flex-shrink: 0;
  231. padding: 0 24upx;
  232. height: 64upx;
  233. line-height: 64upx;
  234. font-size: 28upx;
  235. font-family: PingFang SC;
  236. font-weight: 500;
  237. color: #2BC7B9;
  238. background: #F5FFFE;
  239. border: 1px solid #8AD5CE;
  240. border-radius: 32upx;
  241. margin: 0 20upx 20upx 0;
  242. &.active{
  243. color: #FFFFFF;
  244. background: #2BC7B9;
  245. border: 1px solid #2BC7B9;
  246. }
  247. }
  248. }
  249. .know-list{
  250. margin-top: 20upx;
  251. padding: 0 10upx;
  252. .item{
  253. box-sizing: border-box;
  254. height: 271upx;
  255. background: #FFFFFF;
  256. border-radius: 16upx;
  257. padding: 40upx 30upx;
  258. display: flex;
  259. align-items: center;
  260. justify-content: space-between;
  261. margin-bottom: 20upx;
  262. .left{
  263. flex: 1;
  264. padding-right: 40upx;
  265. height: 190upx;
  266. display: flex;
  267. flex-direction: column;
  268. justify-content: space-between;
  269. .title{
  270. font-size: 32upx;
  271. font-family: PingFang SC;
  272. font-weight: 500;
  273. color: #111111;
  274. line-height: 48upx;
  275. }
  276. .info-box{
  277. width: 100%;
  278. display: flex;
  279. align-items: center;
  280. justify-content: space-between;
  281. .readers{
  282. display: flex;
  283. align-items: center;
  284. .head-box{
  285. margin-right: 27upx;
  286. display: flex;
  287. align-items: center;
  288. .head{
  289. width: 48upx;
  290. height: 48upx;
  291. border-radius: 50%;
  292. overflow: hidden;
  293. box-shadow: 0 0 0 1px #fff;
  294. margin-right: -10upx;
  295. image{
  296. width: 100%;
  297. height: 100%;
  298. }
  299. }
  300. }
  301. .readings{
  302. display: flex;
  303. align-items: center;
  304. .eye{
  305. width: 26upx;
  306. height: 20upx;
  307. margin-right: 9upx;
  308. }
  309. .num{
  310. font-size: 24upx;
  311. font-family: PingFang SC;
  312. font-weight: 500;
  313. color: #999999;
  314. line-height: 1;
  315. }
  316. }
  317. }
  318. .time{
  319. font-size: 24upx;
  320. line-height: 1;
  321. font-family: PingFang SC;
  322. font-weight: 500;
  323. color: #999999;
  324. }
  325. }
  326. }
  327. .right{
  328. width: 250upx;
  329. height: 190upx;
  330. border-radius: 8upx;
  331. overflow: hidden;
  332. image{
  333. width: 100%;
  334. height: 100%;
  335. }
  336. }
  337. }
  338. }
  339. </style>