✨ Feat: 前端:框架搭建完毕
This commit is contained in:
parent
950335441f
commit
78b6bce37f
1
front/.gitignore
vendored
1
front/.gitignore
vendored
@ -21,3 +21,4 @@
|
|||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
|
.vscode
|
@ -10,6 +10,7 @@
|
|||||||
"babel-plugin-import": "^1.12.0",
|
"babel-plugin-import": "^1.12.0",
|
||||||
"customize-cra": "^0.2.14",
|
"customize-cra": "^0.2.14",
|
||||||
"less": "^3.9.0",
|
"less": "^3.9.0",
|
||||||
|
"query-string": "^6.8.1",
|
||||||
"react": "^16.8.6",
|
"react": "^16.8.6",
|
||||||
"react-app-rewired": "^2.1.3",
|
"react-app-rewired": "^2.1.3",
|
||||||
"react-dom": "^16.8.6",
|
"react-dom": "^16.8.6",
|
||||||
|
@ -4,7 +4,7 @@ import { withRouter } from "react-router-dom";
|
|||||||
import { Provider } from "react-redux";
|
import { Provider } from "react-redux";
|
||||||
import store from "./redux";
|
import store from "./redux";
|
||||||
import Login from "./pages/public/Login";
|
import Login from "./pages/public/Login";
|
||||||
import Main from "./pages/Main";
|
import Main from "./pages/index";
|
||||||
import NotFound from "./pages/public/notFound/NotFound";
|
import NotFound from "./pages/public/notFound/NotFound";
|
||||||
|
|
||||||
class App extends Component {
|
class App extends Component {
|
||||||
@ -15,7 +15,7 @@ class App extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const mainStyle = {
|
const mainStyle = {
|
||||||
fontSize: "0.16rem"
|
fontSize: "0.14rem"
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
|
|
||||||
class Main extends React.Component {
|
|
||||||
render() {
|
|
||||||
return <div>这是主页</div>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Main;
|
|
27
front/src/pages/index.jsx
Normal file
27
front/src/pages/index.jsx
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { Button } from "antd";
|
||||||
|
import httpUtil from "../util/httpUtil.js";
|
||||||
|
|
||||||
|
class Main extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
testPriviledge = () => {
|
||||||
|
httpUtil.get("/priviledgeTest");
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div>这是主页</div>
|
||||||
|
<Button type="primary" onClick={this.testPriviledge}>
|
||||||
|
测试未登录跳转
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Main;
|
@ -1,13 +1,14 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
|
import queryString from "query-string";
|
||||||
import { Button, Input, message } from "antd";
|
import { Button, Input, message } from "antd";
|
||||||
import IconFont from "../../../components/IconFont";
|
import IconFont from "../../../components/IconFont";
|
||||||
import styles from "./index.module.less";
|
import styles from "./index.module.less";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { changeLoginInfo } from "../../../redux/action/LoginInfoAction";
|
import { changeLoginInfo, DATA_NAME } from "../../../redux/action/loginInfoAction";
|
||||||
import axios from "../../../util/httpUtil";
|
import axios from "../../../util/httpUtil";
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
function mapStateToProps(state) {
|
||||||
return {};
|
return state[DATA_NAME];
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapDispatchToProps(dispatch) {
|
function mapDispatchToProps(dispatch) {
|
||||||
@ -23,6 +24,7 @@ class Login extends Component {
|
|||||||
username: "",
|
username: "",
|
||||||
password: ""
|
password: ""
|
||||||
};
|
};
|
||||||
|
this.query = queryString.parse(window.location.search);
|
||||||
}
|
}
|
||||||
|
|
||||||
usernameInput = e => {
|
usernameInput = e => {
|
||||||
@ -40,7 +42,11 @@ class Login extends Component {
|
|||||||
window.userInfo = res.userInfo;
|
window.userInfo = res.userInfo;
|
||||||
message.success("登录成功");
|
message.success("登录成功");
|
||||||
this.props.updateLoginInfo(res.token, res.userInfo);
|
this.props.updateLoginInfo(res.token, res.userInfo);
|
||||||
|
if (this.query.redirect) {
|
||||||
|
this.props.history.replace(decodeURIComponent(this.query.redirect));
|
||||||
|
} else {
|
||||||
this.props.history.replace("/");
|
this.props.history.replace("/");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
// 定义登录信息在store中的名字
|
||||||
|
export const DATA_NAME = "loginInfo";
|
||||||
|
|
||||||
|
//定义修改loginInfo type
|
||||||
export const CHANGE_LOGIN_INFO = "changeLoginStatus";
|
export const CHANGE_LOGIN_INFO = "changeLoginStatus";
|
||||||
|
|
||||||
export const changeLoginInfo = (token, userInfo) => {
|
export const changeLoginInfo = (token, userInfo) => {
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import { combineReducers } from "redux";
|
import { combineReducers } from "redux";
|
||||||
|
import { DATA_NAME } from "../action/loginInfoAction";
|
||||||
import loginInfo from "./loginInfo";
|
import loginInfo from "./loginInfo";
|
||||||
|
|
||||||
const reducer = combineReducers({
|
const data = {};
|
||||||
loginInfo
|
data[DATA_NAME] = loginInfo;
|
||||||
});
|
|
||||||
|
|
||||||
|
const reducer = combineReducers(data);
|
||||||
|
|
||||||
export default reducer;
|
export default reducer;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as loginAction from "../action/LoginInfoAction";
|
import * as loginAction from "../action/loginInfoAction";
|
||||||
|
|
||||||
function getInitData() {
|
function getInitData() {
|
||||||
let token, userInfo;
|
let token, userInfo;
|
||||||
|
@ -23,12 +23,19 @@ instance.interceptors.response.use(
|
|||||||
} else {
|
} else {
|
||||||
message = "出问题啦:" + error.response.status;
|
message = "出问题啦:" + error.response.status;
|
||||||
description = JSON.stringify(error.response.data);
|
description = JSON.stringify(error.response.data);
|
||||||
|
//401跳转到登录页面
|
||||||
}
|
}
|
||||||
notification.open({
|
notification.open({
|
||||||
message,
|
message,
|
||||||
description,
|
description,
|
||||||
duration: 2
|
duration: 2
|
||||||
});
|
});
|
||||||
|
setTimeout(() => {
|
||||||
|
if (error.response && error.response.status === 401) {
|
||||||
|
let redirect = encodeURIComponent(window.location.pathname + window.location.search);
|
||||||
|
window.location.replace("/public/login?redirect=" + redirect);
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -8252,6 +8252,15 @@ qs@~6.5.2:
|
|||||||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
|
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
|
||||||
integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==
|
integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==
|
||||||
|
|
||||||
|
query-string@^6.8.1:
|
||||||
|
version "6.8.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/query-string/-/query-string-6.8.1.tgz#62c54a7ef37d01b538c8fd56f95740c81d438a26"
|
||||||
|
integrity sha512-g6y0Lbq10a5pPQpjlFuojfMfV1Pd2Jw9h75ypiYPPia3Gcq2rgkKiIwbkS6JxH7c5f5u/B/sB+d13PU+g1eu4Q==
|
||||||
|
dependencies:
|
||||||
|
decode-uri-component "^0.2.0"
|
||||||
|
split-on-first "^1.0.0"
|
||||||
|
strict-uri-encode "^2.0.0"
|
||||||
|
|
||||||
querystring-es3@^0.2.0:
|
querystring-es3@^0.2.0:
|
||||||
version "0.2.1"
|
version "0.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73"
|
resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73"
|
||||||
@ -9781,6 +9790,11 @@ spdy@^4.0.0:
|
|||||||
select-hose "^2.0.0"
|
select-hose "^2.0.0"
|
||||||
spdy-transport "^3.0.0"
|
spdy-transport "^3.0.0"
|
||||||
|
|
||||||
|
split-on-first@^1.0.0:
|
||||||
|
version "1.1.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/split-on-first/-/split-on-first-1.1.0.tgz#f610afeee3b12bce1d0c30425e76398b78249a5f"
|
||||||
|
integrity sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==
|
||||||
|
|
||||||
split-string@^3.0.1, split-string@^3.0.2:
|
split-string@^3.0.1, split-string@^3.0.2:
|
||||||
version "3.1.0"
|
version "3.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2"
|
resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2"
|
||||||
@ -9875,6 +9889,11 @@ stream-shift@^1.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.0.tgz#d5c752825e5367e786f78e18e445ea223a155952"
|
resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.0.tgz#d5c752825e5367e786f78e18e445ea223a155952"
|
||||||
integrity sha1-1cdSgl5TZ+eG944Y5EXqIjoVWVI=
|
integrity sha1-1cdSgl5TZ+eG944Y5EXqIjoVWVI=
|
||||||
|
|
||||||
|
strict-uri-encode@^2.0.0:
|
||||||
|
version "2.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546"
|
||||||
|
integrity sha1-ucczDHBChi9rFC3CdLvMWGbONUY=
|
||||||
|
|
||||||
string-convert@^0.2.0:
|
string-convert@^0.2.0:
|
||||||
version "0.2.1"
|
version "0.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/string-convert/-/string-convert-0.2.1.tgz#6982cc3049fbb4cd85f8b24568b9d9bf39eeff97"
|
resolved "https://registry.yarnpkg.com/string-convert/-/string-convert-0.2.1.tgz#6982cc3049fbb4cd85f8b24568b9d9bf39eeff97"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user