no message
This commit is contained in:
parent
1abc53b06d
commit
deffec9e26
2
dist/index.html
vendored
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
@ -1,5 +1,5 @@
|
|||||||
import Vue from "vue"
|
import Vue from 'vue'
|
||||||
import Vuex from "vuex"
|
import Vuex from 'vuex'
|
||||||
|
|
||||||
Vue.use(Vuex)
|
Vue.use(Vuex)
|
||||||
|
|
||||||
@ -16,7 +16,8 @@ export default new Vuex.Store({
|
|||||||
hotSearchkeywords: [], // 热门搜索
|
hotSearchkeywords: [], // 热门搜索
|
||||||
loading: null,
|
loading: null,
|
||||||
},
|
},
|
||||||
getters: {},
|
getters: {
|
||||||
|
},
|
||||||
|
|
||||||
mutations: {
|
mutations: {
|
||||||
setHistoricalSearch(state, payload) {
|
setHistoricalSearch(state, payload) {
|
||||||
@ -25,7 +26,7 @@ export default new Vuex.Store({
|
|||||||
if (targetArr.length > 10) targetArr = targetArr.slice(0, 10)
|
if (targetArr.length > 10) targetArr = targetArr.slice(0, 10)
|
||||||
|
|
||||||
state.historicalSearch = targetArr
|
state.historicalSearch = targetArr
|
||||||
localStorage.setItem("historicalSearch", JSON.stringify(targetArr))
|
localStorage.setItem('historicalSearch', JSON.stringify(targetArr))
|
||||||
},
|
},
|
||||||
|
|
||||||
setAllForumList(state, payload) {
|
setAllForumList(state, payload) {
|
||||||
@ -58,92 +59,64 @@ export default new Vuex.Store({
|
|||||||
|
|
||||||
setMenu(state, payload) {
|
setMenu(state, payload) {
|
||||||
state.menu = payload
|
state.menu = payload
|
||||||
},
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
// 获取历史搜索的数据
|
// 获取历史搜索的数据
|
||||||
fetchHistoricalSearch({ commit }) {
|
fetchHistoricalSearch({ commit }) {
|
||||||
let historicalSearch = JSON.parse(localStorage.getItem("historicalSearch")) || []
|
let historicalSearch = JSON.parse(localStorage.getItem('historicalSearch')) || []
|
||||||
commit("setHistoricalSearch", 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) {
|
getAllForum({ commit }, that) {
|
||||||
const str = window.location.hostname
|
that.$http.get("/api/home/allForum").then(res => {
|
||||||
let hash = 0
|
if (res.code != 200) return;
|
||||||
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
|
|
||||||
let allForumList = res.data
|
let allForumList = res.data
|
||||||
commit("setAllForumList", allForumList)
|
commit('setAllForumList', allForumList)
|
||||||
})
|
}).catch(err => {
|
||||||
.catch(err => {
|
|
||||||
that.$message.error(err.message)
|
that.$message.error(err.message)
|
||||||
})
|
})
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 获取用户信息 获取收藏信息那些数据
|
// 获取用户信息 获取收藏信息那些数据
|
||||||
getUserInfo({ state, commit }, that) {
|
getUserInfo({ state, commit }, that) {
|
||||||
if (state.getUserInfoState) return
|
if (state.getUserInfoState) return
|
||||||
commit("setgetUserInfoState", true)
|
commit('setgetUserInfoState', true)
|
||||||
that.$http
|
that.$http.post("/api/home").then(res => {
|
||||||
.post("/api/home")
|
if (res.code != 200) return;
|
||||||
.then(res => {
|
|
||||||
if (res.code != 200) return
|
|
||||||
let data = res.data
|
let data = res.data
|
||||||
let { config, favorite, hotSearchkeywords, recommend, user, menu } = data
|
let { config, favorite, hotSearchkeywords, recommend, user, menu } = data
|
||||||
|
|
||||||
commit("setHomeRequestState", true)
|
commit('setHomeRequestState', true)
|
||||||
commit("setUser", user)
|
commit('setUser', user)
|
||||||
commit("setFavoriteList", favorite)
|
commit('setFavoriteList', favorite)
|
||||||
commit("setRecommendList", recommend)
|
commit('setRecommendList', recommend)
|
||||||
commit("setHotSearchkeywords", hotSearchkeywords)
|
commit('setHotSearchkeywords', hotSearchkeywords)
|
||||||
commit("setMenu", menu)
|
commit('setMenu', menu)
|
||||||
|
|
||||||
if (that.userInfo) {
|
if (that.userInfo) { // 这个是顶部用户数据的 这样不用监听是否请求成功
|
||||||
// 这个是顶部用户数据的 这样不用监听是否请求成功
|
|
||||||
that.userInfo = user
|
that.userInfo = user
|
||||||
that.islogin = user.uid > 0 ? true : false
|
that.islogin = user.uid > 0 ? true : false;
|
||||||
that.hotSearchkeywords = hotSearchkeywords
|
that.hotSearchkeywords = hotSearchkeywords
|
||||||
that.menu = menu
|
that.menu = menu
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.catch(err => {
|
}).catch(err => {
|
||||||
that.$message.error(err.message)
|
that.$message.error(err.message)
|
||||||
})
|
}).finally(() => {
|
||||||
.finally(() => {
|
|
||||||
// that.$closeUnderLoading(that)
|
// that.$closeUnderLoading(that)
|
||||||
commit("setgetUserInfoState", false)
|
commit('setgetUserInfoState', false)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
modules: {},
|
modules: {
|
||||||
|
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
/**** request.js ****/
|
/**** request.js ****/
|
||||||
// 导入axios
|
// 导入axios
|
||||||
import axios from 'axios'
|
import axios from "axios"
|
||||||
// 使用element-ui Message做消息提醒
|
// 使用element-ui Message做消息提醒
|
||||||
import { Message } from 'element-ui';
|
import { Message } from "element-ui"
|
||||||
import baseURL from '@/utils/baseApi'
|
import baseURL from "@/utils/baseApi"
|
||||||
import { goTologin } from "@/utils/common.js"
|
import { goTologin } from "@/utils/common.js"
|
||||||
|
|
||||||
//1. 创建新的axios实例,
|
//1. 创建新的axios实例,
|
||||||
axios.defaults.withCredentials = true
|
axios.defaults.withCredentials = true
|
||||||
axios.defaults.emulateJSON = true
|
axios.defaults.emulateJSON = true
|
||||||
|
|
||||||
|
|
||||||
// 好几个接口
|
// 好几个接口
|
||||||
baseURL = {
|
baseURL = {
|
||||||
// forum: "https://forum.gter.net",
|
// forum: "https://forum.gter.net",
|
||||||
@ -21,87 +20,93 @@ baseURL = {
|
|||||||
|
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
baseURL: baseURL.forum,
|
baseURL: baseURL.forum,
|
||||||
timeout: 15000
|
timeout: 15000,
|
||||||
})
|
})
|
||||||
|
|
||||||
// 2.请求拦截器
|
// 2.请求拦截器
|
||||||
service.interceptors.request.use(config => {
|
service.interceptors.request.use(
|
||||||
|
config => {
|
||||||
//发请求前做的一些处理,数据转化,配置请求头,设置token,设置loading等,根据需求去添加
|
//发请求前做的一些处理,数据转化,配置请求头,设置token,设置loading等,根据需求去添加
|
||||||
//注意使用token的时候需要引入cookie方法或者用本地localStorage等方法,推荐js-cookie
|
//注意使用token的时候需要引入cookie方法或者用本地localStorage等方法,推荐js-cookie
|
||||||
// config['headers']['authorization'] = "qj2q1qk1on0curclipghjtv5ja1g9eq2"
|
// config['headers']['authorization'] = "qj2q1qk1on0curclipghjtv5ja1g9eq2"
|
||||||
// config['headers']['authorization'] = "661aiz52k5e6vqgmkxnz0wvbv8nciz8h"
|
// config['headers']['authorization'] = "661aiz52k5e6vqgmkxnz0wvbv8nciz8h"
|
||||||
|
|
||||||
// if (process.env.NODE_ENV == "development") config['headers']['authorization'] = "0h870ovk2xckoqfsh8a3t3sg4sg5z7eg"
|
// 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
|
return config
|
||||||
}, error => {
|
},
|
||||||
|
error => {
|
||||||
Promise.reject(error)
|
Promise.reject(error)
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// 3.响应拦截器
|
// 3.响应拦截器
|
||||||
service.interceptors.response.use(response => {
|
service.interceptors.response.use(
|
||||||
|
response => {
|
||||||
//接收到响应数据并成功后的一些共有的处理,关闭loading等
|
//接收到响应数据并成功后的一些共有的处理,关闭loading等
|
||||||
let data = response.data
|
let data = response.data
|
||||||
if (data.code == 401) return goTologin()
|
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
|
return data
|
||||||
}, error => {
|
},
|
||||||
|
error => {
|
||||||
/***** 接收到异常响应的处理开始 *****/
|
/***** 接收到异常响应的处理开始 *****/
|
||||||
if (error && error.response) {
|
if (error && error.response) {
|
||||||
// 1.公共错误处理
|
// 1.公共错误处理
|
||||||
// 2.根据响应码具体处理
|
// 2.根据响应码具体处理
|
||||||
switch (error.response.status) {
|
switch (error.response.status) {
|
||||||
case 400:
|
case 400:
|
||||||
error.message = '错误请求'
|
error.message = "错误请求"
|
||||||
break;
|
break
|
||||||
case 401:
|
case 401:
|
||||||
error.message = '未授权,请重新登录'
|
error.message = "未授权,请重新登录"
|
||||||
break;
|
break
|
||||||
case 403:
|
case 403:
|
||||||
error.message = '拒绝访问'
|
error.message = "拒绝访问"
|
||||||
break;
|
break
|
||||||
case 404:
|
case 404:
|
||||||
error.message = '请求错误,未找到该资源'
|
error.message = "请求错误,未找到该资源"
|
||||||
break;
|
break
|
||||||
case 405:
|
case 405:
|
||||||
error.message = '请求方法未允许'
|
error.message = "请求方法未允许"
|
||||||
break;
|
break
|
||||||
case 408:
|
case 408:
|
||||||
error.message = '请求超时'
|
error.message = "请求超时"
|
||||||
break;
|
break
|
||||||
case 500:
|
case 500:
|
||||||
error.message = '服务器端出错'
|
error.message = "服务器端出错"
|
||||||
break;
|
break
|
||||||
case 501:
|
case 501:
|
||||||
error.message = '网络未实现'
|
error.message = "网络未实现"
|
||||||
break;
|
break
|
||||||
case 502:
|
case 502:
|
||||||
error.message = '网络错误'
|
error.message = "网络错误"
|
||||||
break;
|
break
|
||||||
case 503:
|
case 503:
|
||||||
error.message = '服务不可用'
|
error.message = "服务不可用"
|
||||||
break;
|
break
|
||||||
case 504:
|
case 504:
|
||||||
error.message = '网络超时'
|
error.message = "网络超时"
|
||||||
break;
|
break
|
||||||
case 505:
|
case 505:
|
||||||
error.message = 'http版本不支持该请求'
|
error.message = "http版本不支持该请求"
|
||||||
break;
|
break
|
||||||
default:
|
default:
|
||||||
error.message = `连接错误${error.response.status}`
|
error.message = `连接错误${error.response.status}`
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 超时处理
|
// 超时处理
|
||||||
if (JSON.stringify(error).includes('timeout')) error.message = '服务器响应超时,请刷新当前页'
|
if (JSON.stringify(error).includes("timeout")) error.message = "服务器响应超时,请刷新当前页"
|
||||||
error.message = '连接服务器失败'
|
error.message = "连接服务器失败"
|
||||||
}
|
}
|
||||||
|
|
||||||
Message.error(error.message)
|
Message.error(error.message)
|
||||||
/***** 处理结束 *****/
|
/***** 处理结束 *****/
|
||||||
//如果不需要错误处理,以上的处理过程都可省略
|
//如果不需要错误处理,以上的处理过程都可省略
|
||||||
return Promise.resolve(error.response)
|
return Promise.resolve(error.response)
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const http = {
|
const http = {
|
||||||
/**
|
/**
|
||||||
@ -112,23 +117,32 @@ const http = {
|
|||||||
* @param ispop 报错是否需要弹窗
|
* @param ispop 报错是否需要弹窗
|
||||||
*/
|
*/
|
||||||
get(url, params, baseURLName, ispop = true) {
|
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 = {
|
const config = {
|
||||||
method: 'get',
|
method: "get",
|
||||||
url,
|
url,
|
||||||
baseURL: baseURL[baseURLName],
|
baseURL: baseURL[baseURLName],
|
||||||
}
|
}
|
||||||
|
params = Object.assign({}, params, { key: strr })
|
||||||
if (params) config.params = params
|
if (params) config.params = params
|
||||||
config['ispop'] = ispop
|
|
||||||
return service(config)
|
return service(config)
|
||||||
},
|
},
|
||||||
post(url, params, baseURLName, ispop = true) {
|
post(url, params, baseURLName, ispop = true) {
|
||||||
const config = {
|
const config = {
|
||||||
method: 'post',
|
method: "post",
|
||||||
url: url,
|
url: url,
|
||||||
baseURL: baseURL[baseURLName],
|
baseURL: baseURL[baseURLName],
|
||||||
}
|
}
|
||||||
if (params) config.data = params
|
if (params) config.data = params
|
||||||
config['ispop'] = ispop
|
config["ispop"] = ispop
|
||||||
return service(config)
|
return service(config)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user