2023-03-28 18:04:49 +08:00
|
|
|
import Vue from 'vue'
|
|
|
|
import Vuex from 'vuex'
|
|
|
|
|
|
|
|
Vue.use(Vuex)
|
|
|
|
|
|
|
|
export default new Vuex.Store({
|
|
|
|
state: {
|
2023-04-07 16:49:43 +08:00
|
|
|
historicalSearch: [],
|
|
|
|
allForumList: [{}], // 全部板块数据
|
|
|
|
|
2023-03-28 18:04:49 +08:00
|
|
|
},
|
|
|
|
getters: {
|
|
|
|
},
|
2023-04-07 16:49:43 +08:00
|
|
|
|
2023-03-28 18:04:49 +08:00
|
|
|
mutations: {
|
2023-04-06 14:20:11 +08:00
|
|
|
setHistoricalSearch(state, payload) {
|
2023-04-07 16:49:43 +08:00
|
|
|
if (!Array.isArray(payload)) payload = [payload]
|
|
|
|
let targetArr = [...new Set([...payload, ...state.historicalSearch])]
|
|
|
|
if (targetArr.length > 10) targetArr = targetArr.slice(0, 10)
|
|
|
|
|
|
|
|
state.historicalSearch = targetArr
|
|
|
|
localStorage.setItem('historicalSearch', JSON.stringify(targetArr))
|
|
|
|
},
|
|
|
|
|
|
|
|
setAllForumList(state, payload) {
|
|
|
|
state.allForumList = payload
|
|
|
|
},
|
|
|
|
|
2023-03-28 18:04:49 +08:00
|
|
|
},
|
2023-04-07 16:49:43 +08:00
|
|
|
|
2023-03-28 18:04:49 +08:00
|
|
|
actions: {
|
2023-04-06 14:40:10 +08:00
|
|
|
// 获取历史搜索的数据
|
2023-04-06 14:20:11 +08:00
|
|
|
fetchHistoricalSearch({ commit }) {
|
|
|
|
let historicalSearch = JSON.parse(localStorage.getItem('historicalSearch')) || []
|
|
|
|
commit('setHistoricalSearch', historicalSearch)
|
2023-04-06 14:40:10 +08:00
|
|
|
},
|
2023-04-06 15:00:13 +08:00
|
|
|
|
2023-04-07 16:49:43 +08:00
|
|
|
// 获取全部板块的数据
|
|
|
|
getAllForum({ commit }, that) {
|
|
|
|
that.$startupUnderLoading(that)
|
|
|
|
that.$http.get("/api/home/allForum").then(res => {
|
|
|
|
if (res.code != 200) return;
|
|
|
|
let allForumList = res.data
|
|
|
|
commit('setAllForumList', allForumList)
|
|
|
|
|
|
|
|
}).catch(err => {
|
|
|
|
that.$message.error(err.message)
|
|
|
|
}).finally(() => {
|
|
|
|
that.$closeUnderLoading(that)
|
|
|
|
})
|
|
|
|
// allForumList
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-28 18:04:49 +08:00
|
|
|
},
|
|
|
|
modules: {
|
2023-04-06 18:00:11 +08:00
|
|
|
|
2023-03-28 18:04:49 +08:00
|
|
|
}
|
|
|
|
})
|
2023-04-06 18:00:11 +08:00
|
|
|
|