index.vue 8.4 KB

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