+
+ {{ item.name }}

设置
+
设置收藏版块
-
共收藏 {{ list.length - 1 }} 个版块
+
共收藏 {{ favoriteHeadList.length - 1 }} 个版块
添加
-
-
-
{{ item.label }}
+
@@ -50,12 +50,24 @@
+
-
+
+
+
+
@@ -69,37 +81,155 @@ export default {
name: "Collect",
data() {
return {
- hotActive: 0, //热门版块活跃点击
+ allForumList: [], // 所有板块得数据
+ favoriteHeadList: [],
+ // favoriteHeadIdList: [],
+ favoriteHeadIdList: this.$parent.favorite,
+ fid: 0, // 选中的收藏板块
collect: [1],
settingShow: false, //弹窗显示
settingStar: false,
- list: [
- //版块
- {
- label: "全部",
- },
- {
- label: "香港留学",
- },
- {
- label: "香港留学",
- },
- {
- label: "香港留学",
- },
- ],
+ plate: {
+ stairname: "",// 一级版块名称
+ subsectionsname: "",// 子版块名称
+ },
+ favorite: { // 收藏板块
+ list: [],
+ limit: 20,
+ page: 1,
+ count: 0
+ },
+ loading: null,
+
+
};
},
+
+ watch: {
+ "$store.state.homeRequestState": {
+ handler(newV, oldV) {
+ console.log("newVnewV", newV);
+ // if (!newV) return
+ // this.$nextTick(() => {
+ // this.favoriteHeadIdList = this.$parent.favorite || []
+ // this.getAllForumList()
+
+ // if (this.fid) this.handleFavoriteHeadList()
+ // })
+
+ },
+ immediate: true
+ },
+
+ fid: {
+ handler(newV, oldV) {
+ if (this.$store.state.homeRequestState && newV) this.handleFavoriteHeadList()
+ },
+ immediate: true
+ }
+ },
mounted() {
-
- },
- components: {
- plateNavigation,
- indexList
+ let { page, fid } = this.$route.query
+ if (page) this.favorite.page = Number(page)
+ if (fid) this.fid = fid
+
+ this.getCollectList()
+
+ if (this.favoriteHeadIdList.length != 0) this.getAllForumList()
+
+ this.$store.subscribe((mutation, state) => {
+ if (mutation.type == "setHomeRequestState" && mutation.payload) {
+ if (!this.$store.state.homeRequestState) return
+ this.$nextTick(() => {
+ this.favoriteHeadIdList = this.$parent.favorite || []
+ this.getAllForumList()
+
+ if (this.fid) this.handleFavoriteHeadList()
+ })
+ }
+ });
},
+
methods: {
- hotLabelClick(index) {
- this.hotActive = index;
+ // 获取收藏列表数据
+ getCollectList() {
+ this.$startupUnderLoading(this)
+ this.$http.post("/api/home/threadList", {
+ limit: this.favorite.limit,
+ page: this.favorite.page,
+ fid: this.fid,
+ type: "fav"
+ }).then(res => {
+ if (res.code != 200) return
+ let data = res.data
+
+ this.favorite.list = data.data
+ this.favorite.page = data.page
+ this.favorite.limit = data.limit
+ this.favorite.count = data.count
+ }).finally(() => {
+ this.$closeUnderLoading(this)
+ })
+ },
+
+ // 获取全部板块数据
+ getAllForumList() {
+ let allForumList = this.$store.state.allForumList
+ if (allForumList.length == 1) {
+ setTimeout(() => {
+ this.getAllForumList()
+ }, 500);
+ } else {
+ this.allForumList = allForumList
+ this.handleFavoriteHeadList()
+ }
+ },
+
+ // 处理获取收藏板块的值
+ handleFavoriteHeadList() {
+ let allForumList = this.allForumList
+ let favoriteHeadIdList = this.favoriteHeadIdList
+ let favoriteHeadList = [{
+ name: "全部",
+ fid: 0
+ }]
+
+ allForumList.forEach((el, index) => {
+ if (!Array.isArray(el.data)) return
+ el.data.forEach(elememt => {
+ if (elememt.fid == this.fid) {
+ this.plate.stairname = el.name
+ this.plate.subsectionsname = elememt.name
+ }
+
+ if (favoriteHeadIdList.includes(elememt.fid)) {
+ favoriteHeadList.push({
+ fid: elememt.fid,
+ name: elememt.name,
+ })
+ }
+ })
+
+ })
+
+ this.favoriteHeadList = favoriteHeadList
+ },
+
+ currentChange() {
+ let query = {
+ page: this.favorite.page,
+ }
+ if (this.fid) query['fid'] = this.fid
+
+ this.$router.push({ path: `/collect`, query })
+ },
+
+ hotLabelClick(fid) {
+ let query = {
+ page: 1,
+ fid
+ }
+ this.$router.push({ path: `/collect`, query })
},
// 点击显示弹窗
settingClick() {
@@ -110,11 +240,36 @@ export default {
this.settingShow = false;
},
// 处理取消收藏板块
- cancelFavoritesSection(index) {
- this.list.splice(index, 1)
+ cancelFavoritesSection(fid, index) {
+ let url = "/api/operation/unforumFav"
+
+ this.$http.post(url, {
+ fid
+ }).then(res => {
+ if (res.code != 200) return
+
+ let list = this.$store.state.allForumList
+ console.log(list, "list");
+ // list[this.allActive].data[k]['iscollection'] = state == "forumFav" ? 1 : 0
+
+ this.$store.commit('setAllForumList', list)
+
+ this.favoriteHeadList.splice(index, 1)
+
+ this.$Message.success(res.message)
+ }).finally(() => {
+ this.$store.commit('setHomeRequestState', false)
+ this.$parent.init()
+ })
+
+
}
},
+ components: {
+ plateNavigation,
+ indexList
+ },
};
@@ -314,6 +469,7 @@ export default {
.paging {
margin-top: .48rem;
+ padding-bottom: 1rem;
::v-deep {
.el-pagination.is-background .el-pager li:not(.disabled).active {
diff --git a/src/views/index/index.vue b/src/views/index/index.vue
index f85336a..eae7c9a 100755
--- a/src/views/index/index.vue
+++ b/src/views/index/index.vue
@@ -42,10 +42,21 @@ export default {
},
methods: {
init() {
+ let homeRequestState = this.$store.state.homeRequestState
+ if (homeRequestState) {
+ let { favoriteList, recommendList } = this.$store.state
+ this.favorite = favoriteList
+ this.recommend = recommendList
+ return
+ }
+
this.$http.post("/api/home").then(res => {
let data = res.data
this.favorite = data.favorite
this.recommend = data.recommend
+ this.$store.commit('setHomeRequestState', true)
+ this.$store.commit('setFavoriteList', data.favorite)
+ this.$store.commit('setRecommendList', data.recommend)
})
},
}
diff --git a/src/views/index/recommend/Recommend.vue b/src/views/index/recommend/Recommend.vue
index d442a22..fe02230 100755
--- a/src/views/index/recommend/Recommend.vue
+++ b/src/views/index/recommend/Recommend.vue
@@ -2,15 +2,21 @@
-
{{ item.name }}
+
{{ item.name }}
-
-
-
+
+
+
+
+
+
+

@@ -23,38 +29,106 @@
import plateNavigation from '@/components/PlateNavigation.vue'
import indexList from '@/components/IndexList'
export default {
- name: "Recommend",//推荐阅读444kljjkli
+ name: "Recommend",//推荐阅读
data() {
return {
- hotActive: -1,//热门版块活跃点击
hotList: [],
list: [],
+ count: 0, // 总数
+ limit: 20, // 列表
+ page: 1, // 页数
fid: 0, // 板块id
plate: {
stairname: "",// 一级版块名称
subsectionsname: "",// 子版块名称
},
+
+ loading: null,
+ allForumList: this.$store.state.allForumList,
}
},
watch: {
"$parent.recommend": {
handler(newV, oldV) {
- console.log(newV);
this.hotList = newV
},
immediate: true
+ },
+
+ "$store.state.allForumList": {
+ handler(newV, oldV) {
+ this.allForumList = newV
+ this.handleForumFid()
+ },
+ immediate: true
}
},
mounted() {
- console.log(this.$parent.recommend);
+ let { page, fid } = this.$route.query
+ if (page) this.page = Number(page)
+ if (fid) {
+ this.fid = fid
+ this.handleForumFid()
+ }
+
+ this.init()
},
methods: {
- hotLabelClick(index, fid) {
- console.log(fid);
- this.fid = fid
- this.hotActive = index
+ init() {
+ this.$startupUnderLoading(this)
+ this.$http.post("/api/home/threadList", {
+ limit: this.limit,
+ type: "recommend",
+ page: this.page,
+ fid: this.fid,
+ }).then(res => {
+ console.log(res, "ffff");
+
+ if (res.code != 200) return
+ let data = res.data
+ this.list = data.data
+ this.limit = data.limit
+ this.page = data.page
+ this.count = data.count
+ }).finally(() => {
+ this.$closeUnderLoading(this)
+
+ })
+ },
+
+ // 初始化板块的头部
+ handleForumFid() {
+ let allForumList = this.allForumList
+ if (!Array.isArray(allForumList) || allForumList.length <= 1) return
+ allForumList.forEach((el, index) => {
+ if (!Array.isArray(el['data'])) return
+ el.data.forEach(element => {
+ if (element['fid'] == this.fid) {
+ this.plate.subsectionsname = element.name
+ this.plate.stairname = el.name
+ }
+
+ })
+ })
+ },
+
+ currentChange() {
+ let query = {
+ page: this.page,
+ }
+ if (this.fid) query['fid'] = this.fid
+
+ this.$router.push({ path: `/recommend`, query })
+ },
+
+ hotLabelClick(fid) {
+ let query = {
+ page: 1,
+ fid
+ }
+ this.$router.push({ path: `/recommend`, query })
}
},
components: {
@@ -65,8 +139,13 @@ export default {
\ No newline at end of file