Skip to content

Commit 9c68c1e

Browse files
committed
路由跳转Modal.destroyAll()和message.destroy()
1 parent 404dab7 commit 9c68c1e

File tree

17 files changed

+424
-12
lines changed

17 files changed

+424
-12
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
"react-dev-utils": "^9.0.2",
5353
"react-dom": "^16.9.0",
5454
"react-redux": "^7.1.1",
55+
"react-router": "^5.1.2",
5556
"redux": "^4.0.4",
57+
"reqwest": "^2.0.5",
5658
"resolve": "1.12.0",
5759
"resolve-url-loader": "3.1.0",
5860
"sass-loader": "7.2.0",
@@ -143,5 +145,6 @@
143145
"devDependencies": {
144146
"react-router-dom": "^5.0.1",
145147
"react-transition-group": "^4.3.0"
146-
}
148+
},
149+
"proxy": "http://193.112.220.108:8080"
147150
}

src/history.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { createHashHistory } from 'history';
2+
3+
const history = createHashHistory();
4+
export default history;

src/page/Reload/index.jsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { Redirect } from 'react-router-dom';
4+
5+
import { searchParser } from '../../utils/index';
6+
import req from '../../req';
7+
8+
function Page({ location }) {
9+
req.clearAllCache();
10+
if (location.search) {
11+
const urlData = searchParser(location.search) || {};
12+
if (urlData.url) {
13+
const { url } = urlData;
14+
return <Redirect to={decodeURIComponent(url)} />;
15+
}
16+
}
17+
return <Redirect to="/" />;
18+
}
19+
20+
Page.propTypes = {
21+
location: PropTypes.object.isRequired,
22+
};
23+
24+
export default Page;

src/page/form/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import PropTypes from 'prop-types';
33
import {
4-
Input, Form, Button,
4+
Input, Form, Button, message,
55
} from 'antd';
66

77
const { TextArea } = Input;
@@ -12,9 +12,9 @@ const { TextArea } = Input;
1212
*/
1313
function Page({form}) {
1414
const { getFieldDecorator, validateFields, getFieldValue } = form;
15-
function hasErrors(fieldsError) {
16-
return Object.keys(fieldsError).some(field => fieldsError[field]);
17-
}
15+
useEffect(() => {
16+
message.success('111');
17+
}, []);
1818
function onSubmit() {
1919
validateFields((err, val) => {
2020
console.log('value', val);

src/page/promise/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
import { useEffect, useState } from 'react';
3+
import req from '../../req';
4+
5+
function Page() {
6+
const [infos, setInfos] = useState(null);
7+
function getCrtUserInfos() {
8+
req.user.getMyAuthority()
9+
.then((res) => {
10+
if (res.code !== 0) {
11+
// req.err.show(res);
12+
return;
13+
}
14+
setInfos(res.data);
15+
console.log('getCrtUserInfos', infos);
16+
})
17+
// .catch(req.err.show);
18+
}
19+
useEffect(() => {
20+
getCrtUserInfos();
21+
}, [])
22+
return 111;
23+
}
24+
25+
export default Page;

src/req/api/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import transform from './transform';
2+
import session from './session';
3+
import user from './user';
4+
5+
export default {
6+
install(req) {
7+
req.session = session;
8+
req.user = transform(user);
9+
},
10+
};

src/req/api/session.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* 设置cookie
3+
* @param {string} cName key
4+
* @param {string} value value
5+
* @param {number} expiredays 日期天数
6+
*/
7+
export function setCookie(cName, value, expiredays) {
8+
const cookies = {
9+
[cName]: escape(value),
10+
path: '/',
11+
};
12+
if (expiredays) {
13+
const exdate = new Date();
14+
exdate.setDate(exdate.getDate() + expiredays);
15+
cookies.expires = exdate.toGMTString();
16+
}
17+
document.cookie = Object.keys(cookies).map((key) => `${key}=${cookies[key]}`).join(';');
18+
}
19+
20+
/**
21+
* 获取cookie
22+
* @param {string} cName key
23+
*/
24+
export function getCookie(cName) {
25+
if (document.cookie.length > 0) {
26+
let cStart = document.cookie.indexOf(`${cName}=`);
27+
if (cStart !== -1) {
28+
cStart = cStart + cName.length + 1;
29+
let cEnd = document.cookie.indexOf(';', cStart);
30+
if (cEnd === -1) {
31+
cEnd = document.cookie.length;
32+
}
33+
return unescape(document.cookie.substring(cStart, cEnd));
34+
}
35+
}
36+
return '';
37+
}
38+
39+
const cookieKey = 'sessionId';
40+
let sessionId = getCookie(cookieKey) || '';
41+
42+
/**
43+
* 获取session
44+
*/
45+
function getSession() {
46+
return sessionId;
47+
}
48+
49+
/**
50+
* 设置session
51+
*/
52+
function setSession(val) {
53+
sessionId = val;
54+
setCookie(cookieKey, val);
55+
}
56+
57+
export default {
58+
get: getSession,
59+
set: setSession,
60+
};

src/req/api/transform.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import reqwest from 'reqwest';
2+
import { baseUrl } from '../config';
3+
import session from './session';
4+
5+
function wrapper(api) {
6+
console.log('api', api);
7+
return (data, originData = null) => {
8+
const sessionId = session.get();
9+
const {
10+
method, headers = {},
11+
} = api;
12+
if (sessionId) {
13+
headers.sessionId = '38d30a51aedb4e7d94f46df8c0cf4654';
14+
}
15+
let newData = null;
16+
let { url } = api;
17+
if (typeof data === 'object') {
18+
newData = { ...data };
19+
url = url.replace(/\/:\w+/g, (str) => {
20+
const w = str.substr(2);
21+
delete newData[w];
22+
return `/${data[w]}`;
23+
});
24+
} else {
25+
newData = data;
26+
}
27+
const options = {
28+
url: `${baseUrl}${url}`,
29+
method: (method || 'get').toUpperCase(),
30+
data: originData || newData,
31+
type: 'json',
32+
headers,
33+
contentType: 'application/json',
34+
};
35+
return reqwest(options);
36+
};
37+
}
38+
39+
export default function (apis) {
40+
const obj = {};
41+
Object.keys(apis).map((key) => {
42+
obj[key] = wrapper(apis[key]);
43+
return key;
44+
});
45+
return obj;
46+
}

src/req/api/user.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const api = {
2+
getMyInfo: {
3+
url: '/eobi-api/api/sys/currentUserInfo',
4+
},
5+
getMyAuthority: {
6+
url: '/eobi-api/api/sys/getCurrentPermissions',
7+
},
8+
};
9+
10+
export default api;

src/req/config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const baseUrlTable = {
2+
// local: 'http://192.168.1.171:8086',
3+
local: '',
4+
dev: '',
5+
pre: '',
6+
release: 'https://labor.emodor.com',
7+
};
8+
9+
export const baseUrl = baseUrlTable.local;
10+
11+
export default {
12+
baseUrl,
13+
uploadAction: `${baseUrl}/eobi-api/api/file/upload`,
14+
};

0 commit comments

Comments
 (0)