123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- <template>
- <view>
- <view class="top-content">
- <!-- 这里是状态栏 -->
- <view class="status_bar" :style="{height: statusBarHeight}"></view>
- <!-- #ifdef APP -->
- <view class="top-title" style="padding-top: 70rpx;">健康百科</view>
- <!-- #endif -->
- <!-- 除了app外其它都生效 -->
- <!-- #ifndef APP -->
- <view class="top-title">健康百科</view>
- <!-- #endif -->
- <!-- 搜索框 -->
- <view class="search-cont">
- <view class="inner">
- <image class="icon-search" src="../../static/images/search.png" mode=""></image>
- <input type="text" v-model="searchValue" placeholder="输入关键字搜索" confirm-type="search" @confirm="doSearch" placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
- </view>
- </view>
- <view class="keyword-list">
- <!-- 关键字列表 -->
- <scroll-view scroll-x="true" >
- <view class="inner">
- <view v-for="(item,index) in cates" :key="index" :class="choseCateId == item.cateId?'item active':'item'" @click="choseCate(item)">
- {{ item.cateName }}
- </view>
- </view>
- </scroll-view>
- </view>
- </view>
- <!-- 知识列表 -->
- <mescroll-body :top="top" bottom="50px" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
- <view class="know-list">
- <view class="item" v-for="(item,index) in dataList" :key="index" @click="showDetail(item)">
- <view class="left">
- <view class="title ellipsis2">{{ item.title }}</view>
- <view class="info-box">
- <view class="readers">
- <view class="head-box" v-if="item.viewsList!=null&&item.viewsList.length>0">
- <view class="head" v-for="(subitem,j) in item.viewsList" :key="j" v-if="subitem!=null">
- <image :src="subitem.avatar==null?'../../static/images/detault_head.jpg':subitem.avatar" mode=""></image>
- </view>
- </view>
- <view class="readings">
- <image class="eye" src="../../static/images/eye.png" ></image>
- <text class="num">{{item.views}}</text>
- </view>
- </view>
- <view class="time">{{item.publishTime}}</view>
- </view>
- </view>
- <view class="right">
- <image :src="item.imageUrl" mode="aspectFill"></image>
- </view>
- </view>
- </view>
- </mescroll-body>
- <tabbar :actindex="2"></tabbar>
- </view>
- </template>
- <script>
- import {getArticleCate,getArticleList} from '@/api/article'
- import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
- export default {
- mixins: [MescrollMixin],
- data() {
- return {
- top:'0px',
- cates:[],
- choseCateId:0,
- // 状态栏的高度
- statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
- searchValue: '',
- mescroll:null,
- // 上拉加载的配置
- downOption:{
-
- },
- upOption: {
- onScroll:true,
- use: true, // 是否启用上拉加载; 默认true
- page: {
- num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
- size: 10 // 每页数据的数量,默认10
- },
- noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
- empty: {
- icon:'/static/images/no_data.png',
- tip: '暂无数据'
- },
- textNoMore:'已经到底了'
- },
- // 列表数据
- dataList: [],
- };
- },
- onShow() {
- uni.hideTabBar();
- this.getArticleCate();
- var that=this;
- setTimeout(function(){
- let query = uni.createSelectorQuery().select(".top-content");
- query.boundingClientRect(function(data) { //data - 各种参数
- console.log(data.height) // 获取元素宽度
- that.top=data.height+"px";
- }).exec()
- },500);
-
- // let info1 = uni.createSelectorQuery().select(".keyword-list");
- // info1.boundingClientRect(function(data) { //data - 各种参数
- // console.log(data.height) // 获取元素宽度
-
- // }).exec()
-
- },
- methods:{
- doSearch(){
- console.log(this.searchValue)
- this.mescroll.resetUpScroll()
- },
- getArticleCate(){
- var that=this;
- let data = {};
- getArticleCate(data).then(
- res => {
- if(res.code==200){
- this.cates=res.data;
-
-
- }else{
- uni.showToast({
- icon:'none',
- title: "请求失败",
- });
- }
- },
- rej => {}
- );
- },
- mescrollInit(mescroll) {
- this.mescroll = mescroll;
- },
- /*下拉刷新的回调 */
- downCallback(mescroll) {
- mescroll.resetUpScroll()
- },
- upCallback(page) {
- //联网加载数据
- var that = this;
- var data = {
- keyword:this.searchValue,
- cateId:this.choseCateId,
- page: page.num,
- pageSize: page.size
- };
- getArticleList(data).then(res => {
- if(res.code==200){
- //设置列表数据
- if (page.num == 1) {
- that.dataList = res.data.list;
-
- } else {
- that.dataList = that.dataList.concat(res.data.list);
-
- }
- that.mescroll.endBySize(res.data.list.length, res.data.total);
-
- }else{
- uni.showToast({
- icon:'none',
- title: "请求失败",
- });
- that.dataList = null;
- that.mescroll.endErr();
- }
- });
- },
- // 关键词选择
- choseCate(item) {
- this.choseCateId = item.cateId;
- this.mescroll.resetUpScroll()
- },
- // 查看详情
- showDetail(item) {
- uni.navigateTo({
- url: './detail?articleId=' + item.articleId
- })
- }
- }
- }
- </script>
- <style lang="scss">
- .status_bar {
- width: 100%;
- background-color: #FFFFFF;
- }
- .top-content{
- width: 100%;
- position: fixed;
- top: 0;
- left: 0;
- z-index: 10;
- }
- .top-title{
- height: 88upx;
- line-height: 88upx;
- font-size: 42upx;
- font-family: Source Han Sans CN;
- font-weight: bold;
- color: #222222;
- padding-left: 41upx;
- background-color: #FFFFFF;
- }
- .search-cont{
- padding: 16upx 30upx;
- background-color: #FFFFFF;
- .inner{
- box-sizing: border-box;
- width: 100%;
- height: 72upx;
- background: #F7F7F7;
- border-radius: 36upx;
- display: flex;
- align-items: center;
- padding: 0 30upx;
- .icon-search{
- width: 28upx;
- height: 28upx;
- margin-right: 20upx;
- }
- input{
- height: 60upx;
- line-height: 60upx;
- flex: 1;
- }
- }
- }
- .keyword-list{
- box-sizing: border-box;
- background: #fff;
- padding: 10upx 27upx;
- height: 100upx;
- .inner{
- display: flex;
- }
- .item{
- flex-shrink: 0;
- padding: 0 24upx;
- height: 64upx;
- line-height: 64upx;
- font-size: 28upx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #018C39;
- background: #F5FFFE;
- border: 1px solid #018C39;
- border-radius: 32upx;
- margin: 0 20upx 20upx 0;
- &.active{
- color: #FFFFFF;
- background: #018C39;
- border: 1px solid #018C39;
- }
- }
- }
- .know-list{
- margin-top: 20upx;
- padding: 0 10upx;
- .item{
- box-sizing: border-box;
- height: 271upx;
- background: #FFFFFF;
- border-radius: 16upx;
- padding: 40upx 30upx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 20upx;
- .left{
- flex: 1;
- padding-right: 40upx;
- height: 190upx;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- .title{
- font-size: 32upx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #111111;
- line-height: 48upx;
- }
- .info-box{
- width: 100%;
- display: flex;
- align-items: center;
- justify-content: space-between;
- .readers{
- display: flex;
- align-items: center;
- .head-box{
- margin-right: 27upx;
- display: flex;
- align-items: center;
- .head{
- width: 48upx;
- height: 48upx;
- border-radius: 50%;
- overflow: hidden;
- box-shadow: 0 0 0 1px #fff;
- margin-right: -10upx;
- image{
- width: 100%;
- height: 100%;
- }
- }
- }
- .readings{
- display: flex;
- align-items: center;
- .eye{
- width: 26upx;
- height: 20upx;
- margin-right: 9upx;
- }
- .num{
- font-size: 24upx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #999999;
- line-height: 1;
- }
- }
- }
- .time{
- font-size: 24upx;
- line-height: 1;
- font-family: PingFang SC;
- font-weight: 500;
- color: #999999;
- }
- }
- }
- .right{
- width: 250upx;
- height: 190upx;
- border-radius: 8upx;
- overflow: hidden;
- image{
- width: 100%;
- height: 100%;
- }
- }
- }
- }
- </style>
|