Sfoglia il codice sorgente

修改基础js

dev
X 4 anni fa
parent
commit
275a056ab6
8 ha cambiato i file con 97 aggiunte e 8 eliminazioni
  1. +1
    -1
      package.json
  2. +2
    -1
      src/main.js
  3. +4
    -3
      src/router/index.js
  4. +4
    -0
      src/store/getters.js
  5. +1
    -1
      src/store/side-menu.js
  6. +2
    -2
      src/utils/clipboard.js
  7. +15
    -0
      src/utils/cookies.js
  8. +68
    -0
      src/utils/request.js

+ 1
- 1
package.json Vedi File

@@ -33,7 +33,7 @@
"highlight.js": "^10.1.1",
"js-beautify": "^1.11.0",
"litepicker": "^1.5.7",
"lodash": "^4.17.19",
"lodash": "^4.17.20",
"postcss-loader": "3",
"raw-loader": "0.5.1",
"sass-loader": "^9.0.2",


+ 2
- 1
src/main.js Vedi File

@@ -12,7 +12,8 @@ import "./assets/sass/app.scss";
Vue.config.productionTip = false;

new Vue({
el: '#app',
router,
store,
render: h => h(App)
}).$mount("#app");
});

+ 4
- 3
src/router/index.js Vedi File

@@ -280,13 +280,14 @@ const routes = [
component: () => import('@/views/Register')
},
{
path: "/error-page",
path: "/404",
name: "error-page",
component: () => import('@/views/ErrorPage')
},
{
path: "/*",
component: () => import('@/views/ErrorPage')
path: "*",
redirect: '/404',
hidden: true,
}
];



+ 4
- 0
src/store/getters.js Vedi File

@@ -0,0 +1,4 @@
const getters = {

}
export default getters

+ 1
- 1
src/store/side-menu.js Vedi File

@@ -8,7 +8,7 @@ const state = () => {
},
{
icon: "BoxIcon",
pageName: "side-menu-inbox",
pageName: "profile-overview-3",
title: "个人资料"
},
{


+ 2
- 2
src/utils/clipboard.js Vedi File

@@ -3,7 +3,7 @@ import Clipboard from 'clipboard'

function clipboardSuccess() {
Vue.prototype.$message({
message: 'Copy successfully',
message: '拷贝成功',
type: 'success',
duration: 1500
})
@@ -11,7 +11,7 @@ function clipboardSuccess() {

function clipboardError() {
Vue.prototype.$message({
message: 'Copy failed',
message: '拷贝失败',
type: 'error'
})
}


+ 15
- 0
src/utils/cookies.js Vedi File

@@ -0,0 +1,15 @@
import Cookies from 'js-cookie'

const TokenKey = 'Admin-Token'

export function getToken() {
return Cookies.get(TokenKey)
}

export function setToken(token) {
return Cookies.set(TokenKey, token)
}

export function removeToken() {
return Cookies.remove(TokenKey)
}

+ 68
- 0
src/utils/request.js Vedi File

@@ -0,0 +1,68 @@
import axios from '@/utils/request'


const service = axios.create({
baseURL: process.env.VUE_APP_BASE_URL,
timeout: 5000
})


service.interceptors.request.use(
config => {
if (store.getters.token) {
config.headers['X-Token'] = getToken()
}
return config
},
error => {
return Promise.reject(error)
}
)


// response interceptor
service.interceptors.response.use(
response => {
const res = response.data
console.log(res.msg, 'msg')
// if the custom code is not 20000, it is judged as an error.
if (res.code !== 0) {
Message({
message: res.message || 'Error',
type: 'error',
duration: 5 * 1000
})
if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
console.log(res.code, 'res code3')
// to re-login
MessageBox.confirm(
'You have been logged out, you can cancel to stay on this page, or log in again',
'Confirm logout',
{
confirmButtonText: 'Re-Login',
cancelButtonText: 'Cancel',
type: 'warning'
}
).then(() => {
store.dispatch('user/resetToken').then(() => {
location.reload()
})
})
}
return Promise.reject(new Error(res.message || 'Error'))
} else {
return res
}
},
error => {
console.log('err' + error) // for debug
Message({
message: error.message,
type: 'error',
duration: 5 * 1000
})
return Promise.reject(error)
}
)

export default service

Caricamento…
Annulla
Salva