no message

This commit is contained in:
A1300399510 2024-08-09 15:33:44 +08:00
parent 1abc53b06d
commit deffec9e26
4 changed files with 209 additions and 222 deletions

2
dist/index.html vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
import Vue from "vue"
import Vuex from "vuex"
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
@ -16,7 +16,8 @@ export default new Vuex.Store({
hotSearchkeywords: [], // 热门搜索
loading: null,
},
getters: {},
getters: {
},
mutations: {
setHistoricalSearch(state, payload) {
@ -25,7 +26,7 @@ export default new Vuex.Store({
if (targetArr.length > 10) targetArr = targetArr.slice(0, 10)
state.historicalSearch = targetArr
localStorage.setItem("historicalSearch", JSON.stringify(targetArr))
localStorage.setItem('historicalSearch', JSON.stringify(targetArr))
},
setAllForumList(state, payload) {
@ -58,92 +59,64 @@ export default new Vuex.Store({
setMenu(state, payload) {
state.menu = payload
},
}
},
actions: {
// 获取历史搜索的数据
fetchHistoricalSearch({ commit }) {
let historicalSearch = JSON.parse(localStorage.getItem("historicalSearch")) || []
commit("setHistoricalSearch", historicalSearch)
let historicalSearch = JSON.parse(localStorage.getItem('historicalSearch')) || []
commit('setHistoricalSearch', historicalSearch)
},
// 获取当前 HOST
// const host = window.location.hostname;
// 简单的哈希函数,返回十六进制字符串
simpleHash() {
const str = window.location.hostname
let hash = 0
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i)
hash = (hash << 5) - hash + char
hash |= 0 // Convert to 32bit integer
}
return (hash >>> 0).toString(16) // 将哈希值转换为无符号整数,然后转换为十六进制字符串
},
// // 生成唯一值
// const uniqueValue = simpleHash(host);
// console.log(uniqueValue); // 输出基于 HOST 生成的唯一值
// 获取全部板块的数据
getAllForum({ commit }, that) {
const str = window.location.hostname
let hash = 0
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i)
hash = (hash << 5) - hash + char
hash |= 0 // Convert to 32bit integer
}
const strr = (hash >>> 0).toString(16) // 将哈希值转换为无符号整数,然后转换为十六进制字符串
that.$http
.get("/api/home/allForum?" + strr)
.then(res => {
if (res.code != 200) return
that.$http.get("/api/home/allForum").then(res => {
if (res.code != 200) return;
let allForumList = res.data
commit("setAllForumList", allForumList)
})
.catch(err => {
commit('setAllForumList', allForumList)
}).catch(err => {
that.$message.error(err.message)
})
},
// 获取用户信息 获取收藏信息那些数据
getUserInfo({ state, commit }, that) {
if (state.getUserInfoState) return
commit("setgetUserInfoState", true)
that.$http
.post("/api/home")
.then(res => {
if (res.code != 200) return
commit('setgetUserInfoState', true)
that.$http.post("/api/home").then(res => {
if (res.code != 200) return;
let data = res.data
let { config, favorite, hotSearchkeywords, recommend, user, menu } = data
commit("setHomeRequestState", true)
commit("setUser", user)
commit("setFavoriteList", favorite)
commit("setRecommendList", recommend)
commit("setHotSearchkeywords", hotSearchkeywords)
commit("setMenu", menu)
commit('setHomeRequestState', true)
commit('setUser', user)
commit('setFavoriteList', favorite)
commit('setRecommendList', recommend)
commit('setHotSearchkeywords', hotSearchkeywords)
commit('setMenu', menu)
if (that.userInfo) {
// 这个是顶部用户数据的 这样不用监听是否请求成功
if (that.userInfo) { // 这个是顶部用户数据的 这样不用监听是否请求成功
that.userInfo = user
that.islogin = user.uid > 0 ? true : false
that.islogin = user.uid > 0 ? true : false;
that.hotSearchkeywords = hotSearchkeywords
that.menu = menu
}
})
.catch(err => {
}).catch(err => {
that.$message.error(err.message)
})
.finally(() => {
}).finally(() => {
// that.$closeUnderLoading(that)
commit("setgetUserInfoState", false)
commit('setgetUserInfoState', false)
})
},
},
modules: {},
modules: {
}
})

View File

@ -1,16 +1,15 @@
/**** request.js ****/
// 导入axios
import axios from 'axios'
import axios from "axios"
// 使用element-ui Message做消息提醒
import { Message } from 'element-ui';
import baseURL from '@/utils/baseApi'
import { Message } from "element-ui"
import baseURL from "@/utils/baseApi"
import { goTologin } from "@/utils/common.js"
//1. 创建新的axios实例
axios.defaults.withCredentials = true
axios.defaults.emulateJSON = true
// 好几个接口
baseURL = {
// forum: "https://forum.gter.net",
@ -21,87 +20,93 @@ baseURL = {
const service = axios.create({
baseURL: baseURL.forum,
timeout: 15000
timeout: 15000,
})
// 2.请求拦截器
service.interceptors.request.use(config => {
service.interceptors.request.use(
config => {
//发请求前做的一些处理数据转化配置请求头设置token,设置loading等根据需求去添加
//注意使用token的时候需要引入cookie方法或者用本地localStorage等方法推荐js-cookie
// config['headers']['authorization'] = "qj2q1qk1on0curclipghjtv5ja1g9eq2"
// config['headers']['authorization'] = "661aiz52k5e6vqgmkxnz0wvbv8nciz8h"
// if (process.env.NODE_ENV == "development") config['headers']['authorization'] = "0h870ovk2xckoqfsh8a3t3sg4sg5z7eg"
if (process.env.NODE_ENV == "development") config['headers']['authorization'] = "95paemsnrr393p9vikpp16qo72"
if (process.env.NODE_ENV == "development") config["headers"]["authorization"] = "95paemsnrr393p9vikpp16qo72"
return config
}, error => {
},
error => {
Promise.reject(error)
})
}
)
// 3.响应拦截器
service.interceptors.response.use(response => {
service.interceptors.response.use(
response => {
//接收到响应数据并成功后的一些共有的处理关闭loading等
let data = response.data
if (data.code == 401) return goTologin()
if (data.code == 201 && response['config']['ispop'] == true) Message.error(data.message)
if (data.code == 201 && response["config"]["ispop"] == true) Message.error(data.message)
return data
}, error => {
},
error => {
/***** 接收到异常响应的处理开始 *****/
if (error && error.response) {
// 1.公共错误处理
// 2.根据响应码具体处理
switch (error.response.status) {
case 400:
error.message = '错误请求'
break;
error.message = "错误请求"
break
case 401:
error.message = '未授权,请重新登录'
break;
error.message = "未授权,请重新登录"
break
case 403:
error.message = '拒绝访问'
break;
error.message = "拒绝访问"
break
case 404:
error.message = '请求错误,未找到该资源'
break;
error.message = "请求错误,未找到该资源"
break
case 405:
error.message = '请求方法未允许'
break;
error.message = "请求方法未允许"
break
case 408:
error.message = '请求超时'
break;
error.message = "请求超时"
break
case 500:
error.message = '服务器端出错'
break;
error.message = "服务器端出错"
break
case 501:
error.message = '网络未实现'
break;
error.message = "网络未实现"
break
case 502:
error.message = '网络错误'
break;
error.message = "网络错误"
break
case 503:
error.message = '服务不可用'
break;
error.message = "服务不可用"
break
case 504:
error.message = '网络超时'
break;
error.message = "网络超时"
break
case 505:
error.message = 'http版本不支持该请求'
break;
error.message = "http版本不支持该请求"
break
default:
error.message = `连接错误${error.response.status}`
}
} else {
// 超时处理
if (JSON.stringify(error).includes('timeout')) error.message = '服务器响应超时,请刷新当前页'
error.message = '连接服务器失败'
if (JSON.stringify(error).includes("timeout")) error.message = "服务器响应超时,请刷新当前页"
error.message = "连接服务器失败"
}
Message.error(error.message)
/***** 处理结束 *****/
//如果不需要错误处理,以上的处理过程都可省略
return Promise.resolve(error.response)
})
}
)
const http = {
/**
@ -112,23 +117,32 @@ const http = {
* @param ispop 报错是否需要弹窗
*/
get(url, params, baseURLName, ispop = true) {
const str = window.location.hostname
let hash = 0
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i)
hash = (hash << 5) - hash + char
hash |= 0
}
const strr = (hash >>> 0).toString(16)
const config = {
method: 'get',
method: "get",
url,
baseURL: baseURL[baseURLName],
}
params = Object.assign({}, params, { key: strr })
if (params) config.params = params
config['ispop'] = ispop
return service(config)
},
post(url, params, baseURLName, ispop = true) {
const config = {
method: 'post',
method: "post",
url: url,
baseURL: baseURL[baseURLName],
}
if (params) config.data = params
config['ispop'] = ispop
config["ispop"] = ispop
return service(config)
},
}