From d82c425491c33102de7024cfdbccb4b39bc9330f Mon Sep 17 00:00:00 2001
From: xiaoronghao <1300399510@qq.com>
Date: Tue, 11 Apr 2023 17:56:16 +0800
Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package.json | 1 +
src/App.vue | 9 +-
src/components/DetailReply.vue | 2 +-
src/components/HeaderNav.vue | 42 +++++---
src/components/SearchBox.vue | 1 -
src/main.js | 3 +
src/store/index.js | 54 +++++++++-
src/utils/common.js | 4 +-
src/views/detail/detail.vue | 3 +-
src/views/detail/detailIndex.vue | 87 +++++++++++------
src/views/index/allSections/AllSections.vue | 29 +++++-
src/views/index/collect/Collect.vue | 103 +++++++-------------
src/views/index/index.vue | 32 +++---
src/views/index/recommend/Recommend.vue | 5 +-
src/views/index/recommend/Recommend.vue.rej | 10 --
15 files changed, 228 insertions(+), 157 deletions(-)
delete mode 100644 src/views/index/recommend/Recommend.vue.rej
diff --git a/package.json b/package.json
index d8966d3..286887c 100755
--- a/package.json
+++ b/package.json
@@ -14,6 +14,7 @@
"svg-sprite-loader": "^6.0.11",
"vue": "^2.6.14",
"vue-router": "^3.5.1",
+ "vue-sanitize": "^0.2.3",
"vuex": "^3.6.2"
},
"devDependencies": {
diff --git a/src/App.vue b/src/App.vue
index 54f7211..bf32625 100755
--- a/src/App.vue
+++ b/src/App.vue
@@ -15,9 +15,14 @@ export default {
loading: null,
}
},
+ watch:{
+
+ },
+
mounted() {
- this.$store.dispatch('fetchHistoricalSearch')
- this.$store.dispatch('getAllForum', this)
+ this.$store.dispatch('fetchHistoricalSearch') // 获取历史搜索记录
+ this.$store.dispatch('getAllForum', this) // 获取全部板块
+ // this.$store.dispatch('getUserInfo', this) /// 获取用户信息
},
}
diff --git a/src/components/DetailReply.vue b/src/components/DetailReply.vue
index ecf5ffb..a49b199 100755
--- a/src/components/DetailReply.vue
+++ b/src/components/DetailReply.vue
@@ -60,7 +60,7 @@ export default {
props: ["twoCommentData", "popState", "commentContent"],
mounted() {
- console.log("子组件");
+ // console.log("子组件");
},
methods: {
diff --git a/src/components/HeaderNav.vue b/src/components/HeaderNav.vue
index 1e22365..4e9eaa1 100755
--- a/src/components/HeaderNav.vue
+++ b/src/components/HeaderNav.vue
@@ -76,36 +76,48 @@ export default {
tab: "Offer榜",
headMorePopState: false, // 弹窗的状态
islogin: false,
- userInfo: {},
+ userInfo: {}, // 注意 userInfo 写I 是否是大写 ,, 因为 user 已经改为全局,后面要删除传值的 user
menu: [],
hotSearchkeywords: [], // 热门搜索
};
},
props: ["issearch", "needgetuser", "userinfo"],
watch: {
- needgetuser: {
- handler(newValue, oldValue) {
- if (newValue) this.getUserInfoData();
- },
- immediate: true,
- },
+ // needgetuser: {
+ // handler(newValue, oldValue) {
+ // // if (newValue) this.getUserInfoData();
+ // },
+ // immediate: true,
+ // },
+
+ // userinfo(newValue, oldValue) {
+ // this.userInfo = newValue;
+ // this.islogin = newValue.uid > 0 ? true : false;
+ // },
- userinfo(newValue, oldValue) {
- this.userInfo = newValue;
- this.islogin = newValue.uid > 0 ? true : false;
- },
headMorePopState(newValue, oldValue) {
if (newValue) this.$pageStop();
else this.$pageMove();
},
},
mounted() {
- this.getMenu()
+ let user = this.$store.state.user
+ if (JSON.stringify(user) === "{}") this.$store.dispatch('getUserInfo', this)
+ else {
+ this.userInfo = user
+ this.islogin = user.uid > 0 ? true : false;
+ this.hotSearchkeywords = this.$store.state.hotSearchkeywords
+ }
+
+ // this.getMenu()
+
+
},
components: {
SearchBox,
},
+
methods: {
// 处理登录
handleRegister() {
@@ -115,17 +127,17 @@ export default {
// 获取用户信息
getUserInfoData() {
+ return
// this.$http.post("/widget/getUser").then((res) => {
this.$http.post("/api/index",).then((res) => {
if (res.code != 200) return;
- // this.prototype.userInfo = res.data.user
this.userInfo = res.data.user;
this.islogin = res.data.user.uid > 0 ? true : false;
this.hotSearchkeywords = res.data.hotSearchkeywords
}).catch(err => {
- this.$message.error(err.message)
- });
+ this.$message.error(err.message)
+ });
},
getMenu() {
diff --git a/src/components/SearchBox.vue b/src/components/SearchBox.vue
index ceb36c1..6ccdc47 100755
--- a/src/components/SearchBox.vue
+++ b/src/components/SearchBox.vue
@@ -53,7 +53,6 @@ export default {
mounted() {
if (this.searchText.length > 0) this.showClear = true
else this.showClear = false
-
},
methods: {
diff --git a/src/main.js b/src/main.js
index 56f9b90..9ece1ac 100755
--- a/src/main.js
+++ b/src/main.js
@@ -6,6 +6,8 @@ import ElementUI, { Message, Pagination, loading } from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import { skipUrl, pageStop, pageMove, goTologin, copy, startupUnderLoading, closeUnderLoading, formattedDate, updateURLSearchParams } from "@/utils/common.js"
import http from "@/utils/request"
+import VueSanitize from 'vue-sanitize'
+
import hintBox from '@/components/Hintbox'
Vue.config.productionTip = false
@@ -45,6 +47,7 @@ if (!Array.isArray) {
Vue.use(ElementUI);
Vue.use(Pagination);
+Vue.use(VueSanitize);
new Vue({
diff --git a/src/store/index.js b/src/store/index.js
index a7460bb..bb790fc 100755
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -6,10 +6,14 @@ Vue.use(Vuex)
export default new Vuex.Store({
state: {
historicalSearch: [],
- allForumList: [{}], // 全部板块数据
- homeRequestState: false, // 首页推荐和收藏接口的数据请求状态
+ allForumList: [], // 全部板块数据
+ homeRequestState: false, // 首页推荐和收藏接口的数据请求状态 这个是是否需要发送请求,因为用户点击收藏后需要重新获取
+ getUserInfoState: false, // 这个是是否在请求状态
favoriteList: [],
recommendList: [],
+ user: {}, // 用户信息
+ hotSearchkeywords: [], // 热门搜索
+ loading: null,
},
getters: {
},
@@ -40,6 +44,18 @@ export default new Vuex.Store({
state.recommendList = payload
},
+ setUser(state, payload) {
+ state.user = payload
+ },
+
+ setHotSearchkeywords(state, payload) {
+ state.hotSearchkeywords = payload
+ },
+
+ setgetUserInfoState(state, payload) {
+ state.getUserInfoState = payload
+ },
+
},
actions: {
@@ -51,6 +67,7 @@ export default new Vuex.Store({
// 获取全部板块的数据
getAllForum({ commit }, that) {
+ // getAllForum(commit, that) {
that.$startupUnderLoading(that)
that.$http.get("/api/home/allForum").then(res => {
if (res.code != 200) return;
@@ -62,9 +79,38 @@ export default new Vuex.Store({
}).finally(() => {
that.$closeUnderLoading(that)
})
- // allForumList
- }
+ },
+
+ // 获取用户信息 获取收藏信息那些数据
+ getUserInfo({ state, commit }, that) {
+ if (state.getUserInfoState) return
+ commit('setgetUserInfoState', true)
+ // that.$startupUnderLoading(that)
+ that.$http.post("/api/home").then(res => {
+ if (res.code != 200) return;
+ let data = res.data
+ let { config, favorite, hotSearchkeywords, recommend, user } = data
+
+ commit('setHomeRequestState', true)
+ commit('setUser', user)
+ commit('setFavoriteList', favorite)
+ commit('setRecommendList', recommend)
+ commit('setHotSearchkeywords', hotSearchkeywords)
+
+ if (that.userInfo) { // 这个是顶部用户数据的 这样不用监听是否请求成功
+ that.userInfo = user
+ that.islogin = user.uid > 0 ? true : false;
+ that.hotSearchkeywords = hotSearchkeywords
+ }
+
+ }).catch(err => {
+ that.$message.error(err.message)
+ }).finally(() => {
+ // that.$closeUnderLoading(that)
+ commit('setgetUserInfoState', false)
+ })
+ },
},
diff --git a/src/utils/common.js b/src/utils/common.js
index 80c0b26..d808404 100755
--- a/src/utils/common.js
+++ b/src/utils/common.js
@@ -48,6 +48,8 @@ function copy(value, message) {
// 启动加载中
function startupUnderLoading(that) {
+
+ // this.
that.loading = that.$loading({
lock: true,
text: '加载中...',
@@ -57,7 +59,7 @@ function startupUnderLoading(that) {
// 关闭加载中
function closeUnderLoading(that) {
- that.loading.close();
+ that.loading && that.loading.close();
that.loading = null
}
diff --git a/src/views/detail/detail.vue b/src/views/detail/detail.vue
index 11b70d3..68afbfa 100755
--- a/src/views/detail/detail.vue
+++ b/src/views/detail/detail.vue
@@ -3,7 +3,7 @@