diff --git a/package.json b/package.json
index e7e25718c464207a082d2c27af31c2979e24e2d5..3c6f911523d164d9349bb813f05a0fe38fe6826d 100644
--- a/package.json
+++ b/package.json
@@ -25,7 +25,6 @@
"date-fns": "^2.14.0",
"enquire.js": "^2.1.6",
"highlight.js": "^10.2.1",
- "js-cookie": "^2.2.1",
"mockjs": "^1.1.0",
"nprogress": "^0.2.0",
"tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.2.2",
diff --git a/src/components/table/index.vue b/src/components/table/index.vue
index 7f6b4a91ecc281ec4fa179acad89f4c345d1178e..0e9af81a80a51eec915a978b9f7e973207758e9c 100644
--- a/src/components/table/index.vue
+++ b/src/components/table/index.vue
@@ -5,7 +5,7 @@
-
+
重置
查询
@@ -44,7 +44,6 @@
diff --git a/src/router/interceptors.js b/src/router/interceptors.js
index ec6f12f7865795f863834272f31361efe159cc52..0f1856f40eb1c08b9f95626a416720c5d1e5d8d1 100644
--- a/src/router/interceptors.js
+++ b/src/router/interceptors.js
@@ -1,82 +1,81 @@
-import Cookie from 'js-cookie'
// 401拦截
const resp401 = {
- /**
- * 响应数据之前做点什么
- * @param response 响应对象
- * @param options 应用配置 包含: {router, i18n, store, message}
- * @returns {*}
- */
- onFulfilled(response, options) {
- const {message} = options
- if (response.code === 401) {
- message.error('无此权限')
- }
- return response
- },
- /**
- * 响应出错时执行
- * @param error 错误对象
- * @param options 应用配置 包含: {router, i18n, store, message}
- * @returns {Promise}
- */
- onRejected(error, options) {
- const {message} = options
- const {response} = error
- if (response.status === 401) {
- message.error('无此权限')
- }
- return Promise.reject(error)
- }
-}
+ /**
+ * 响应数据之前做点什么
+ * @param response 响应对象
+ * @param options 应用配置 包含: {router, i18n, store, message}
+ * @returns {*}
+ */
+ onFulfilled(response, options) {
+ const { message } = options;
+ if (response.code === 401) {
+ message.error('无此权限');
+ }
+ return response;
+ },
+ /**
+ * 响应出错时执行
+ * @param error 错误对象
+ * @param options 应用配置 包含: {router, i18n, store, message}
+ * @returns {Promise}
+ */
+ onRejected(error, options) {
+ const { message } = options;
+ const { response } = error;
+ if (response.status === 401) {
+ message.error('无此权限');
+ }
+ return Promise.reject(error);
+ },
+};
const resp403 = {
- onFulfilled(response, options) {
- const {message} = options
- if (response.code === 403) {
- message.error('请求被拒绝')
- }
- return response
- },
- onRejected(error, options) {
- const {message} = options
- const {response} = error
- if (response.status === 403) {
- message.error('请求被拒绝')
- }
- return Promise.reject(error)
- }
-}
+ onFulfilled(response, options) {
+ const { message } = options;
+ if (response.code === 403) {
+ message.error('请求被拒绝');
+ }
+ return response;
+ },
+ onRejected(error, options) {
+ const { message } = options;
+ const { response } = error;
+ if (response.status === 403) {
+ message.error('请求被拒绝');
+ }
+ return Promise.reject(error);
+ },
+};
const reqCommon = {
- /**
- * 发送请求之前做些什么
- * @param config axios config
- * @param options 应用配置 包含: {router, i18n, store, message}
- * @returns {*}
- */
- onFulfilled(config, options) {
- const {message} = options
- const {url, xsrfCookieName} = config
- if (url.indexOf('login') === -1 && xsrfCookieName && !Cookie.get(xsrfCookieName)) {
- message.warning('认证 token 已过期,请重新登录')
- }
- return config
- },
- /**
- * 请求出错时做点什么
- * @param error 错误对象
- * @param options 应用配置 包含: {router, i18n, store, message}
- * @returns {Promise}
- */
- onRejected(error, options) {
- const {message} = options
- message.error(error.message)
- return Promise.reject(error)
- }
-}
+ /**
+ * 发送请求之前做些什么
+ * @param config axios config
+ * @param options 应用配置 包含: {router, i18n, store, message}
+ * @returns {*}
+ */
+ onFulfilled(config, options) {
+ const { message } = options;
+ const { url, xsrfCookieName } = config;
+ if (url.indexOf('login') === -1 && xsrfCookieName) {
+ message.warning('认证 token 已过期,请重新登录');
+ }
+ return config;
+ },
+ /**
+ * 请求出错时做点什么
+ * @param error 错误对象
+ * @param options 应用配置 包含: {router, i18n, store, message}
+ * @returns {Promise}
+ */
+ onRejected(error, options) {
+ const { message } = options;
+ message.error(error.message);
+ return Promise.reject(error);
+ },
+};
export default {
- request: [reqCommon], // 请求拦截
- response: [resp401, resp403] // 响应拦截
-}
+ request: [reqCommon], // 请求拦截
+ response: [resp401, resp403], // 响应拦截
+};
diff --git a/src/utils/requestUtil.js b/src/utils/requestUtil.js
index e02f544e3271ba5a2baeb712c1d30c4e94d61189..a210156d15a44b47c8efd1c3037a5ad9ec83d13f 100644
--- a/src/utils/requestUtil.js
+++ b/src/utils/requestUtil.js
@@ -14,9 +14,10 @@ axios.defaults.xsrfCookieName = xsrfHeaderName;
/**
* @param {*} info 提示函数
*/
-function loadResponseInterceptor() {
+function loadResponseInterceptor({ router }) {
axios.interceptors.request.use(
function(config) {
+ console.log(getToken(), config);
// 在发送请求之前做些什么
config.headers = {
...config.headers,
@@ -40,10 +41,15 @@ function loadResponseInterceptor() {
if (data.code === 'sys.success') {
return data.data;
}
+
+ if (data.code === 'error.system.authc') {
+ router.push('/login');
+ }
notification.error({
message: data.code,
description: h => h('pre', data.message),
});
+
return Promise.reject(data.message);
},
function(error) {
@@ -58,14 +64,6 @@ function loadResponseInterceptor() {
);
}
-// 认证类型
-const AUTH_TYPE = {
- BEARER: 'Bearer',
- BASIC: 'basic',
- AUTH1: 'auth1',
- AUTH2: 'auth2',
-};
-
// http method
const METHOD = {
GET: 'get',
@@ -136,13 +134,4 @@ function checkAuthorization() {
return !!getToken();
}
-export {
- METHOD,
- AUTH_TYPE,
- request,
- parseUrlParams,
- loadResponseInterceptor,
- setToken,
- checkAuthorization,
- clearToken,
-};
+export { METHOD, request, parseUrlParams, loadResponseInterceptor, setToken, checkAuthorization, clearToken };
diff --git a/vue.config.js b/vue.config.js
index b89d4944ffa4d3db5f0dd99e98a2efd52a10d99d..663d87db35e4d75ed7637aa5abbd7e6b2fd0d64e 100644
--- a/vue.config.js
+++ b/vue.config.js
@@ -177,7 +177,6 @@ const assetsCDN = {
nprogress: 'NProgress',
clipboard: 'ClipboardJS',
'@antv/data-set': 'DataSet',
- 'js-cookie': 'Cookies',
},
css: [],
js: [
@@ -188,7 +187,6 @@ const assetsCDN = {
'//cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js',
'//cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js',
'//cdn.jsdelivr.net/npm/@antv/data-set@0.11.4/build/data-set.min.js',
- '//cdn.jsdelivr.net/npm/js-cookie@2.2.1/src/js.cookie.min.js',
],
};