index.vue 8.4 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="https://zkzh-2025.oss-cn-beijing.aliyuncs.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://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/detault_head.jpg':subitem.avatar" mode=""></image>
  36. </view>
  37. </view>
  38. <view class="readings">
  39. <image class="eye" src="https://zkzh-2025.oss-cn-beijing.aliyuncs.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: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  77. size: 10 // 每页数据的数量,默认10
  78. },
  79. noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  80. empty: {
  81. icon:'https://zkzh-2025.oss-cn-beijing.aliyuncs.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. var that = this;
  137. var data = {
  138. keyword:this.searchValue,
  139. cateId:this.choseCateId,
  140. page: page.num,
  141. pageSize: page.size
  142. };
  143. getArticleList(data).then(res => {
  144. if(res.code==200){
  145. //设置列表数据
  146. if (page.num == 1) {
  147. that.dataList = res.data.list;
  148. } else {
  149. that.dataList = that.dataList.concat(res.data.list);
  150. }
  151. that.mescroll.endBySize(res.data.list.length, res.data.total);
  152. }else{
  153. uni.showToast({
  154. icon:'none',
  155. title: "请求失败",
  156. });
  157. that.dataList = null;
  158. that.mescroll.endErr();
  159. }
  160. });
  161. },
  162. // 关键词选择
  163. choseCate(item) {
  164. this.choseCateId = item.cateId;
  165. this.mescroll.resetUpScroll()
  166. },
  167. // 查看详情
  168. showDetail(item) {
  169. uni.navigateTo({
  170. url: './detail?articleId=' + item.articleId
  171. })
  172. }
  173. }
  174. }
  175. </script>
  176. <style lang="scss">
  177. .status_bar {
  178. width: 100%;
  179. background-color: #FFFFFF;
  180. }
  181. .top-content{
  182. width: 100%;
  183. position: fixed;
  184. top: 0;
  185. left: 0;
  186. z-index: 10;
  187. }
  188. .top-title{
  189. height: 88upx;
  190. line-height: 88upx;
  191. font-size: 42upx;
  192. font-family: Source Han Sans CN;
  193. font-weight: bold;
  194. color: #222222;
  195. padding-left: 41upx;
  196. background-color: #FFFFFF;
  197. }
  198. .search-cont{
  199. padding: 16upx 30upx;
  200. background-color: #FFFFFF;
  201. .inner{
  202. box-sizing: border-box;
  203. width: 100%;
  204. height: 72upx;
  205. background: #F7F7F7;
  206. border-radius: 36upx;
  207. display: flex;
  208. align-items: center;
  209. padding: 0 30upx;
  210. .icon-search{
  211. width: 28upx;
  212. height: 28upx;
  213. margin-right: 20upx;
  214. }
  215. input{
  216. height: 60upx;
  217. line-height: 60upx;
  218. flex: 1;
  219. }
  220. }
  221. }
  222. .keyword-list{
  223. box-sizing: border-box;
  224. background: #fff;
  225. padding: 10upx 27upx;
  226. height: 100upx;
  227. .inner{
  228. display: flex;
  229. }
  230. .item{
  231. flex-shrink: 0;
  232. padding: 0 24upx;
  233. height: 64upx;
  234. line-height: 64upx;
  235. font-size: 28upx;
  236. font-family: PingFang SC;
  237. font-weight: 500;
  238. color: #2BC7B9;
  239. background: #F5FFFE;
  240. border: 1px solid #2BC7B9;
  241. border-radius: 32upx;
  242. margin: 0 20upx 20upx 0;
  243. &.active{
  244. color: #FFFFFF;
  245. background: #2BC7B9;
  246. border: 1px solid #2BC7B9;
  247. }
  248. }
  249. }
  250. .know-list{
  251. margin-top: 20upx;
  252. padding: 0 10upx;
  253. .item{
  254. box-sizing: border-box;
  255. height: 271upx;
  256. background: #FFFFFF;
  257. border-radius: 16upx;
  258. padding: 40upx 30upx;
  259. display: flex;
  260. align-items: center;
  261. justify-content: space-between;
  262. margin-bottom: 20upx;
  263. .left{
  264. flex: 1;
  265. padding-right: 40upx;
  266. height: 190upx;
  267. display: flex;
  268. flex-direction: column;
  269. justify-content: space-between;
  270. .title{
  271. font-size: 32upx;
  272. font-family: PingFang SC;
  273. font-weight: 500;
  274. color: #111111;
  275. line-height: 48upx;
  276. }
  277. .info-box{
  278. width: 100%;
  279. display: flex;
  280. align-items: center;
  281. justify-content: space-between;
  282. .readers{
  283. display: flex;
  284. align-items: center;
  285. .head-box{
  286. margin-right: 27upx;
  287. display: flex;
  288. align-items: center;
  289. .head{
  290. width: 48upx;
  291. height: 48upx;
  292. border-radius: 50%;
  293. overflow: hidden;
  294. box-shadow: 0 0 0 1px #fff;
  295. margin-right: -10upx;
  296. image{
  297. width: 100%;
  298. height: 100%;
  299. }
  300. }
  301. }
  302. .readings{
  303. display: flex;
  304. align-items: center;
  305. .eye{
  306. width: 26upx;
  307. height: 20upx;
  308. margin-right: 9upx;
  309. }
  310. .num{
  311. font-size: 24upx;
  312. font-family: PingFang SC;
  313. font-weight: 500;
  314. color: #999999;
  315. line-height: 1;
  316. }
  317. }
  318. }
  319. .time{
  320. font-size: 24upx;
  321. line-height: 1;
  322. font-family: PingFang SC;
  323. font-weight: 500;
  324. color: #999999;
  325. }
  326. }
  327. }
  328. .right{
  329. width: 250upx;
  330. height: 190upx;
  331. border-radius: 8upx;
  332. overflow: hidden;
  333. image{
  334. width: 100%;
  335. height: 100%;
  336. }
  337. }
  338. }
  339. }
  340. </style>