index.vue 8.4 KB

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