From 40d489f462f711e8591ab77180a17c31a830acbe Mon Sep 17 00:00:00 2001 From: duanledexianxianxian Date: Mon, 1 Jul 2019 20:40:58 +0800 Subject: [PATCH] sync code --- config/plugin.config.ts | 1 + .../SettingDrawer/themeColorClient.ts | 1 + src/config.js | 2 ++ src/models/setting.ts | 7 +++-- src/utils/index.js | 1 + src/utils/kim-request.js | 1 - src/utils/request.js | 29 ++++++++++++++++--- src/utils/utils.ts | 9 +++++- 8 files changed, 42 insertions(+), 9 deletions(-) diff --git a/config/plugin.config.ts b/config/plugin.config.ts index 4ba5a55e..f4e54b6b 100644 --- a/config/plugin.config.ts +++ b/config/plugin.config.ts @@ -26,6 +26,7 @@ function getModulePackageName(module: { context: string }) { export default (config: any) => { // preview.pro.ant.design only do not use in your production; + console.log(process.env.ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, process.env.NODE_ENV); if ( process.env.ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site' || process.env.NODE_ENV !== 'production' diff --git a/src/components/SettingDrawer/themeColorClient.ts b/src/components/SettingDrawer/themeColorClient.ts index d663e3bf..bbc6dd33 100644 --- a/src/components/SettingDrawer/themeColorClient.ts +++ b/src/components/SettingDrawer/themeColorClient.ts @@ -25,6 +25,7 @@ export default { return `/${cssUrl}`; }, }; + console.log(options); return client.changer.changeColor(options, Promise); }, }; diff --git a/src/config.js b/src/config.js index 147283e8..2b0cf60e 100644 --- a/src/config.js +++ b/src/config.js @@ -7,6 +7,8 @@ export default { resMessageKey: 'message', // 后台正常返回错误编码 successCode: 'sys.success', // 后台正常返回错误编码 isThrowError: true, // 默认为true + authCodes: ['system.authc'], + apiType: 0, // 接口模式0-code 模式 1-stauts模式 }, copyright: `${new Date().getFullYear()} KIM3.0技术中台部出品`, homePage: '/dashboard/analysis', diff --git a/src/models/setting.ts b/src/models/setting.ts index c71ad394..1b9b01ea 100644 --- a/src/models/setting.ts +++ b/src/models/setting.ts @@ -20,6 +20,7 @@ export interface SettingModelType { const updateTheme = (newPrimaryColor?: string) => { if (newPrimaryColor) { + console.log(newPrimaryColor); const timeOut = 0; const hideMessage = message.loading('正在切换主题!', timeOut); themeColorClient.changeColor(newPrimaryColor).finally(() => hideMessage()); @@ -121,9 +122,9 @@ const SettingModel: SettingModelType = { primaryColor: appTheme, layout: navigatorStyle === 0 ? 'sidemenu' : 'topmenu', contentWidth: contentWidth === 0 ? 'Fluid' : 'Fixed', - fixedHeader: fixedHead, - autoHideHeader: hideHead, - fixSiderbar: fixedSide, + fixedHeader: fixedHead === 1, + autoHideHeader: hideHead === 1, + fixSiderbar: fixedSide === 1, }; } yield put({ diff --git a/src/utils/index.js b/src/utils/index.js index fb34da11..c475fcdd 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -2,6 +2,7 @@ /* eslint-disable no-bitwise */ import pathToRegexp from 'path-to-regexp'; import { parse } from 'qs'; +import { async } from 'q'; /** * 获取链接的query url部分 diff --git a/src/utils/kim-request.js b/src/utils/kim-request.js index 63f00fe1..e41b5320 100644 --- a/src/utils/kim-request.js +++ b/src/utils/kim-request.js @@ -1,5 +1,4 @@ import axios from 'axios'; -import { string } from 'prop-types'; class HttpRequest { constructor(options) { diff --git a/src/utils/request.js b/src/utils/request.js index 2fce439c..2e771640 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -1,7 +1,9 @@ import { notification } from 'antd'; +import router from 'umi/router'; import HttpRequest from './kim-request'; import config from '@/config'; import store from '@/utils/store'; +import { clearLoginStatus } from '@/utils/utils'; /** * todo 还需处理国际化 @@ -32,7 +34,7 @@ const { resMessageKey, successCode, isThrowError = true, - redirectFunc, + authCodes = ['system.authc'], }, } = config; @@ -84,7 +86,7 @@ const handleResponse = (response, more) => { const handleError = error => { const { response } = error; - // 如果response存在 + // status if (response && response.status) { const errorText = codeMessage[response.status] || response.statusText; const { @@ -92,17 +94,36 @@ const handleError = error => { config: { url }, } = response; notification.error({ - message: `请求错误 ${status}: ${url}`, - description: errorText, + message: `请求错误 ${status}`, + description: `${url}${errorText}`, }); + // if (status >= 404 && status < 422) { + // router.push('/exception/404'); + // } + if (status <= 504 && status >= 500) { + router.push('/exception/500'); + } + // 跳转到登录页面 可能原因:token 失效 + if (status === 403 && status === 401) { + clearLoginStatus(); + router.push('/user/login'); + } } else { + // code const { code, message } = error; notification.error({ key: `notification_${code ? message : code}`, message: '请求错误', description: message, }); + // 跳转到登录页面 可能原因:token 失效 + if (authCodes && authCodes.includes(code)) { + // 清空相关信息 + clearLoginStatus(); + router.push('/user/login'); + } } + if (isThrowError) { throw error; } else { diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 1037a6c3..eae2b594 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,3 +1,5 @@ +import store from '@/utils/store'; + /* eslint no-useless-escape:0 import/prefer-default-export:0 */ const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/; @@ -22,4 +24,9 @@ const isAntDesignProOrDev = (): boolean => { return isAntDesignPro(); }; -export { isAntDesignProOrDev, isAntDesignPro, isUrl }; +const clearLoginStatus = () => { + store.set('token', ''); + store.set('userId', ''); +}; + +export { isAntDesignProOrDev, isAntDesignPro, isUrl, clearLoginStatus }; -- GitLab