mirror of
https://gitee.com/wangkang/udf.git
synced 2026-11-01 07:33:53 +00:00
更新
This commit is contained in:
@@ -3,5 +3,6 @@ const merge = require('webpack-merge')
|
||||
const prodEnv = require('./prod.env')
|
||||
|
||||
module.exports = merge(prodEnv, {
|
||||
NODE_ENV: '"development"'
|
||||
NODE_ENV: '"development"',
|
||||
VUE_APP_TITLE: '"ITKK"'
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
'use strict'
|
||||
module.exports = {
|
||||
NODE_ENV: '"production"'
|
||||
NODE_ENV: '"production"',
|
||||
VUE_APP_TITLE: '"ITKK"'
|
||||
}
|
||||
|
||||
@@ -3,5 +3,6 @@ const merge = require('webpack-merge')
|
||||
const devEnv = require('./dev.env')
|
||||
|
||||
module.exports = merge(devEnv, {
|
||||
NODE_ENV: '"testing"'
|
||||
NODE_ENV: '"testing"',
|
||||
VUE_APP_TITLE: '"ITKK"'
|
||||
})
|
||||
|
||||
+2
-1
@@ -4,7 +4,8 @@
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>ITKK</title>
|
||||
<link rel="icon" href="favicon.ico">
|
||||
<title><%=process.env.VUE_APP_TITLE%></title>
|
||||
<style>
|
||||
.start-loading-center {
|
||||
position: fixed;
|
||||
|
||||
@@ -75,6 +75,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
data() {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import axios from 'axios'
|
||||
import glob from '../assets/js/glob.js';
|
||||
|
||||
const api_user = {
|
||||
// test: () => axios.get(glob.URL_ROOT_WEB + '/actuator/info')
|
||||
};
|
||||
export default api_user;
|
||||
@@ -1,12 +1,25 @@
|
||||
import Vue from 'vue'
|
||||
import NProgress from 'nprogress';
|
||||
import 'nprogress/nprogress.css';
|
||||
import router from "../../router";
|
||||
import axios from 'axios';
|
||||
import {Message} from 'element-ui';
|
||||
|
||||
export default {
|
||||
const glob = {
|
||||
//token名称
|
||||
TOKEN_NAME: 'udf_token',
|
||||
//API根路径
|
||||
URL_ROOT_WEB: '/api/udf/web',
|
||||
//错误消息持续时间
|
||||
ERROR_MESSAGE_DURATION: 3,
|
||||
//默认提示语
|
||||
DEF_ERROR_INFO_MESSAGE: '服务器开小差了 , 请稍后再试',
|
||||
//初始化
|
||||
inti() {
|
||||
//初始化NProgress
|
||||
this.initNProgress();
|
||||
//初始化Axios
|
||||
this.intiAxios();
|
||||
},
|
||||
//初始化NProgress
|
||||
initNProgress() {
|
||||
@@ -24,5 +37,75 @@ export default {
|
||||
router.afterEach(() => {
|
||||
NProgress.done();
|
||||
});
|
||||
}
|
||||
},
|
||||
//初始化Axios
|
||||
intiAxios() {
|
||||
// 添加请求拦截器(从session存储中拿token)
|
||||
axios.interceptors.request.use(config => {
|
||||
//添加token到header中
|
||||
config.headers.token = sessionStorage.getItem(this.TOKEN_NAME) ? sessionStorage.getItem(this.TOKEN_NAME) : '';
|
||||
//返回
|
||||
return config;
|
||||
},
|
||||
error => Promise.reject(error)
|
||||
);
|
||||
// 添加响应拦截器(状态码不为200默认失败)
|
||||
axios.interceptors.response.use(response => {
|
||||
if (response.status == 200) {
|
||||
return Promise.resolve(response);
|
||||
}
|
||||
this.message(error);
|
||||
return Promise.reject(response);
|
||||
},
|
||||
error => {
|
||||
this.message(error);
|
||||
return Promise.reject(error.response);
|
||||
}
|
||||
);
|
||||
},
|
||||
// 错误面板
|
||||
message(error) {
|
||||
// 默认400错误给警告框,其他为错误框
|
||||
const type = error.status === 400 ? 'warning' : 'error';
|
||||
//弹出消息框
|
||||
Message({
|
||||
dangerouslyUseHTMLString: false, // 设置HTML显示
|
||||
showClose: true, // 显示关闭按钮
|
||||
duration: this.ERROR_MESSAGE_DURATION * 1000, // 默认3秒后关闭
|
||||
type,
|
||||
message: this.getErrorMessage(error)
|
||||
});
|
||||
},
|
||||
// 3.获取错误详情
|
||||
getErrorMessage(error) {
|
||||
//默认提示语
|
||||
let msg = this.DEF_ERROR_INFO_MESSAGE;
|
||||
//判断是否有响应消息体
|
||||
if (error.data && rror.data.errorDetail) {
|
||||
//判断错误类型
|
||||
if (error.data.errorDetail.type === 'org.springframework.web.bind.MethodArgumentNotValidException') {
|
||||
//参数校验错误
|
||||
let obj = [];
|
||||
try {
|
||||
const msgData = error.data.errorDetail.message.replace(/"/g, '"');
|
||||
obj = JSON.parse(msgData);
|
||||
} catch (e) {
|
||||
obj = [];
|
||||
}
|
||||
let message = '';
|
||||
if (obj instanceof Array) {
|
||||
obj.forEach(item => {
|
||||
message = message ? `${message},${item.defaultMessage}` : item.defaultMessage;
|
||||
})
|
||||
}
|
||||
msg = message;
|
||||
} else {
|
||||
//其他错误
|
||||
msg = error.data.errorDetail.message;
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
},
|
||||
}
|
||||
Vue.prototype.$glob = glob;
|
||||
export default glob;
|
||||
|
||||
Reference in New Issue
Block a user