224 lines
4.6 KiB
Vue
Executable File

<template>
<div class="allSections">
<!-- 左选项 -->
<div class="allSections-left">
<span v-for="(item, index) in list" :class="{ 'active': index == allActive }" :key="index"
@click="allClick(index)">{{ item.name }}</span>
</div>
<!-- 右选项 -->
<div class="allSections-right">
<div class="allSections-right-item" v-for="(i, k) in list[allActive].data" :key="k">
<div class="item-content">
<div class="item-title">{{ i.name }}</div>
<div v-if="i.description" class="item-text" v-html="i.description.replace(/<[^>]+>/g, '')"></div>
</div>
<div class="item-star">
<img v-if="!i.iscollection" src="~assets/img/allSections/nullStar.png" alt="空星"
@click="starClick(k, i.fid)">
<img v-else src="~assets/img/allSections/star.png" alt="实星" @click="cancelCollection(k, i.fid)">
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: "AllSections",
data() {
return {
allActive: 0,
list: [{}],
postCollectionState: false, // 收藏的请求的状态
}
},
methods: {
allClick(index) {
this.allActive = index
},
// 点击收藏
starClick(k, fid) {
if (this.postCollectionState) return
this.postCollectionState = true
this.$http.post("/api/operation/forumFav", {
fid
}).then(res => {
if (res.code != 200) return
this.list[this.allActive].data[k]['iscollection'] = 1
this.$forceUpdate()
}).finally(() => {
this.postCollectionState = false
})
},
// 点击取消收藏
cancelCollection(k, fid) {
if (this.postCollectionState) return
this.postCollectionState = true
this.$http.post("/api/operation/unforumFav", {
fid
}).then(res => {
if (res.code != 200) return
this.list[this.allActive].data[k]['iscollection'] = 0
this.$Message({
})
this.$forceUpdate()
}).finally(() => {
this.postCollectionState = false
})
},
// 获取全部板块
getAllForum() {
this.$http.post("/api/home/allForum").then((res) => {
if (res.code != 200) return;
this.list = res.data
console.log("res.data", res.data);
}).catch(err => {
this.$message.error(err.message)
});
}
},
mounted() {
this.getAllForum()
},
}
</script>
<style lang="scss" scoped>
.allSections {
display: flex;
flex-direction: row;
border-radius: 0.32rem;
margin-top: 0.666667rem;
filter: drop-shadow(0.05rem 0 0.09rem rgba(0, 0, 0, 0.1));
margin: .64rem 0.35rem 0;
}
.allSections-left {
width: 35%;
border-left: 0.013333rem solid #ddd;
background-color: rgba(235, 235, 235, 0.556862745098039);
border-radius: 0.32rem 0 0 0.32rem;
display: flex;
flex-direction: column;
text-align: center;
span {
height: 1.28rem;
line-height: 1.28rem;
border-radius: 0.32rem;
font-size: 0.32rem;
// padding: 0 0 0 0.2rem;
position: relative;
&.active {
background-color: #fff;
font-weight: bolder;
border-radius: 0.32rem 0 0 0.32rem;
color: #000;
width: 105%;
margin-left: -0.133333rem;
filter: drop-shadow(0 0 0.08rem rgba(0, 0, 0, 0.1));
}
&.active::before {
content: "";
width: 0.36rem;
height: 101%;
position: absolute;
right: 0;
top: -100%;
box-shadow: 0.14rem 0.14rem #fff;
border-radius: 0 0 0.32rem 0;
}
&.active::after {
content: "";
width: 0.36rem;
height: 101%;
position: absolute;
right: 0;
bottom: -100%;
box-shadow: 0.14rem -0.14rem #fff;
border-radius: 0 0.32rem 0 0;
}
&:first-child.active::before {
display: none;
}
&:last-child.active::after {
display: none;
}
}
}
.allSections-right {
width: 65%;
background-color: #fff;
border-radius: 0 0.32rem 0.32rem 0;
display: flex;
flex-direction: column;
z-index: 1;
padding-bottom: 0.4rem;
&.active {
display: block;
}
.allSections-right-item {
padding: 0.4rem 0;
margin: 0 0.32rem 0 0.7rem;
border-bottom: 0.013333rem solid #ddd;
display: flex;
justify-content: space-between;
position: relative;
.item-content {
width: 80%;
}
.item-title {
color: #000;
font-size: 0.32rem;
}
.item-text {
margin: 0.266667rem 0;
color: #aaa;
font-size: 0.28rem;
}
.item-star {
display: flex;
align-items: center;
img {
width: .48rem;
height: .46rem;
}
}
&::before {
content: "";
width: 0.12rem;
height: 0.32rem;
border-radius: 0.16rem;
position: absolute;
top: 0.48rem;
left: -0.35rem;
background-color: #62b1ff;
}
}
}
</style>