You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

326 lines
7.3 KiB

4 years ago
<template>
<view class="konwledge-index">
3 years ago
<view class="tabs">
<scroll-view class="scroll-view_H" scroll-x="true" scroll-with-animation :scroll-left='scrollLeft'>
<view class="tab-item scroll-item" :class="index == tabSelect ? 'tab-item-active' : ''"
v-for="(item,index) in tabList" :key="item.id"
@click="tabChange(item,index)">{{item.categoryName}}</view>
</scroll-view>
</view>
<view class="tab-box">
4 years ago
<view class="introduce-box acea-row">
<view class="left-box"></view>
<view class="right-box">
3 years ago
<view class="title-txt">{{currentTab.categoryName}}</view>
<view class="desc line5">
<text>{{currentTab.categoryDetails || '暂无'}}</text>
4 years ago
</view>
</view>
</view>
4 years ago
<SecondMenu
4 years ago
:menuList="secondMenu"
:active.sync="active"
@secondMenuClick="secondMenuClick">
</SecondMenu>
3 years ago
</view>
<view class="content-box">
4 years ago
<view class="knowledge-list">
3 years ago
<view class="knowledge-item acea-row" v-if="articleList.length > 0" v-for="item in articleList" @click="toDetail(item.id)">
4 years ago
<view class="img-box">
3 years ago
<image :src="item.imageInput" mode="aspectFill"></image>
4 years ago
</view>
3 years ago
<view class="knowledge-info-box acea-row row-column row-between">
3 years ago
<view style="width: 100%;">
3 years ago
<view class="title line1">{{item.title}}</view>
3 years ago
<view class="intro">{{item.synopsis}}</view>
3 years ago
</view>
4 years ago
<view class="type-box acea-row">
3 years ago
<view class="tip" :class="item.chargeType == 0 ? 'free-bg' : item.chargeType == 1 ? '' : 'jifen'">
{{item.chargeType == 0 ? '免费' : item.chargeType == 1 ? '收费' : '积分'}}
</view>
4 years ago
<view class="time">{{item.addTime}}</view>
</view>
</view>
</view>
3 years ago
<view class="no-content" v-if="articleList.length == 0">暂无内容...</view>
4 years ago
</view>
</view>
</view>
</template>
<script>
import SecondMenu from './components/secondMenu.vue';
3 years ago
import { getArticleCategorys,getArticle } from '@/api/knowledge';
4 years ago
export default {
data() {
return {
3 years ago
windowWidth:'',
tabSelect:0,
scrollLeft:0,
currentTab:null,
showView:true,
isFixedTop:false,
4 years ago
TabCur: null,
tabList: [],
secondMenu:[],
active:null,
3 years ago
articleList:[],
tabHeight:0,
scrollTop:0
4 years ago
}
},
3 years ago
components: { SecondMenu },
onShow() {
console.log(this.tabSelect,'tabSelect')
},
onLoad(){
getArticleCategorys().then((res)=>{
4 years ago
this.tabList = res.data
3 years ago
this.$set(this, 'currentTab', res.data[0])
4 years ago
this.$set(this, 'tabList', res.data)
this.$set(this, 'secondMenu', res.data[0].categoryList)
if(res.data[0].categoryList.length > 0){
this.$set(this, 'active', res.data[0].categoryList[0].id)
3 years ago
} else{
// this.$set(this, 'tabSelect', 0)
// this.scrollLeft = 0
4 years ago
}
}).then(()=>{
this.getArticle()
})
},
methods: {
toDetail(id){
this.$yrouter.push({
path: '/pages/knowledge/detail',
query: {
id: id,
},
})
},
getArticle(){
3 years ago
uni.showLoading({
title:'正在加载中...'
})
4 years ago
var cid = null;
3 years ago
this.active == null ? cid = this.currentTab.id : cid = this.active
4 years ago
getArticle({cid:cid}).then((res)=>{
3 years ago
uni.hideLoading()
4 years ago
if(res.success){
this.articleList = res.data
}
})
},
3 years ago
tabChange(item,index) {
this.currentTab = item
this.tabSelect = index
this.moveTo(index)
4 years ago
if(item.categoryList.length > 0){
this.$set(this, 'active', item.categoryList[0].id)
}
3 years ago
this.secondMenu = item.categoryList
4 years ago
this.getArticle()
},
3 years ago
// 将点击元素移动到中间
moveTo(index) {
const query = uni.createSelectorQuery().in(this)
query.selectAll(`.scroll-item`).boundingClientRect(rect => {
const windowWidth = this.windowWidth // 屏幕宽度
let width = 0
// 循环获取计算当前点击的标签项距离左侧的距离
for (let i = 0; i < index; i++) {
width += rect[i].width
}
// 当大于屏幕一半的宽度则滚动,否则就设置位置为0
if (width > windowWidth / 2) {
this.scrollLeft = width + rect[index].width / 2 - windowWidth / 2
} else {
this.scrollLeft = 0
}
}).exec()
},
4 years ago
secondMenuClick(item){
this.active = item.id;
this.getArticle()
}
}
}
</script>
<style scoped lang="less">
.konwledge-index{
background: #fff;
min-height: 100%;
3 years ago
padding-top: 110rpx;
.tab-box{
// position: fixed;
// top: 0;
background: #fff;
/deep/.second-menu-box {
padding: 0 24rpx;
}
}
.tabs{
width:100%;
height: 96rpx;
padding-left: 20rpx;
position: fixed;
top: 0;
background: #fff;
z-index: 10;
.scroll-view_H{
white-space: nowrap;
width: 100%;
height: 96rpx;
}
.tab-item{
height: 96rpx;
line-height: 96rpx;
display: inline-block;
margin-right: 40rpx;
font-size: 32rpx;
color: #999999;
}
.tab-item-active{
3 years ago
color: #F99C10;
border-bottom: 2px solid #F99C10;
3 years ago
font-weight: bold;
}
}
.fixed{
position: -webkit-sticky;
position: sticky;
top: 0;
z-index: 99;
}
4 years ago
.content-box{
width: 100%;
box-sizing: border-box;
padding: 0 24rpx;
}
.introduce-box{
3 years ago
width: calc(100% - 60rpx);
height: auto;
3 years ago
box-shadow: 0px 6rpx 14rpx 8rpx rgba(255, 237, 204, 1);
4 years ago
border-radius: 8px;
overflow: hidden;
3 years ago
margin: 10rpx auto 30rpx;
3 years ago
padding-bottom: 30rpx;
padding-left: 10rpx;
position: relative;
4 years ago
.right-box{
width: calc(100% - 16rpx);
padding: 30rpx 50rpx 0 24rpx;
font-size: 26rpx;
color: #999;
.title-txt{
font-size: 36rpx;
font-weight: 500;
color: #3C464F;
line-height: 50rpx;
font-weight: 600;
margin-bottom: 20rpx;
}
.desc{
text-indent: 1em;
}
}
}
3 years ago
.introduce-box::after{
content: '';
display: block;
width: 16rpx;
height: 100%;
3 years ago
// background: #F7D08E;
3 years ago
position: absolute;
left: -1rpx;
top: 50%;
border-radius: 50px;
transform: translateY(-50%);
}
4 years ago
.knowledge-list{
width: 100%;
3 years ago
.no-content{
font-size: 28rpx;
color: #666666;
text-align: center;
padding: 30rpx 0;
}
4 years ago
.knowledge-item{
border-bottom: 1px solid #ECECEC;
padding-bottom: 20rpx;
margin-bottom: 20rpx;
.img-box{
width: 204rpx;
height: 200rpx;
margin-right: 30rpx;
image{
width: 100%;
height: 100%;
3 years ago
border-radius: 10rpx;
4 years ago
}
}
.knowledge-info-box{
width: calc(100% - 234rpx);
.title{
3 years ago
font-size: 32rpx;
4 years ago
color: #333;
font-size: 500;
3 years ago
line-height: 32rpx;
4 years ago
}
.intro{
3 years ago
// height: 82rpx;
4 years ago
font-size: 28rpx;
color: #999999;
line-height: 40rpx;
margin: 8rpx 0 36rpx;
3 years ago
overflow:hidden;
text-overflow:ellipsis;
display:-webkit-box;
-webkit-box-orient:vertical;
-webkit-line-clamp:2;
4 years ago
}
.type-box{
font-size: 24rpx;
color: #999;
.tip{
width: 60rpx;
3 years ago
font-size: 20rpx;
color: #FFAD3A;
4 years ago
height: 34rpx;
text-align: center;
3 years ago
line-height: 34rpx;
background: #fcd391;
border-radius: 10rpx;
4 years ago
margin-right: 20rpx;
}
3 years ago
.free-bg{
background: #8FB85B;
color: #D7FFA4;
4 years ago
}
3 years ago
.jifen{
background: #AAC8FA;
color: #5693F9;
4 years ago
}
}
}
}
}
}
.text-black{
font-size: 32rpx;
}
.text-orange{
3 years ago
color: #E5270F;
4 years ago
font-size: 40rpx !important;
3 years ago
border-color: #E5270F;
4 years ago
}
</style>