This commit is contained in:
fanxb 2019-06-26 17:41:01 +08:00
parent 04ec599625
commit 2482634031
22 changed files with 11787 additions and 0 deletions

23
.gitignore vendored Normal file
View File

@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

68
README.md Normal file
View File

@ -0,0 +1,68 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.<br>
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.<br>
You will also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.<br>
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.<br>
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.<br>
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you cant go back!**
If you arent satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point youre on your own.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
### Analyzing the Bundle Size
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
### Making a Progressive Web App
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
### Advanced Configuration
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
### Deployment
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
### `npm run build` fails to minify
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

17
config-overrides.js Normal file
View File

@ -0,0 +1,17 @@
const { override, fixBabelImports, addLessLoader } = require("customize-cra");
module.exports = override(
//antd按需引入
fixBabelImports("import", {
libraryName: "antd",
libraryDirectory: "es",
style: true
}),
//配置less同时通过less的变量覆盖功能配置antd主题
addLessLoader({
//设置css类型生成规则
localIdentName: "[local]--[hash:base64:5]",
javascriptEnabled: true,
// modifyVars: { "@primary-color": "#1DA57A" }
})
);

43
package.json Normal file
View File

@ -0,0 +1,43 @@
{
"name": "chat-room",
"version": "0.1.0",
"private": true,
"homepage": ".",
"dependencies": {
"antd": "^3.19.8",
"babel-plugin-import": "^1.12.0",
"customize-cra": "^0.2.14",
"less": "^3.9.0",
"react": "^16.8.6",
"react-app-rewired": "^2.1.3",
"react-dom": "^16.8.6",
"react-redux": "^7.1.0",
"react-router-dom": "^5.0.1",
"react-scripts": "3.0.1",
"redux": "^4.0.1"
},
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-app-rewired eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"less-loader": "^5.0.0"
}
}

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

38
public/index.html Normal file
View File

@ -0,0 +1,38 @@
<!DOCTYPE html>
<html style="font-size: 100px" lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root" class="fullScreen"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

15
public/manifest.json Normal file
View File

@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

42
src/App.jsx Normal file
View File

@ -0,0 +1,42 @@
import React, { Component } from "react";
import { Route } from "react-router-dom";
import { withRouter } from "react-router-dom";
import { Provider } from "react-redux";
import store from "./redux";
import Login from "./pages/public/Login";
import Main from "./pages/main";
class App extends Component {
constructor(props) {
super(props);
this.state = {};
this.checkRoute(this.props.location.pathname);
}
componentWillReceiveProps(nextProps) {
this.checkRoute(nextProps.location.pathname);
}
checkRoute(currentPath) {
// if (currentPath !== "/login") {
// console.log("");
// this.props.history.replace("/login");
// }
}
render() {
const mainStyle = {
fontSize: "0.16rem"
};
return (
<Provider store={store}>
<div className="fullScreen" style={mainStyle}>
<Route exact path="/" component={Main} />
<Route exact path="/login" component={Login} />
</div>
</Provider>
);
}
}
export default withRouter(App);

View File

@ -0,0 +1,18 @@
import React, { Component } from "react";
import { Button } from "antd";
import styles1 from "./index.module.less";
class Hello extends Component {
render() {
return (
<div className={styles1.main}>
hello
<div className={styles1.text}>world</div>
<Button type="primary">你好</Button>
<div className="text1">heihei</div>
</div>
);
}
}
export default Hello;

View File

@ -0,0 +1,15 @@
.main {
width: 100%;
height: 50px;
text-align: center;
.text {
font-size: 2em;
}
:global {
.text1 {
color: green;
}
}
}

View File

@ -0,0 +1,7 @@
import { Icon } from "antd";
const IconFont = Icon.createFromIconfontCN({
scriptUrl: "//at.alicdn.com/t/font_1261825_8aroyishrdq.js"
});
export default IconFont;

34
src/index.css Normal file
View File

@ -0,0 +1,34 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace;
}
html,
body {
width: 100%;
height: 100%;
font-family: "lucida grande", "lucida sans unicode", lucida, helvetica, "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;
}
.fullScreen {
width: 100%;
height: 100%;
}
/* 居中设置 */
.flex {
display: flex;
}
.main-center {
justify-content: center;
}
.across-center {
align-items: center;
}

19
src/index.jsx Normal file
View File

@ -0,0 +1,19 @@
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import { BrowserRouter } from "react-router-dom";
import * as serviceWorker from "./serviceWorker";
const s = (
<BrowserRouter>
<App />
</BrowserRouter>
);
ReactDOM.render(s, document.getElementById("root"));
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();

33
src/pages/main/index.jsx Normal file
View File

@ -0,0 +1,33 @@
import React from "react";
import { connect } from "react-redux";
function mapStateToProps(state) {
return {
loginInfo: state.loginInfo
};
}
function mapDispatchToProps(dispatch) {
return {};
}
class Main extends React.Component {
constructor(props) {
console.log(props);
super(props);
this.state = {};
}
render() {
const { token, userInfo } = this.props.loginInfo;
if (token == null) {
return <div>这是首页你还没登陆</div>;
}
return <div>你好{userInfo.name}</div>;
}
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(Main);

View File

@ -0,0 +1,76 @@
import React, { Component } from "react";
import { Button, Input } from "antd";
import IconFont from "../../../components/IconFont";
import styles from "./index.module.less";
import { connect } from "react-redux";
import { Link } from "react-router-dom";
import { changeLoginInfo } from "../../../redux/action/LoginInfoAction";
function mapStateToProps(state) {
return {};
}
function mapDispatchToProps(dispatch) {
return {
dealClick: () => dispatch(changeLoginInfo("12345", { name: "fanxb", age: "12" }))
};
}
class Login extends Component {
constructor(props) {
super(props);
this.state = {
username: "",
password: ""
};
}
usernameInput = e => {
this.setState({ username: e.target.value });
};
passwordInput = e => {
this.setState({ password: e.target.value });
};
login = () => {
console.log("登陆了");
};
render() {
return (
<div className="fullScreen flex main-center across-center">
<div className={styles.main}>
<div className={styles.top}>
<IconFont type="icon-LC_icon_chat_fill" />
<span>FIM</span>
</div>
<div className={styles.bottom}>
<div className={styles.inputArea}>
<IconFont type="icon-head" style={{ fontSize: "3em" }} />
{/* 用户名密码输入框 */}
<div>
<div>
<Input placeholder="用户名" onChange={this.usernameInput} />
注册账户
</div>
<div>
<Input type="password" placeholder="密码" onChange={this.passwordInput} />
找回密码
</div>
</div>
</div>
<Button type="primary" onClick={this.props.dealClick}>
登录
</Button>
<Link to="/">回到首页</Link>
</div>
</div>
</div>
);
}
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(Login);

View File

@ -0,0 +1,37 @@
.main {
text-align: center;
width: 600px;
height: 400px;
box-shadow: #ccc 0px 0px 20px;
border-radius: 5px;
.top {
height: 50%;
border-radius: 5px 5px 0 0;
background: #3d4fae;
display: flex;
justify-content: center;
align-items: center;
font-size: 0.8rem;
color: white;
}
.bottom {
height: 50%;
background: #ebf2f9;
border-radius: 0 0 5px 5px;
.inputArea {
padding: 0.2rem 0;
display: flex;
justify-content: center;
align-items: center;
:global {
.ant-input {
width: 20em;
}
}
}
}
}

View File

@ -0,0 +1,11 @@
export const CHANGE_LOGIN_INFO = "changeLoginStatus";
export const changeLoginInfo = (token, userInfo) => {
return {
type: CHANGE_LOGIN_INFO,
data: {
token,
userInfo
}
};
};

6
src/redux/index.js Normal file
View File

@ -0,0 +1,6 @@
import { createStore } from "redux";
import reducer from "./reducer";
const store = createStore(reducer);
export default store;

View File

@ -0,0 +1,8 @@
import { combineReducers } from "redux";
import loginInfo from "./loginInfo";
const reducer = combineReducers({
loginInfo
});
export default reducer;

View File

@ -0,0 +1,17 @@
import * as loginAction from "../action/LoginInfoAction";
const initData = {
token: null,
userInfo: null
};
const LoginStatusReducer = (state = initData, action) => {
switch (action.type) {
case loginAction.CHANGE_LOGIN_INFO:
return { ...action.data };
default:
return state;
}
};
export default LoginStatusReducer;

135
src/serviceWorker.js Normal file
View File

@ -0,0 +1,135 @@
// This optional code is used to register a service worker.
// register() is not called by default.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on subsequent visits to a page, after all the
// existing tabs open on the page have been closed, since previously cached
// resources are updated in the background.
// To learn more about the benefits of this model and instructions on how to
// opt-in, read https://bit.ly/CRA-PWA
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
export function register(config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return;
}
window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://bit.ly/CRA-PWA'
);
});
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
}
});
}
}
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
);
// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration);
}
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
// Execute callback
if (config && config.onSuccess) {
config.onSuccess(registration);
}
}
}
};
};
})
.catch(error => {
console.error('Error during service worker registration:', error);
});
}
function checkValidServiceWorker(swUrl, config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl)
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload();
});
});
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl, config);
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
});
}
export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => {
registration.unregister();
});
}
}

11125
yarn.lock Normal file

File diff suppressed because it is too large Load Diff