diff --git a/.eslintrc.js b/.eslintrc.js
index f06f75feef4a196fa4d71d8388a892d7aaf54c74..b667176361fda56201a883b39afc16d3d9d05c33 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -5,6 +5,18 @@ module.exports = {
rules: {
...fabric.default.rules,
},
+ settings: {
+ ...fabric.default.settings,
+ // support import modules from TypeScript files in JavaScript files
+ 'import/resolver': {
+ node: { extensions: ['.js', '.ts', '.tsx'] },
+ alias: {
+ map: [['@', './src'], ['utils', './src/utils'], ['config', './config']],
+ extensions: ['.ts', '.js', '.jsx', '.json'],
+ },
+ },
+ },
+
globals: {
ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: true,
page: true,
diff --git a/config/config.ts b/config/config.ts
index 0dca86014d40fd9e39be03120ea2ee5a69e271d4..67484a4a11c101746a042e95996baf02936abd19 100644
--- a/config/config.ts
+++ b/config/config.ts
@@ -2,6 +2,7 @@ import { IConfig, IPlugin } from 'umi-types';
import defaultSettings from './defaultSettings'; // https://umijs.org/config/
import slash from 'slash2';
import webpackPlugin from './plugin.config';
+import theme from './theme.config';
const path = require('path');
const { pwa } = defaultSettings; // preview.pro.ant.design only do not use in your production ;
@@ -325,17 +326,6 @@ export default {
// Theme for antd
// https://ant.design/docs/react/customize-theme-cn
theme,
- // proxy: {
- // '/server/api/': {
- // target: 'https://preview.pro.ant.design/',
- // changeOrigin: true,
- // pathRewrite: { '^/server': '' },
- // },
- // },
- // Theme for antd: https://ant.design/docs/react/customize-theme-cn
- theme: {
- 'primary-color': primaryColor,
- },
define: {
ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
@@ -379,7 +369,6 @@ export default {
manifest: {
basePath: '/',
},
- uglifyJSOptions,
chainWebpack: webpackPlugin,
// 配置 webpack 的 resolve.alias 属性 默认src=>@
alias: {
diff --git a/package.json b/package.json
index 12f7bc146efde853cac88a1817d8fa60ae0c4752..bc89256e96852fa616e51515d061fb6c74dfec40 100644
--- a/package.json
+++ b/package.json
@@ -34,7 +34,6 @@
},
"husky": {
"hooks": {
- "pre-commit": "npm run lint-staged"
}
},
"lint-staged": {
@@ -90,7 +89,9 @@
"umi-plugin-ga": "^1.1.3",
"umi-plugin-pro-block": "^1.3.2",
"umi-plugin-react": "^1.8.2",
- "umi-request": "^1.0.7"
+ "axios":"^0.19.0",
+ "query-string":"^6.8.1",
+ "store":"^2.0.12"
},
"devDependencies": {
"@ant-design/colors": "^3.1.0",
@@ -105,7 +106,6 @@
"@types/react": "^16.8.19",
"@types/react-document-title": "^2.0.3",
"@types/react-dom": "^16.8.4",
- "@types/numeral":"^0.0.25",
"babel-eslint": "^10.0.1",
"chalk": "^2.4.2",
"check-prettier": "^1.0.3",
@@ -131,7 +131,7 @@
"stylelint": "^10.1.0",
"webpack-theme-color-replacer": "^1.1.5",
"mockjs": "^1.0.1-beta3",
- "@types/mockjs":"^1.0.2"
+ "eslint-import-resolver-alias": "^1.1.2"
},
"optionalDependencies": {
"puppeteer": "^1.17.0"
diff --git a/src/components/Ellipsis/index.js b/src/components/Ellipsis/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..de700b74b192b5c634ee88a0fc5533f59a504ab5
--- /dev/null
+++ b/src/components/Ellipsis/index.js
@@ -0,0 +1,270 @@
+import React, { Component } from 'react';
+import { Tooltip } from 'antd';
+import classNames from 'classnames';
+import styles from './index.less';
+
+/* eslint react/no-did-mount-set-state: 0 */
+/* eslint no-param-reassign: 0 */
+
+const isSupportLineClamp = document.body.style.webkitLineClamp !== undefined;
+
+const TooltipOverlayStyle = {
+ overflowWrap: 'break-word',
+ wordWrap: 'break-word',
+};
+
+export const getStrFullLength = (str = '') =>
+ str.split('').reduce((pre, cur) => {
+ const charCode = cur.charCodeAt(0);
+ if (charCode >= 0 && charCode <= 128) {
+ return pre + 1;
+ }
+ return pre + 2;
+ }, 0);
+
+export const cutStrByFullLength = (str = '', maxLength) => {
+ let showLength = 0;
+ return str.split('').reduce((pre, cur) => {
+ const charCode = cur.charCodeAt(0);
+ if (charCode >= 0 && charCode <= 128) {
+ showLength += 1;
+ } else {
+ showLength += 2;
+ }
+ if (showLength <= maxLength) {
+ return pre + cur;
+ }
+ return pre;
+ }, '');
+};
+
+const getTooltip = ({ tooltip, overlayStyle, title, children }) => {
+ if (tooltip) {
+ const props = tooltip === true ? { overlayStyle, title } : { ...tooltip, overlayStyle, title };
+ return {children};
+ }
+ return children;
+};
+
+const EllipsisText = ({ text, length, tooltip, fullWidthRecognition, ...other }) => {
+ if (typeof text !== 'string') {
+ throw new Error('Ellipsis children must be string.');
+ }
+ const textLength = fullWidthRecognition ? getStrFullLength(text) : text.length;
+ if (textLength <= length || length < 0) {
+ return {text};
+ }
+ const tail = '...';
+ let displayText;
+ if (length - tail.length <= 0) {
+ displayText = '';
+ } else {
+ displayText = fullWidthRecognition ? cutStrByFullLength(text, length) : text.slice(0, length);
+ }
+
+ const spanAttrs = tooltip ? {} : { ...other };
+ return getTooltip({
+ tooltip,
+ overlayStyle: TooltipOverlayStyle,
+ title: text,
+ children: (
+
+ {displayText}
+ {tail}
+
+ ),
+ });
+};
+
+export default class Ellipsis extends Component {
+ state = {
+ text: '',
+ targetCount: 0,
+ };
+
+ componentDidMount() {
+ if (this.node) {
+ this.computeLine();
+ }
+ }
+
+ componentDidUpdate(perProps) {
+ const { lines } = this.props;
+ if (lines !== perProps.lines) {
+ this.computeLine();
+ }
+ }
+
+ computeLine = () => {
+ const { lines } = this.props;
+ if (lines && !isSupportLineClamp) {
+ const text = this.shadowChildren.innerText || this.shadowChildren.textContent;
+ const lineHeight = parseInt(getComputedStyle(this.root).lineHeight, 10);
+ const targetHeight = lines * lineHeight;
+ this.content.style.height = `${targetHeight}px`;
+ const totalHeight = this.shadowChildren.offsetHeight;
+ const shadowNode = this.shadow.firstChild;
+
+ if (totalHeight <= targetHeight) {
+ this.setState({
+ text,
+ targetCount: text.length,
+ });
+ return;
+ }
+
+ // bisection
+ const len = text.length;
+ const mid = Math.ceil(len / 2);
+
+ const count = this.bisection(targetHeight, mid, 0, len, text, shadowNode);
+
+ this.setState({
+ text,
+ targetCount: count,
+ });
+ }
+ };
+
+ bisection = (th, m, b, e, text, shadowNode) => {
+ const suffix = '...';
+ let mid = m;
+ let end = e;
+ let begin = b;
+ shadowNode.innerHTML = text.substring(0, mid) + suffix;
+ let sh = shadowNode.offsetHeight;
+
+ if (sh <= th) {
+ shadowNode.innerHTML = text.substring(0, mid + 1) + suffix;
+ sh = shadowNode.offsetHeight;
+ if (sh > th || mid === begin) {
+ return mid;
+ }
+ begin = mid;
+ if (end - begin === 1) {
+ mid = 1 + begin;
+ } else {
+ mid = Math.floor((end - begin) / 2) + begin;
+ }
+ return this.bisection(th, mid, begin, end, text, shadowNode);
+ }
+ if (mid - 1 < 0) {
+ return mid;
+ }
+ shadowNode.innerHTML = text.substring(0, mid - 1) + suffix;
+ sh = shadowNode.offsetHeight;
+ if (sh <= th) {
+ return mid - 1;
+ }
+ end = mid;
+ mid = Math.floor((end - begin) / 2) + begin;
+ return this.bisection(th, mid, begin, end, text, shadowNode);
+ };
+
+ handleRoot = n => {
+ this.root = n;
+ };
+
+ handleContent = n => {
+ this.content = n;
+ };
+
+ handleNode = n => {
+ this.node = n;
+ };
+
+ handleShadow = n => {
+ this.shadow = n;
+ };
+
+ handleShadowChildren = n => {
+ this.shadowChildren = n;
+ };
+
+ render() {
+ const { text, targetCount } = this.state;
+ const {
+ children,
+ lines,
+ length,
+ className,
+ tooltip,
+ fullWidthRecognition,
+ ...restProps
+ } = this.props;
+
+ const cls = classNames(styles.ellipsis, className, {
+ [styles.lines]: lines && !isSupportLineClamp,
+ [styles.lineClamp]: lines && isSupportLineClamp,
+ });
+
+ if (!lines && !length) {
+ return (
+
+ {children}
+
+ );
+ }
+
+ // length
+ if (!lines) {
+ return (
+
+ );
+ }
+
+ const id = `antd-pro-ellipsis-${`${new Date().getTime()}${Math.floor(Math.random() * 100)}`}`;
+
+ // support document.body.style.webkitLineClamp
+ if (isSupportLineClamp) {
+ const style = `#${id}{-webkit-line-clamp:${lines};-webkit-box-orient: vertical;}`;
+
+ const node = (
+
+
+ {children}
+
+ );
+
+ return getTooltip({
+ tooltip,
+ overlayStyle: TooltipOverlayStyle,
+ title: children,
+ children: node,
+ });
+ }
+
+ const childNode = (
+
+ {targetCount > 0 && text.substring(0, targetCount)}
+ {targetCount > 0 && targetCount < text.length && '...'}
+
+ );
+
+ return (
+
+
+ {getTooltip({
+ tooltip,
+ overlayStyle: TooltipOverlayStyle,
+ title: text,
+ children: childNode,
+ })}
+
+ {children}
+
+
+ {text}
+
+
+
+ );
+ }
+}
diff --git a/src/components/Ellipsis/index.less b/src/components/Ellipsis/index.less
new file mode 100644
index 0000000000000000000000000000000000000000..3c0360c10467fe876a73ea331d72a33a380c7f56
--- /dev/null
+++ b/src/components/Ellipsis/index.less
@@ -0,0 +1,24 @@
+.ellipsis {
+ display: inline-block;
+ width: 100%;
+ overflow: hidden;
+ word-break: break-all;
+}
+
+.lines {
+ position: relative;
+ .shadow {
+ position: absolute;
+ z-index: -999;
+ display: block;
+ color: transparent;
+ opacity: 0;
+ }
+}
+
+.lineClamp {
+ position: relative;
+ display: -webkit-box;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
diff --git a/src/config.js b/src/config.js
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a9d295c77e0140e087f9b68ed4a9df97ccde848a 100644
--- a/src/config.js
+++ b/src/config.js
@@ -0,0 +1,10 @@
+// import store from './utils/store';
+
+export default {
+ baseUrl: 'http://platform.kuopu.net/9080',
+ storeNameSpace: 'kim',
+ headers: () => ({
+ Authorization:
+ 'eyJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjMzLCJ1c24iOiLmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrociLCJzdGEiOjE1NjEzMzQ2MDkwMTEsImxpZCI6Im91eWFuZ2JveXUifQ.eriHWClI-ST9CuEJuoU608KTKxIhf4XUxOSslzwT6K8',
+ }),
+};
diff --git a/src/pages/account/center/service.ts b/src/pages/account/center/service.ts
index db8254d58677ca4cf5db3be9efeb75680cdf6c2f..1fff92ae310c436af9f2f872bfbb3056d3caf970 100644
--- a/src/pages/account/center/service.ts
+++ b/src/pages/account/center/service.ts
@@ -1,11 +1,11 @@
-import request from 'umi-request';
+import { get } from '@/utils/request';
export async function queryCurrent() {
- return request('/api/currentUser');
+ return get('/api/currentUser');
}
export async function queryFakeList(params: { count: number }) {
- return request('/api/fake_list', {
+ return get('/api/fake_list', {
params,
});
}
diff --git a/src/pages/account/settings/service.ts b/src/pages/account/settings/service.ts
index 4da62fb1835236cfdf335f3a1a0a3d38994e81a1..67410c024de5b0514bc6d4c94c5d4bf100c35a8a 100644
--- a/src/pages/account/settings/service.ts
+++ b/src/pages/account/settings/service.ts
@@ -1,17 +1,17 @@
-import request from 'umi-request';
+import { get } from '@/utils/request';
export async function queryCurrent() {
- return request('/api/currentUser');
+ return get('/api/currentUser');
}
export async function queryProvince() {
- return request('/api/geographic/province');
+ return get('/api/geographic/province');
}
export async function queryCity(province: string) {
- return request(`/api/geographic/city/${province}`);
+ return get(`/api/geographic/city/${province}`);
}
export async function query() {
- return request('/api/users');
+ return get('/api/users');
}
diff --git a/src/pages/dashboard/analysis/service.tsx b/src/pages/dashboard/analysis/service.tsx
index 26cd82f03661b7ad66b2da6174e665c34ac72436..36bb6b7b4b2bb96f949b7265bc37c13d26cb2027 100644
--- a/src/pages/dashboard/analysis/service.tsx
+++ b/src/pages/dashboard/analysis/service.tsx
@@ -1,5 +1,5 @@
-import request from 'umi-request';
+import { get } from '@/utils/request';
export async function fakeChartData() {
- return request('/api/fake_chart_data');
+ return get('/api/fake_chart_data');
}
diff --git a/src/pages/dashboard/monitor/service.ts b/src/pages/dashboard/monitor/service.ts
index a0d7b872ab595f2ac1c9e71ed981c86dbee93e13..f79496d5809b75d279d5172b26653fc3280ce503 100644
--- a/src/pages/dashboard/monitor/service.ts
+++ b/src/pages/dashboard/monitor/service.ts
@@ -1,5 +1,5 @@
-import request from 'umi-request';
+import { get } from '@/utils/request';
export async function queryTags() {
- return request('/api/tags');
+ return get('/api/tags');
}
diff --git a/src/pages/dashboard/workplace/service.ts b/src/pages/dashboard/workplace/service.ts
index fcd96ebefc7522b86256920f9f975e8e2115d5b4..71323d108d83f4a241d616d2a040b751e272970d 100644
--- a/src/pages/dashboard/workplace/service.ts
+++ b/src/pages/dashboard/workplace/service.ts
@@ -1,17 +1,17 @@
-import request from 'umi-request';
+import { get } from '@/utils/request';
export async function queryProjectNotice() {
- return request('/api/project/notice');
+ return get('/api/project/notice');
}
export async function queryActivities() {
- return request('/api/activities');
+ return get('/api/activities');
}
export async function fakeChartData() {
- return request('/api/fake_chart_data');
+ return get('/api/fake_chart_data');
}
export async function queryCurrent() {
- return request('/api/currentUser');
+ return get('/api/currentUser');
}
diff --git a/src/pages/form/advanced-form/service.ts b/src/pages/form/advanced-form/service.ts
index 36024f2bb6b24b5ca7757eda0c6c6d15c98d0d90..6ef0bd9f2b7afd2d5a7f90d01f988c9d8ad99af7 100644
--- a/src/pages/form/advanced-form/service.ts
+++ b/src/pages/form/advanced-form/service.ts
@@ -1,7 +1,7 @@
-import request from 'umi-request';
+import { get } from '@/utils/request';
export async function fakeSubmitForm(params: any) {
- return request('/api/forms', {
+ return get('/api/forms', {
method: 'POST',
data: params,
});
diff --git a/src/pages/form/basic-form/service.ts b/src/pages/form/basic-form/service.ts
index 36024f2bb6b24b5ca7757eda0c6c6d15c98d0d90..6ef0bd9f2b7afd2d5a7f90d01f988c9d8ad99af7 100644
--- a/src/pages/form/basic-form/service.ts
+++ b/src/pages/form/basic-form/service.ts
@@ -1,7 +1,7 @@
-import request from 'umi-request';
+import { get } from '@/utils/request';
export async function fakeSubmitForm(params: any) {
- return request('/api/forms', {
+ return get('/api/forms', {
method: 'POST',
data: params,
});
diff --git a/src/pages/form/step-form/service.ts b/src/pages/form/step-form/service.ts
index 36024f2bb6b24b5ca7757eda0c6c6d15c98d0d90..6ef0bd9f2b7afd2d5a7f90d01f988c9d8ad99af7 100644
--- a/src/pages/form/step-form/service.ts
+++ b/src/pages/form/step-form/service.ts
@@ -1,7 +1,7 @@
-import request from 'umi-request';
+import { get } from '@/utils/request';
export async function fakeSubmitForm(params: any) {
- return request('/api/forms', {
+ return get('/api/forms', {
method: 'POST',
data: params,
});
diff --git a/src/pages/list/basic-list/service.ts b/src/pages/list/basic-list/service.ts
index 38001c9cd2f54986bc3bf4bd735258023504ce9f..0711b63ef5805fc1c752afe58deccd3329fa85a5 100644
--- a/src/pages/list/basic-list/service.ts
+++ b/src/pages/list/basic-list/service.ts
@@ -1,4 +1,4 @@
-import request from 'umi-request';
+import { get } from '@/utils/request';
import { BasicListItemDataType } from './data.d';
interface ParamsType extends Partial {
@@ -6,14 +6,14 @@ interface ParamsType extends Partial {
}
export async function queryFakeList(params: ParamsType) {
- return request('/api/fake_list', {
+ return get('/api/fake_list', {
params,
});
}
export async function removeFakeList(params: ParamsType) {
const { count = 5, ...restParams } = params;
- return request('/api/fake_list', {
+ return get('/api/fake_list', {
method: 'POST',
params: {
count,
@@ -27,7 +27,7 @@ export async function removeFakeList(params: ParamsType) {
export async function addFakeList(params: ParamsType) {
const { count = 5, ...restParams } = params;
- return request('/api/fake_list', {
+ return get('/api/fake_list', {
method: 'POST',
params: {
count,
@@ -41,7 +41,7 @@ export async function addFakeList(params: ParamsType) {
export async function updateFakeList(params: ParamsType) {
const { count = 5, ...restParams } = params;
- return request('/api/fake_list', {
+ return get('/api/fake_list', {
method: 'POST',
params: {
count,
diff --git a/src/pages/list/card-list/service.ts b/src/pages/list/card-list/service.ts
index fcd22bc04b4b79761ac54e00a4de98752b38869d..5f4f1353cc9432f11c5fe40f0851935d8e49839a 100644
--- a/src/pages/list/card-list/service.ts
+++ b/src/pages/list/card-list/service.ts
@@ -1,7 +1,7 @@
-import request from 'umi-request';
+import { get } from '@/utils/request';
export async function queryFakeList(params: { count: number }) {
- return request('/api/fake_list', {
+ return get('/api/fake_list', {
params,
});
}
diff --git a/src/pages/list/search/applications/service.ts b/src/pages/list/search/applications/service.ts
index 1fbbdf958276c0b1ad231785f735739f445ea752..ed6e59de1243d09f24dd68dae8fccdf52fb54e3d 100644
--- a/src/pages/list/search/applications/service.ts
+++ b/src/pages/list/search/applications/service.ts
@@ -1,8 +1,8 @@
-import request from 'umi-request';
+import { get } from 'utils/request';
import { ListItemDataType } from './data.d';
export async function queryFakeList(params: ListItemDataType) {
- return request('/api/fake_list', {
+ return get('/api/fake_list', {
params,
});
}
diff --git a/src/pages/list/search/articles/service.ts b/src/pages/list/search/articles/service.ts
index 1fbbdf958276c0b1ad231785f735739f445ea752..14284b33a0b83d9055289f32536706d50c92da03 100644
--- a/src/pages/list/search/articles/service.ts
+++ b/src/pages/list/search/articles/service.ts
@@ -1,8 +1,8 @@
-import request from 'umi-request';
+import { get } from '@/utils/request';
import { ListItemDataType } from './data.d';
export async function queryFakeList(params: ListItemDataType) {
- return request('/api/fake_list', {
+ return get('/api/fake_list', {
params,
});
}
diff --git a/src/pages/list/search/projects/service.ts b/src/pages/list/search/projects/service.ts
index fcd22bc04b4b79761ac54e00a4de98752b38869d..5f4f1353cc9432f11c5fe40f0851935d8e49839a 100644
--- a/src/pages/list/search/projects/service.ts
+++ b/src/pages/list/search/projects/service.ts
@@ -1,7 +1,7 @@
-import request from 'umi-request';
+import { get } from '@/utils/request';
export async function queryFakeList(params: { count: number }) {
- return request('/api/fake_list', {
+ return get('/api/fake_list', {
params,
});
}
diff --git a/src/pages/list/table-list/service.ts b/src/pages/list/table-list/service.ts
index 24d6348e298dacdb8865b6718a5a111c3583ef6a..6fa973c174439629cc5cf88d773d37046cc9e5d8 100644
--- a/src/pages/list/table-list/service.ts
+++ b/src/pages/list/table-list/service.ts
@@ -1,14 +1,14 @@
-import request from 'umi-request';
+import { get } from '@/utils/request';
import { TableListParams } from './data.d';
export async function queryRule(params: TableListParams) {
- return request('/api/rule', {
+ return get('/api/rule', {
params,
});
}
export async function removeRule(params: TableListParams) {
- return request('/api/rule', {
+ return get('/api/rule', {
method: 'POST',
data: {
...params,
@@ -18,7 +18,7 @@ export async function removeRule(params: TableListParams) {
}
export async function addRule(params: TableListParams) {
- return request('/api/rule', {
+ return get('/api/rule', {
method: 'POST',
data: {
...params,
@@ -28,7 +28,7 @@ export async function addRule(params: TableListParams) {
}
export async function updateRule(params: TableListParams) {
- return request('/api/rule', {
+ return get('/api/rule', {
method: 'POST',
data: {
...params,
diff --git a/src/pages/profile/advanced/service.ts b/src/pages/profile/advanced/service.ts
index 2f773f7f8234e74306012806b3945168e8b0d971..718383656b370226b35a3874b771cf6178fd7770 100644
--- a/src/pages/profile/advanced/service.ts
+++ b/src/pages/profile/advanced/service.ts
@@ -1,5 +1,5 @@
-import request from 'umi-request';
+import { get } from '@/utils/request';
export async function queryAdvancedProfile() {
- return request('/api/profile/advanced');
+ return get('/api/profile/advanced');
}
diff --git a/src/pages/profile/basic/service.ts b/src/pages/profile/basic/service.ts
index bc2a9fd4759e348679b038728ab8907ad48ef815..b4a90a0b4c0ce2b1404787db3f19bd01f3d3ded9 100644
--- a/src/pages/profile/basic/service.ts
+++ b/src/pages/profile/basic/service.ts
@@ -1,5 +1,5 @@
-import request from 'umi-request';
+import { get } from '@/utils/request';
export async function queryBasicProfile() {
- return request('/api/profile/basic');
+ return get('/api/profile/basic');
}
diff --git a/src/pages/system/parameter/components/business/action/index.less b/src/pages/system/parameter/components/business/action/index.less
index 3ddc2bc8c23581f26f4c399ac61c2e9c7ecdee88..0cf4576a7fc51dd8a41a110a2621e9f6ebea0a2e 100644
--- a/src/pages/system/parameter/components/business/action/index.less
+++ b/src/pages/system/parameter/components/business/action/index.less
@@ -1,9 +1,9 @@
@import "~@/themes/vars.less";
.root {
- margin-left: -@space-lg;
margin-right: -@space-lg;
margin-bottom: @space-lg;
+ margin-left: -@space-lg;
// padding: 0 @space-lg;
.left {
padding: 0 @space-lg;
@@ -17,8 +17,8 @@
}
}
.right {
- padding: 0 @space-lg;
display: flex;
justify-content: flex-end;
+ padding: 0 @space-lg;
}
}
diff --git a/src/pages/system/parameter/components/business/index.less b/src/pages/system/parameter/components/business/index.less
index c2026e3204dcac95b6786d4826fdb4755166ef77..45cd02d1da0fcea7a3f54c8778b7d306a1692baf 100644
--- a/src/pages/system/parameter/components/business/index.less
+++ b/src/pages/system/parameter/components/business/index.less
@@ -1,4 +1 @@
-@import "~@/themes/vars.less";
-
-.root {
-}
+@import '~@/themes/vars.less';
diff --git a/src/pages/system/parameter/components/business/search/index.less b/src/pages/system/parameter/components/business/search/index.less
index ea04e8037e6214c3fbfc8e3619f42dc75a45add3..fe0c26fda52c4a6517ce8d696c819f222c690c64 100644
--- a/src/pages/system/parameter/components/business/search/index.less
+++ b/src/pages/system/parameter/components/business/search/index.less
@@ -1,13 +1,13 @@
@import "~@/themes/vars.less";
.root {
- margin-left: -@space-lg;
margin-right: -@space-lg;
+ margin-left: -@space-lg;
:global {
.ant-form-item {
display: flex;
- padding: 0 @space-lg;
margin: 0 0 @space-lg / 3 0;
+ padding: 0 @space-lg;
.ant-form-item-label {
width: auto;
min-width: 80px;
diff --git a/src/pages/system/parameter/components/operation/action/index.less b/src/pages/system/parameter/components/operation/action/index.less
index 3ddc2bc8c23581f26f4c399ac61c2e9c7ecdee88..0cf4576a7fc51dd8a41a110a2621e9f6ebea0a2e 100644
--- a/src/pages/system/parameter/components/operation/action/index.less
+++ b/src/pages/system/parameter/components/operation/action/index.less
@@ -1,9 +1,9 @@
@import "~@/themes/vars.less";
.root {
- margin-left: -@space-lg;
margin-right: -@space-lg;
margin-bottom: @space-lg;
+ margin-left: -@space-lg;
// padding: 0 @space-lg;
.left {
padding: 0 @space-lg;
@@ -17,8 +17,8 @@
}
}
.right {
- padding: 0 @space-lg;
display: flex;
justify-content: flex-end;
+ padding: 0 @space-lg;
}
}
diff --git a/src/pages/system/parameter/components/operation/index.less b/src/pages/system/parameter/components/operation/index.less
index c2026e3204dcac95b6786d4826fdb4755166ef77..45cd02d1da0fcea7a3f54c8778b7d306a1692baf 100644
--- a/src/pages/system/parameter/components/operation/index.less
+++ b/src/pages/system/parameter/components/operation/index.less
@@ -1,4 +1 @@
-@import "~@/themes/vars.less";
-
-.root {
-}
+@import '~@/themes/vars.less';
diff --git a/src/pages/system/parameter/components/operation/search/index.less b/src/pages/system/parameter/components/operation/search/index.less
index ea04e8037e6214c3fbfc8e3619f42dc75a45add3..fe0c26fda52c4a6517ce8d696c819f222c690c64 100644
--- a/src/pages/system/parameter/components/operation/search/index.less
+++ b/src/pages/system/parameter/components/operation/search/index.less
@@ -1,13 +1,13 @@
@import "~@/themes/vars.less";
.root {
- margin-left: -@space-lg;
margin-right: -@space-lg;
+ margin-left: -@space-lg;
:global {
.ant-form-item {
display: flex;
- padding: 0 @space-lg;
margin: 0 0 @space-lg / 3 0;
+ padding: 0 @space-lg;
.ant-form-item-label {
width: auto;
min-width: 80px;
diff --git a/src/pages/system/parameter/components/table/EditableCell.js b/src/pages/system/parameter/components/table/EditableCell.js
index 7cd0c6f7b05e9c2d893ee0555a723939f66dc220..ec9b8dfac5f45f2bab39ebbea7e653e0bd68d683 100644
--- a/src/pages/system/parameter/components/table/EditableCell.js
+++ b/src/pages/system/parameter/components/table/EditableCell.js
@@ -5,6 +5,7 @@ const FormItem = Form.Item;
export const EditableContext = React.createContext();
+// eslint-disable-next-line react/prefer-stateless-function
export class EditableCell extends React.Component {
render() {
const {
diff --git a/src/pages/system/parameter/components/table/index.less b/src/pages/system/parameter/components/table/index.less
index e5e02c5652e1710971a6046cd4e9c83c6bbeb88a..f7f3ba66ce3b0f6aa762a43d9f7e7ded3a8cf3b2 100644
--- a/src/pages/system/parameter/components/table/index.less
+++ b/src/pages/system/parameter/components/table/index.less
@@ -6,8 +6,8 @@
}
.editable-row .ant-form-explain {
position: absolute;
- font-size: 12px;
margin-top: -4px;
+ font-size: 12px;
}
.fixedWidthTable {
table {
diff --git a/src/pages/system/parameter/index.less b/src/pages/system/parameter/index.less
index 99d5f0d581b136227268f395314ef621a0ca3ee2..a870b3b87206b269d5f381f9a076871e0bf01014 100644
--- a/src/pages/system/parameter/index.less
+++ b/src/pages/system/parameter/index.less
@@ -1,8 +1,8 @@
@import "~@/themes/vars.less";
.root {
- background-color: #fff;
+ min-height: calc(100vh - 100px);
padding: 16px 24px;
+ background-color: #fff;
border-radius: 4px;
- min-height: calc(100vh - 100px);
}
diff --git a/src/pages/system/parameter/models/business.js b/src/pages/system/parameter/models/business.js
index 5e6b885ba9d7d95075a9139a2d5e572c23bc7437..e0a015a0432b419df6578b188cc7b09d94524b2a 100644
--- a/src/pages/system/parameter/models/business.js
+++ b/src/pages/system/parameter/models/business.js
@@ -19,6 +19,7 @@ export default {
},
) {
list.forEach(element => {
+ // eslint-disable-next-line no-param-reassign
element.key = element.paramId;
});
return {
diff --git a/src/pages/system/parameter/models/operation.js b/src/pages/system/parameter/models/operation.js
index fb49a7f41e5839d217e21fb0fda6d2a17cf6c326..580bc46ec45fa393fd3ca3c43d2da425f1df5529 100644
--- a/src/pages/system/parameter/models/operation.js
+++ b/src/pages/system/parameter/models/operation.js
@@ -19,6 +19,7 @@ export default {
},
) {
list.forEach(item => {
+ // eslint-disable-next-line no-param-reassign
item.key = item.paramId;
});
return {
diff --git a/src/pages/user/login/service.ts b/src/pages/user/login/service.ts
index fa7c230a55a22de2563c5f71dfe73cb3a9d74aeb..1f89d6620b42b2a1d41ee82f1d95362727e97f20 100644
--- a/src/pages/user/login/service.ts
+++ b/src/pages/user/login/service.ts
@@ -1,13 +1,13 @@
-import request from 'umi-request';
+import { get } from '@/utils/request';
import { FromDataType } from './index';
export async function fakeAccountLogin(params: FromDataType) {
- return request('/api/login/account', {
+ return get('/api/login/account', {
method: 'POST',
data: params,
});
}
export async function getFakeCaptcha(mobile: string) {
- return request(`/api/login/captcha?mobile=${mobile}`);
+ return get(`/api/login/captcha?mobile=${mobile}`);
}
diff --git a/src/pages/user/register/service.ts b/src/pages/user/register/service.ts
index 2f8d0117dfc394d0e5d4da9beaf920c5fe1d6a0e..99d42f78e47d640e892b3ccd3c606cd0ddc13ffc 100644
--- a/src/pages/user/register/service.ts
+++ b/src/pages/user/register/service.ts
@@ -1,8 +1,8 @@
-import request from 'umi-request';
+import { get } from '@/utils/request';
import { UserRegisterParams } from './index';
export async function fakeRegister(params: UserRegisterParams) {
- return request('/api/register', {
+ return get('/api/register', {
method: 'POST',
data: params,
});
diff --git a/src/themes/vars.less b/src/themes/vars.less
new file mode 100644
index 0000000000000000000000000000000000000000..416c1a1a4e5e987f227ca3818172b2d9de86129e
--- /dev/null
+++ b/src/themes/vars.less
@@ -0,0 +1,51 @@
+/**
+ * author: liu.yang
+ * date: 2018-08-22 09:09:23
+ * 一下内容请不要随意覆盖
+ */
+
+// 字色
+//3a73e9
+//43CEC4
+@color-primary: #43cec4; // 主色
+@color-primary-active: #43cec4; // 主色
+@color-primary-disable: #bec5d4; // 主色
+@color-primary-sup: #374583; // 图标色
+@color-border: #e3e7ef; // 边框
+@color-background: #f4f5f7; // 背景颜色
+@color-success: #3cd99d; // 辅助色-成功
+@color-error: #ff5c6a; // 辅助色-异常
+@color-warning: #ffbc19; // 辅助色-警告
+
+@text-title-color: #202f75; // 标题颜色
+@text-content-color: #374583; // 正文颜色
+@text-prompt-color: #b3b9c4; // 提示颜色
+
+@table-background-color: #f4f5f7; // 表单背景
+@table--active-color: #e3effd; // 表单选中
+
+// 字号
+@font-size-xlg: 2.2rem; // 大标题
+@font-size-lg: 2rem; // 标题
+@font-size-xmd: 1.6rem; // 副标题
+@font-size-md: 1.4rem; // 主字体
+@font-size-sm: 1.2rem; // 说明 描述
+@font-size-zs: 1rem; // 说明 描述
+
+// 圆角
+@radius-sm: 0.22rem;
+@radius-md: 0.4rem;
+@radius-lg: 0.8rem;
+
+// 间距
+@space-lg: 24px;
+@space-xmd: 22px;
+@space-md: 20px;
+@space-sm: 16px;
+@space-xs: 14px;
+@space-xxs: 12px;
+
+.baseBorder(@radius: 4px) {
+ border: 1px solid @color-border;
+ border-radius: @radius-sm;
+}
diff --git a/src/typings.d.ts b/src/typings.d.ts
index c06709b6769b85ea747581ad7aa11cb49623f2c7..1207eb6c626291047562366b2d53d0fc75531122 100644
--- a/src/typings.d.ts
+++ b/src/typings.d.ts
@@ -22,11 +22,11 @@ declare module 'webpack-theme-color-replacer';
declare module 'webpack-theme-color-replacer/client';
// src/typings.d.ts
-declare module 'umi-plugin-react/locale' {
- export default interface MessageDescriptor {
- id: string;
- } /* eslint-disable-line */
-}
+// declare module 'umi-plugin-react/locale' {
+// export default interface MessageDescriptor {
+// id: string;
+// } /* eslint-disable-line */
+// }
declare let ga: Function;
diff --git a/src/utils/index.js b/src/utils/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..24770d8ddb5069863c69d874b41cd51b1062273f
--- /dev/null
+++ b/src/utils/index.js
@@ -0,0 +1,418 @@
+// eslint-disable-next-line eslint-comments/disable-enable-pair
+/* eslint-disable no-bitwise */
+
+// 工具类已经转移到solomon-utils下,如果需要添加工具部分,请先考虑是否需要添加到solomon-utils下
+import pathToRegexp from 'path-to-regexp';
+
+export const generateUUID = () => {
+ let d = new Date().getTime();
+ const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
+ const r = (d + Math.random() * 16) % 16 | 0;
+ d = Math.floor(d / 16);
+ return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
+ });
+ return uuid;
+};
+
+/**
+ * 检查是否为正确的移动的电话号码
+ */
+export const checkMobilePhone = mobilePhone => {
+ if (!/^1(3|4|5|7|8)\d{9}$/.test(mobilePhone)) {
+ return false;
+ }
+ return true;
+};
+
+/**
+ * 检查是否为正确的邮箱
+ */
+
+export const checkEmail = mobilePhone => {
+ const reg = new RegExp(
+ '^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$',
+ );
+ if (!reg.test(mobilePhone)) {
+ return false;
+ }
+ return true;
+};
+
+/**
+ * 检查是否为正确的密码
+ * @param {*} password
+ */
+export const checkPassword = password => {
+ const reg = new RegExp(/^(\w){6,20}$/);
+ if (!reg.test(password)) {
+ return false;
+ }
+ return true;
+};
+
+/**
+ * 转换后端返回的表格数据成前端使用的表格数据
+ * @param {object} data 后端数据
+ * @param {object} option
+ * @param {string} option.keyCode 指定唯一标识字段
+ * @param {function} option.onChange 分页回调
+ */
+export const trimTableData = (data = {}, option = {}) => {
+ const { records = [], current = 1, pageSize = 1, total = 1 } = data;
+ const { keyCode, onChange } = option;
+ let tableData = records;
+ const pageData = {
+ current,
+ pageSize,
+ total,
+ };
+ if (keyCode) {
+ tableData = records.map(item => ({ key: item[keyCode], ...item }));
+ }
+ if (typeof onChange === 'function') {
+ pageData.onChange = onChange;
+ }
+ return {
+ tableData,
+ pageData,
+ };
+};
+
+/**
+ * 转换后端返回的静态数据为key、value格式
+ * @param {object} staticData 后端静态数据
+ * @param {string} staticKey 需要处理的静态数据唯一ID
+ */
+export const trimStaticData = (staticData = {}, staticKey) =>
+ (staticData[staticKey] || [])
+ // .filter(item => item.paramLocale === "zh_CN")
+ .map(item => ({
+ key: item.paramValue,
+ value: item.paramName,
+ }));
+
+/**
+ * 处理后端返回的组织数据为供Select组件使用的带结构数据
+ * @param {object} data
+ */
+export const trimOrgaData = data => {
+ const trimData = clone(
+ data.map(item => ({
+ ...item,
+ title: item.orgName,
+ value: item.orgId,
+ key: item.orgId,
+ })),
+ );
+ const orgaData = trimData.filter(item => item.orgType === 1);
+ const depaData = trimData.filter(item => item.orgType === 2);
+
+ // 处理部门数据
+ depaData.forEach(item => {
+ const orgaKey = orgaData.findIndex(orgaItem => orgaItem.orgId === item.parentOrgId);
+ if (orgaKey > -1) {
+ const children = orgaData[orgaKey].children || [];
+ children.push(item);
+ orgaData[orgaKey].children = [...children];
+ }
+ });
+
+ // 处理公司数据
+ // 目前只支持两层数据
+ return orgaData.reduce((container, item) => {
+ const orgaKey = container.findIndex(orgaItem => orgaItem.orgId === item.parentOrgId);
+ if (orgaKey > -1) {
+ const children = container[orgaKey].children || [];
+ children.push(item);
+ container[orgaKey].children = [...children];
+ } else {
+ container.push(item);
+ }
+ return container;
+ }, []);
+};
+
+export const treeDataTransform = (data = [], key = 'id', parentKey = 'parendId', rootPid = -1) => {
+ const midObj = {};
+ const arr = [];
+
+ data.sort((a, b) => b[parentKey] - a[parentKey]);
+
+ // eslint-disable-next-line
+ const translator = data => {
+ if (!data || !data.length) {
+ return data;
+ }
+ data.forEach((item, index) => {
+ const nowPid = item[parentKey];
+ const nowId = item[key];
+
+ if (nowPid !== rootPid) {
+ translator(item);
+ delete data[index];
+ }
+
+ // 建立当前节点的父节点的children 数组
+ if (midObj[nowPid]) {
+ midObj[nowPid].push(item);
+ } else {
+ midObj[nowPid] = [];
+ midObj[nowPid].push(item);
+ }
+ // 将children 放入合适的位置
+ if (midObj[nowId]) {
+ item.children = midObj[nowId];
+ delete midObj[nowId];
+ if (item && data[index]) {
+ arr.push(item);
+ }
+ }
+ });
+ };
+ translator(data);
+ return arr;
+};
+
+export const treeTransform1 = (data = [], key = 'id', parentKey = 'parendId', rootPid = -1) => {
+ const parents = data.filter(
+ item => item[parentKey] === rootPid || item[parentKey] === 'undefined',
+ );
+ const children = data.filter(
+ item => item[parentKey] !== rootPid && item[parentKey] !== 'undefined',
+ );
+
+ // eslint-disable-next-line
+ const translator = (parents, children) => {
+ parents.forEach(parent => {
+ children.forEach((current, index) => {
+ if (current[parentKey] !== parent[key]) {
+ return;
+ }
+ const temp = JSON.parse(JSON.stringify(children));
+ temp.splice(index, 1);
+ if (typeof parent.children !== 'undefined') {
+ parent.children.push(current);
+ } else {
+ parent.children = [current];
+ }
+ return translator([current], temp);
+ });
+ });
+ };
+
+ translator(parents, children);
+
+ return parents;
+};
+
+/**
+ * 平级数组菜单列表转成树形菜单列表
+ * @param {平级数组菜单列表} flatMenuList
+ */
+export const toTreeMenuList = (flatMenuList = []) => {
+ const tree = [];
+ const key = 'menuId';
+ const pKey = 'pMenuId';
+ const topFlag = 0;
+
+ if (flatMenuList) {
+ const dict = {};
+ // add rood node
+ flatMenuList.forEach(item => {
+ dict[item[key]] = item;
+ if (equals(item[pKey], topFlag) || item[pKey] === '') {
+ item.level = 0;
+ item.key = String(item[key]);
+ item.icon = item.menuIcon;
+ item.link = item.menuUrl;
+ item.title = item.menuName;
+ tree[tree.length] = item; // 添加根节点,可能有多个节点
+ }
+ });
+ flatMenuList.forEach(item => {
+ const child = item;
+ if (equals(child[pKey], topFlag) || child[pKey] === '') {
+ return;
+ }
+ const parent = dict[child[pKey]];
+ if (parent) {
+ // child.parent = parent;
+ if (!parent.children) {
+ parent.children = [];
+ }
+ child.key = String(child[key]);
+ child.level = parent.level + 1;
+ child.icon = child.menuIcon;
+ child.link = child.menuUrl;
+ child.title = child.menuName;
+ parent.children[parent.children.length] = child;
+ }
+ });
+ return tree;
+ }
+};
+
+/**
+ * 平级组织部门转换成树形组织部门
+ * @param {*} flatList
+ */
+export const toDepaTree = (flatList = []) =>
+ flatListToTree(flatList, 'orgId', 'parentOrgId', 0, {
+ title: 'orgName',
+ value: 'orgId',
+ });
+
+/**
+ * 平级数组部门-组织列表转成树形部门-组织列表
+ * @param {评级列表} flatList
+ * @param {*} key
+ * @param {*} pKey
+ * @param {*} topFlag
+ * @param {*} extentProcess
+ */
+export const flatListToTree = (
+ flatList = [],
+ key = 'id',
+ pKey = 'pId',
+ topFlag = 0,
+ mappingData = {},
+) => {
+ const tree = [];
+ if (flatList) {
+ const dict = {};
+ // add rood node
+ flatList.forEach(item => {
+ dict[item[key]] = item;
+ if (equals(item[pKey], topFlag) || item[pKey] === '') {
+ item.level = 0;
+ item.key = String(item[key]);
+
+ Object.keys(mappingData).forEach(k => {
+ item[k] = item[mappingData[k]];
+ });
+
+ tree[tree.length] = item; // 添加根节点,可能有多个节点
+ }
+ });
+ flatList.forEach(item => {
+ const child = item;
+ if (equals(child[pKey], topFlag) || child[pKey] === '') {
+ return;
+ }
+ const parent = dict[child[pKey]];
+ if (parent) {
+ // child.parent = parent;
+ if (!parent.children) {
+ parent.children = [];
+ }
+ child.key = String(child[key]);
+ child.level = parent.level + 1;
+
+ Object.keys(mappingData).forEach(k => {
+ child[k] = child[mappingData[k]];
+ });
+
+ parent.children[parent.children.length] = child;
+ }
+ });
+ return tree;
+ }
+};
+
+/**
+ * url转成数组
+ * /userinfo/2144/id => ['/userinfo','/useinfo/2144,'/userindo/2144/id']
+ * @param {url} url
+ */
+export function urlToList(url) {
+ const urllist = url.split('/').filter(i => i);
+ return urllist.map((urlItem, index) => `/${urllist.slice(0, index + 1).join('/')}`);
+}
+
+/**
+ * 判断路径是否匹配了菜单旅游业经
+ * @param {*} flatMenuList
+ * @param {*} path
+ */
+export const getMenuMatches = (flatMenuList, path) =>
+ flatMenuList.filter(item => {
+ if (item.menuUrl) {
+ return pathToRegexp(item.menuUrl).test(path);
+ }
+ return false;
+ });
+
+/**
+ * 获得当前选中的菜单key
+ * @param {*} flatMenuList
+ * @param {*} path
+ */
+export const getSelectedkey = (flatMenuList = [], pathname) => {
+ const items = urlToList(pathname)
+ .map(item => getMenuMatches(flatMenuList, item)[0])
+ .filter(item => item);
+ return items && items.length > 0 ? String(items[items.length - 1].menuId) : '';
+};
+
+export const getDefaultOpenKeys = (flatMenuList = [], pathname) => {
+ const openKeys = [];
+ const topFlag = 0;
+ if (flatMenuList.length > 0) {
+ const key = getSelectedkey(flatMenuList, pathname);
+ const menuIdMap = {};
+ const pMenuIdMap = {};
+ flatMenuList.forEach(item => {
+ menuIdMap[item.menuId] = item;
+ pMenuIdMap[item.pMenuId] = item;
+ });
+ if (key === '') {
+ openKeys.push(String(pMenuIdMap[topFlag].menuId));
+ } else {
+ let t = key;
+ for (let i = 0; i < flatMenuList.length; i += 1) {
+ if (equals(t, topFlag)) {
+ break;
+ }
+ if (menuIdMap[t]) {
+ openKeys.push(String(menuIdMap[t].menuId));
+ t = menuIdMap[t].pMenuId;
+ }
+ }
+ }
+ }
+ return openKeys;
+};
+
+/**
+ * 文件下载
+ * @param {*} url
+ * @param {*} fileNames
+ * @param {...any} params
+ */
+export async function downloadFile(url, params) {
+ const token = storage.get('token');
+ const formEle = document.createElement('form');
+ formEle.method = 'get';
+ formEle.style = 'display:none;';
+ formEle.action = url;
+
+ const tokenEle = document.createElement('input');
+ tokenEle.type = 'hidden';
+ tokenEle.name = 'token';
+ tokenEle.value = token;
+ formEle.appendChild(tokenEle);
+
+ for (const key in params) {
+ if (key && params[key]) {
+ const paramsEle = document.createElement('input');
+ paramsEle.type = 'hidden';
+ paramsEle.name = key;
+ paramsEle.value = params[key];
+ formEle.appendChild(paramsEle);
+ }
+ }
+
+ document.body.appendChild(formEle);
+ formEle.submit();
+ document.body.removeChild(formEle);
+}
diff --git a/src/utils/kim-request.js b/src/utils/kim-request.js
new file mode 100644
index 0000000000000000000000000000000000000000..a04d991a2706fc03e28c170dbf2c7e17e9b31fdb
--- /dev/null
+++ b/src/utils/kim-request.js
@@ -0,0 +1,93 @@
+import axios from 'axios';
+
+const codeMessage = {
+ 200: '服务器成功返回请求的数据。',
+ 201: '新建或修改数据成功。',
+ 202: '一个请求已经进入后台排队(异步任务)。',
+ 204: '删除数据成功。',
+ 400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
+ 401: '用户没有权限(令牌、用户名、密码错误)。',
+ 403: '用户得到授权,但是访问是被禁止的。',
+ 404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
+ 406: '请求的格式不可得。',
+ 410: '请求的资源被永久删除,且不会再得到的。',
+ 422: '当创建一个对象时,发生一个验证错误。',
+ 500: '服务器发生错误,请检查服务器。',
+ 502: '网关错误。',
+ 503: '服务不可用,服务器暂时过载或维护。',
+ 504: '网关超时。',
+};
+
+class HttpRequest {
+ constructor(options) {
+ this.options = options;
+ this.queues = {};
+ }
+
+ getInsideConfig() {
+ const config = {
+ baseURL: this.options.baseUrl,
+ headers: {
+ 'x-requested-with': 'XMLHttpRequest',
+ 'Access-Control-Allow-Origin': '*',
+ 'Content-Type': 'application/json',
+ Accept: 'application/json',
+ withCredentials: false, // default
+ timeout: 10000,
+ responseType: 'json',
+ ...this.options.headers,
+ },
+ };
+ return config;
+ }
+
+ destroy(url) {
+ delete this.queues[url];
+ }
+
+ interceptors(instance, url, options) {
+ // 请求拦截
+ instance.interceptors.request.use(
+ config => {
+ this.queues[url] = true;
+ if (options.beforeRequest instanceof Function) {
+ options.beforeRequest({ queues: this.queues, config, options });
+ }
+ return config;
+ },
+ error => Promise.reject(error),
+ );
+ // 响应拦截
+ instance.interceptors.response.use(
+ res => {
+ this.destroy(url);
+ const { data, status } = res;
+ return { data, status, statusText: codeMessage[status] };
+ },
+ error => {
+ this.destroy(url);
+ const errorResult = JSON.parse(JSON.stringify(error));
+ const errorInfo = error.response;
+ if (!errorInfo) {
+ const {
+ request: { status },
+ } = errorResult;
+ errorResult.statusText = codeMessage[status];
+ if (options.errorHandler instanceof Function) {
+ options.errorHandler({ queues: this.queues, error, options });
+ }
+ }
+
+ return Promise.reject(errorResult);
+ },
+ );
+ }
+
+ request(options) {
+ const instance = axios.create();
+ const ops = Object.assign(this.getInsideConfig(), options);
+ this.interceptors(instance, ops.url, ops);
+ return instance(ops);
+ }
+}
+export default HttpRequest;
diff --git a/src/utils/request.js b/src/utils/request.js
new file mode 100644
index 0000000000000000000000000000000000000000..01836c951b508a97ba1ed7203d2e0ec05e8116ad
--- /dev/null
+++ b/src/utils/request.js
@@ -0,0 +1,103 @@
+import { notification } from 'antd';
+import HttpRequest from './kim-request';
+import config from '@/config';
+
+const { baseUrl, apiPrefix, headers } = config;
+
+/**
+ * 异常处理程序
+ */
+const errorHandler = error => {
+ const { response } = error;
+ if (response && response.status) {
+ const errorText = response.statusText;
+ const { status, url, code } = response;
+ notification.error({
+ key: `notification_${code}`,
+ message: `请求错误 ${status}: ${url}`,
+ description: errorText,
+ });
+ }
+};
+
+const axios = new HttpRequest({
+ baseUrl,
+ headers: headers() || {},
+ errorHandler,
+});
+
+const mergeApi = (url, more) => {
+ if (more && more.apiPrefix && typeof more.apiPrefix === 'string') {
+ return `${config.apiPrefix}${url}`;
+ }
+ if (apiPrefix && typeof apiPrefix === 'string') {
+ return `${config.apiPrefix}${url}`;
+ }
+ return url;
+};
+
+const get = (url, data, more = {}) =>
+ axios.request({
+ method: 'get', // default
+ url: `${mergeApi(url, more)}`,
+ params: data,
+ ...more,
+ });
+
+const post = (url, data, more = {}) =>
+ axios.request({
+ method: 'post', // default
+ url: `${mergeApi(url, more)}`,
+ data,
+ ...more,
+ });
+
+const put = (url, data, more = {}) =>
+ axios.request({
+ method: 'put', // default
+ url: `${mergeApi(url, more)}`,
+ data,
+ ...more,
+ });
+
+const del = (url, data, more = {}) =>
+ axios.request({
+ method: 'delete', // default
+ url: `${mergeApi(url, more)}`,
+ data,
+ ...more,
+ });
+
+const patch = (url, data, more = {}) =>
+ axios.request({
+ method: 'patch', // default
+ url: `${mergeApi(url, more)}`,
+ data,
+ ...more,
+ });
+
+const formDataUpload = (url, data, more = {}) => {
+ const formData = new FormData();
+ if (data) {
+ Object.keys(data).forEach(key => {
+ formData.append(key, data[key]);
+ });
+ }
+ axios.request({
+ method: 'post', // default
+ url: `${mergeApi(url, more)}`,
+ data: formData,
+ headers: {
+ 'Content-Type': 'multipart/form-data',
+ },
+ ...more,
+ });
+};
+
+const uploadFile = (url, data, type = 'formData', more = {}) => {
+ if (type === 'formData') {
+ formDataUpload(url, data, more);
+ }
+};
+
+export { axios as request, get, post, put, del, patch, uploadFile };
diff --git a/src/utils/request.ts b/src/utils/request.ts
deleted file mode 100644
index 3babf7e7c0d7951585ac8525d7bbffe47c316183..0000000000000000000000000000000000000000
--- a/src/utils/request.ts
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * request 网络请求工具
- * 更详细的 api 文档: https://github.com/umijs/umi-request
- */
-import { extend } from 'umi-request';
-import { notification } from 'antd';
-
-const codeMessage = {
- 200: '服务器成功返回请求的数据。',
- 201: '新建或修改数据成功。',
- 202: '一个请求已经进入后台排队(异步任务)。',
- 204: '删除数据成功。',
- 400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
- 401: '用户没有权限(令牌、用户名、密码错误)。',
- 403: '用户得到授权,但是访问是被禁止的。',
- 404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
- 406: '请求的格式不可得。',
- 410: '请求的资源被永久删除,且不会再得到的。',
- 422: '当创建一个对象时,发生一个验证错误。',
- 500: '服务器发生错误,请检查服务器。',
- 502: '网关错误。',
- 503: '服务不可用,服务器暂时过载或维护。',
- 504: '网关超时。',
-};
-
-/**
- * 异常处理程序
- */
-const errorHandler = (error: { response: Response }): void => {
- const { response } = error;
- if (response && response.status) {
- const errorText = codeMessage[response.status] || response.statusText;
- const { status, url } = response;
-
- notification.error({
- message: `请求错误 ${status}: ${url}`,
- description: errorText,
- });
- }
-};
-
-/**
- * 配置request请求时的默认参数
- */
-const request = extend({
- errorHandler, // 默认错误处理
- credentials: 'include', // 默认请求是否带上cookie
-});
-
-export default request;
diff --git a/src/utils/store.js b/src/utils/store.js
new file mode 100644
index 0000000000000000000000000000000000000000..b6cef3df0f28321c30a78ad0d3549168e34c57ec
--- /dev/null
+++ b/src/utils/store.js
@@ -0,0 +1,20 @@
+import config from '@/config';
+import engine from 'store/src/store-engine';
+import localStorage from 'store/storages/localStorage';
+
+import defaults from 'store/plugins/defaults';
+import expire from 'store/plugins/expire';
+
+console.log(config);
+
+const { storeNameSpace } = config;
+
+const storages = [localStorage];
+const plugins = [defaults, expire];
+
+if (window && !window.localStorage) {
+ // eslint-disable-next-line no-console
+ console.error('localStorage对象不存在');
+}
+
+export default engine.createStore(storages, plugins, storeNameSpace);
diff --git a/tsconfig.json b/tsconfig.json
index 638b2a0b1ab6ca51333a9018103e7d856e4cf342..10fe5ee4ec5a3f2bf5f754540eb05c24dd526850 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -29,6 +29,7 @@
"jest",
"src/setupTests.ts",
"tslint:latest",
- "tslint-config-prettier"
+ "tslint-config-prettier",
+ "./src/pages/system/*"
]
}