From 872a42b7a596a20c7d2e41fdcbfe69f5594a69f3 Mon Sep 17 00:00:00 2001
From: CPunisher <1343316114@qq.com>
Date: Wed, 6 May 2020 20:39:05 +0800
Subject: [PATCH 1/7] Restructure code
---
package-lock.json | 55 ++++++++++++++++++++++++++++++++
package.json | 10 ++++--
src/App.js | 18 -----------
src/App.test.js | 9 ------
src/components/Footer.js | 20 ------------
src/components/InputInfo.js | 22 +++++++++++++
src/components/Qrcode.js | 15 ++-------
src/{ => components/app}/App.css | 0
src/components/app/App.js | 21 ++++++++++++
src/components/footer/Footer.js | 32 +++++++++++++++++++
src/components/header/Header.js | 20 ++++++++++++
src/containers/Layout.css | 4 ---
src/containers/Layout.js | 12 -------
src/index.js | 11 +++++--
src/reducers/index.js | 0
15 files changed, 169 insertions(+), 80 deletions(-)
delete mode 100644 src/App.js
delete mode 100644 src/App.test.js
delete mode 100644 src/components/Footer.js
create mode 100644 src/components/InputInfo.js
rename src/{ => components/app}/App.css (100%)
create mode 100644 src/components/app/App.js
create mode 100644 src/components/footer/Footer.js
create mode 100644 src/components/header/Header.js
delete mode 100644 src/containers/Layout.css
delete mode 100644 src/containers/Layout.js
create mode 100644 src/reducers/index.js
diff --git a/package-lock.json b/package-lock.json
index 0247657..c5eefca 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -6087,6 +6087,14 @@
"minimalistic-crypto-utils": "^1.0.1"
}
},
+ "hoist-non-react-statics": {
+ "version": "3.3.2",
+ "resolved": "https://registry.npm.taobao.org/hoist-non-react-statics/download/hoist-non-react-statics-3.3.2.tgz",
+ "integrity": "sha1-7OCsr3HWLClpwuxZ/v9CpLGoW0U=",
+ "requires": {
+ "react-is": "^16.7.0"
+ }
+ },
"hosted-git-info": {
"version": "2.8.8",
"resolved": "https://registry.npm.taobao.org/hosted-git-info/download/hosted-git-info-2.8.8.tgz",
@@ -10917,6 +10925,18 @@
"resolved": "https://registry.npm.taobao.org/react-is/download/react-is-16.13.1.tgz",
"integrity": "sha1-eJcppNw23imZ3BVt1sHZwYzqVqQ="
},
+ "react-redux": {
+ "version": "7.2.0",
+ "resolved": "https://registry.npm.taobao.org/react-redux/download/react-redux-7.2.0.tgz",
+ "integrity": "sha1-+XD2IZKzmBZC/sRv0NsYoHT+h50=",
+ "requires": {
+ "@babel/runtime": "^7.5.5",
+ "hoist-non-react-statics": "^3.3.0",
+ "loose-envify": "^1.4.0",
+ "prop-types": "^15.7.2",
+ "react-is": "^16.9.0"
+ }
+ },
"react-scripts": {
"version": "3.4.1",
"resolved": "https://registry.npm.taobao.org/react-scripts/download/react-scripts-3.4.1.tgz",
@@ -11079,6 +11099,36 @@
"strip-indent": "^3.0.0"
}
},
+ "redux": {
+ "version": "4.0.5",
+ "resolved": "https://registry.npm.taobao.org/redux/download/redux-4.0.5.tgz?cache=0&sync_timestamp=1577154206919&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fredux%2Fdownload%2Fredux-4.0.5.tgz",
+ "integrity": "sha1-TbXeWBbheJHeioDEJCMtBvBR2T8=",
+ "requires": {
+ "loose-envify": "^1.4.0",
+ "symbol-observable": "^1.2.0"
+ }
+ },
+ "redux-devtools": {
+ "version": "3.5.0",
+ "resolved": "https://registry.npm.taobao.org/redux-devtools/download/redux-devtools-3.5.0.tgz",
+ "integrity": "sha1-1pq3bU8Pir320kvPWVTXoaoraCc=",
+ "dev": true,
+ "requires": {
+ "lodash": "^4.2.0",
+ "prop-types": "^15.5.7",
+ "redux-devtools-instrument": "^1.9.0"
+ }
+ },
+ "redux-devtools-instrument": {
+ "version": "1.9.6",
+ "resolved": "https://registry.npm.taobao.org/redux-devtools-instrument/download/redux-devtools-instrument-1.9.6.tgz",
+ "integrity": "sha1-a0EllfdLnUjP1OzBPlhbFYjtbn4=",
+ "dev": true,
+ "requires": {
+ "lodash": "^4.2.0",
+ "symbol-observable": "^1.0.2"
+ }
+ },
"regenerate": {
"version": "1.4.0",
"resolved": "https://registry.npm.taobao.org/regenerate/download/regenerate-1.4.0.tgz",
@@ -12526,6 +12576,11 @@
"util.promisify": "~1.0.0"
}
},
+ "symbol-observable": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npm.taobao.org/symbol-observable/download/symbol-observable-1.2.0.tgz",
+ "integrity": "sha1-wiaIrtTqs83C3+rLtWFmBWCgCAQ="
+ },
"symbol-tree": {
"version": "3.2.4",
"resolved": "https://registry.npm.taobao.org/symbol-tree/download/symbol-tree-3.2.4.tgz",
diff --git a/package.json b/package.json
index 750cab4..0bc5de1 100644
--- a/package.json
+++ b/package.json
@@ -6,9 +6,12 @@
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
+ "prop-types": "^15.7.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
- "react-scripts": "3.4.1"
+ "react-redux": "^7.2.0",
+ "react-scripts": "3.4.1",
+ "redux": "^4.0.5"
},
"scripts": {
"start": "react-scripts start",
@@ -31,5 +34,8 @@
"last 1 safari version"
]
},
- "homepage": "./"
+ "homepage": "./",
+ "devDependencies": {
+ "redux-devtools": "^3.5.0"
+ }
}
diff --git a/src/App.js b/src/App.js
deleted file mode 100644
index e52f668..0000000
--- a/src/App.js
+++ /dev/null
@@ -1,18 +0,0 @@
-import React from 'react';
-import './App.css';
-import Layout from './containers/Layout'
-import Qrcode from "./components/Qrcode";
-
-function App() {
- return (
-
-
-
- );
-}
-
-export default App;
diff --git a/src/App.test.js b/src/App.test.js
deleted file mode 100644
index 4db7ebc..0000000
--- a/src/App.test.js
+++ /dev/null
@@ -1,9 +0,0 @@
-import React from 'react';
-import { render } from '@testing-library/react';
-import App from './App';
-
-test('renders learn react link', () => {
- const { getByText } = render();
- const linkElement = getByText(/learn react/i);
- expect(linkElement).toBeInTheDocument();
-});
diff --git a/src/components/Footer.js b/src/components/Footer.js
deleted file mode 100644
index 69e2ed8..0000000
--- a/src/components/Footer.js
+++ /dev/null
@@ -1,20 +0,0 @@
-import React from "react";
-import './Qrcode.css';
-
-const currentYear = new Date().getFullYear();
-
-class Footer extends React.Component {
- render() {
- return (
-
-
-
-
Copyright © {currentYear} QRBTF. 保留所有权利。
-
-
-
- );
- }
-}
-
-export default Footer
diff --git a/src/components/InputInfo.js b/src/components/InputInfo.js
new file mode 100644
index 0000000..ace1ba2
--- /dev/null
+++ b/src/components/InputInfo.js
@@ -0,0 +1,22 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+
+const InputInfo = ({ onChange, onBlur, onKeyPress }) => (
+
+
+
+)
+
+InputInfo.propTypes = {
+ onChange: PropTypes.func.isRequired,
+ onBlur: PropTypes.func.isRequired,
+ onKeyPress: PropTypes.func.isRequired
+}
+
+export default InputInfo
diff --git a/src/components/Qrcode.js b/src/components/Qrcode.js
index 37b263c..4ef7357 100644
--- a/src/components/Qrcode.js
+++ b/src/components/Qrcode.js
@@ -8,7 +8,7 @@ import {isWeiXin} from "../utils/util";
import './Qrcode.css';
import logo from '../qrbtf-logo.svg';
-import Footer from "./Footer";
+import Footer from "./footer/Footer";
import QrItem from "./QrItem";
import QrRendererBase from "./QrRendererBase";
import QrRendererRound from "./QrRendererRound";
@@ -17,11 +17,6 @@ import QrRendererBlank from "./QrRendererBlank";
import QrRendererRandRect from "./QrRendererRandRect";
import QrRendererDSJ from "./QrRendererDSJ";
-const logoStyle = {
- background: `url(${logo})`,
- backgroundRepeat: 'no-repeat',
- backgroundPosition: 'left'
-};
const styleList = [
{value: "A1", renderer: QrRendererBase},
@@ -150,12 +145,8 @@ class Qrcode extends React.Component {
render() {
return (
-
-
-
);
}
}
diff --git a/src/App.css b/src/components/app/App.css
similarity index 100%
rename from src/App.css
rename to src/components/app/App.css
diff --git a/src/components/app/App.js b/src/components/app/App.js
new file mode 100644
index 0000000..9042a7a
--- /dev/null
+++ b/src/components/app/App.js
@@ -0,0 +1,21 @@
+import React from 'react';
+import './App.css';
+import '../Qrcode.css';
+import Footer from "../footer/Footer";
+import Header from "../header/Header";
+
+function App() {
+ return (
+
+ );
+}
+
+export default App;
diff --git a/src/components/footer/Footer.js b/src/components/footer/Footer.js
new file mode 100644
index 0000000..c2272d5
--- /dev/null
+++ b/src/components/footer/Footer.js
@@ -0,0 +1,32 @@
+import React from "react";
+import '../Qrcode.css';
+
+const currentYear = new Date().getFullYear();
+
+const Footer = () => (
+
+
+
+
+ Copyright © {currentYear} QRBTF. 保留所有权利。
+
+
+
+
+)
+
+export default Footer
diff --git a/src/components/header/Header.js b/src/components/header/Header.js
new file mode 100644
index 0000000..9ca7f78
--- /dev/null
+++ b/src/components/header/Header.js
@@ -0,0 +1,20 @@
+import React from "react";
+import '../Qrcode.css';
+import logo from "../../qrbtf-logo.svg";
+
+const logoStyle = {
+ background: `url(${logo})`,
+ backgroundRepeat: 'no-repeat',
+ backgroundPosition: 'left'
+};
+
+const Header = () => (
+
+)
+
+export default Header
diff --git a/src/containers/Layout.css b/src/containers/Layout.css
deleted file mode 100644
index 573cf55..0000000
--- a/src/containers/Layout.css
+++ /dev/null
@@ -1,4 +0,0 @@
-.Layout {
- margin: 0;
- padding: 0;
-}
\ No newline at end of file
diff --git a/src/containers/Layout.js b/src/containers/Layout.js
deleted file mode 100644
index da72fc9..0000000
--- a/src/containers/Layout.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import React from "react";
-import './Layout.css'
-
-const Layout = (props) => {
- return (
-
- {props.children}
-
- );
-}
-
-export default Layout;
\ No newline at end of file
diff --git a/src/index.js b/src/index.js
index f5185c1..9c2ed28 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,12 +1,19 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
-import App from './App';
+import App from './components/app/App';
import * as serviceWorker from './serviceWorker';
+import { Provider } from 'react-redux';
+import rootReducer from './reducers';
+import {createStore} from "redux";
+
+const store = createStore(rootReducer);
ReactDOM.render(
-
+
+
+
,
document.getElementById('root')
);
diff --git a/src/reducers/index.js b/src/reducers/index.js
new file mode 100644
index 0000000..e69de29
From 4ea5215f4c4eb89f92b7d6493ad937df3a8253b8 Mon Sep 17 00:00:00 2001
From: CPunisher <1343316114@qq.com>
Date: Wed, 6 May 2020 23:59:56 +0800
Subject: [PATCH 2/7] Basic QRcode Generation
---
src/actions/index.js | 14 +++
src/components/InputInfo.js | 22 ----
src/components/QrItem.js | 41 --------
src/components/Qrcode.js | 117 +++-------------------
src/components/app/App.js | 7 +-
src/components/app/PartInput.js | 11 ++
src/components/app/PartMore.js | 20 ++++
src/components/app/PartStyles.js | 17 ++++
src/components/download/DownloadButton.js | 16 +++
src/components/link/LinkButton.js | 16 +++
src/components/renderer/RendererBase.js | 30 ++++++
src/components/renderer/RendererBlank.js | 13 +++
src/components/style/Style.js | 30 ++++++
src/components/style/StyleList.js | 26 +++++
src/containers/InputText.js | 16 +++
src/containers/Renderer.js | 14 +++
src/containers/StyleListViewer.js | 36 +++++++
src/reducers/index.js | 26 +++++
18 files changed, 306 insertions(+), 166 deletions(-)
create mode 100644 src/actions/index.js
delete mode 100644 src/components/InputInfo.js
delete mode 100644 src/components/QrItem.js
create mode 100644 src/components/app/PartInput.js
create mode 100644 src/components/app/PartMore.js
create mode 100644 src/components/app/PartStyles.js
create mode 100644 src/components/download/DownloadButton.js
create mode 100644 src/components/link/LinkButton.js
create mode 100644 src/components/renderer/RendererBase.js
create mode 100644 src/components/renderer/RendererBlank.js
create mode 100644 src/components/style/Style.js
create mode 100644 src/components/style/StyleList.js
create mode 100644 src/containers/InputText.js
create mode 100644 src/containers/Renderer.js
create mode 100644 src/containers/StyleListViewer.js
diff --git a/src/actions/index.js b/src/actions/index.js
new file mode 100644
index 0000000..c40b127
--- /dev/null
+++ b/src/actions/index.js
@@ -0,0 +1,14 @@
+export const actionTypes = {
+ GENERATE_QR_INFO: 'GENERATE_QR_INFO',
+ CHANGE_STYLE: 'CHANGE_STYLE'
+}
+
+export const genQRInfo = text => ({
+ type: actionTypes.GENERATE_QR_INFO,
+ text
+})
+
+export const changeStyle = index => ({
+ type: actionTypes.CHANGE_STYLE,
+ index
+})
diff --git a/src/components/InputInfo.js b/src/components/InputInfo.js
deleted file mode 100644
index ace1ba2..0000000
--- a/src/components/InputInfo.js
+++ /dev/null
@@ -1,22 +0,0 @@
-import React from 'react';
-import PropTypes from 'prop-types';
-
-const InputInfo = ({ onChange, onBlur, onKeyPress }) => (
-
-
-
-)
-
-InputInfo.propTypes = {
- onChange: PropTypes.func.isRequired,
- onBlur: PropTypes.func.isRequired,
- onKeyPress: PropTypes.func.isRequired
-}
-
-export default InputInfo
diff --git a/src/components/QrItem.js b/src/components/QrItem.js
deleted file mode 100644
index 944117a..0000000
--- a/src/components/QrItem.js
+++ /dev/null
@@ -1,41 +0,0 @@
-import React from "react";
-import './Qrcode.css'
-
-function calClassName(props) {
- if (props.selected === true) return 'Qr-item Qr-item-selected';
- return 'Qr-item';
-}
-
-export default class QrItem extends React.Component {
-
- constructor(props) {
- super(props);
- }
-
- componentDidMount() {
- this.forceUpdate()
- }
-
- handleClick = (e) => {
- this.props.onSelected(this.props.index);
- }
-
- shouldComponentUpdate(nextProps, nextState, nextContext) {
- return (nextProps.selected || this.props.selected) && (this.props.text == nextProps.text || this.props.text.length == 0)
- }
-
- render() {
- return (
-
-
-
- {this.props.renderer}
-
-
-
- {this.props.value}
-
-
- );
- }
-}
diff --git a/src/components/Qrcode.js b/src/components/Qrcode.js
index 4ef7357..39a8f74 100644
--- a/src/components/Qrcode.js
+++ b/src/components/Qrcode.js
@@ -145,108 +145,21 @@ class Qrcode extends React.Component {
render() {
return (
-
-
- this.setState({text: e.target.value})}
- onBlur={this.handleCreate}
- onKeyPress={(e) => {if(e.key === 'Enter') this.handleCreate(e)}}
- />
-
-
-
-
-
- {
- styleList.map((style, index) => {
- return this.setState({selectedIndex: index})}
- />
- })
- }
-
-
-
-
-
-
-
-
-
-
- 容错率 |
-
-
- |
-
- {this.renderAdjustment()}
-
-
-
-
-
-
-
-
Downloads
-
下载二维码 — {styleList[this.state.selectedIndex].value}
-
-
-
-
-
+
+ //
+ //
+ //
Downloads
+ //
下载二维码 — {styleList[this.state.selectedIndex].value}
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
);
}
}
diff --git a/src/components/app/App.js b/src/components/app/App.js
index 9042a7a..66b14ba 100644
--- a/src/components/app/App.js
+++ b/src/components/app/App.js
@@ -3,6 +3,9 @@ import './App.css';
import '../Qrcode.css';
import Footer from "../footer/Footer";
import Header from "../header/Header";
+import PartInput from "./PartInput";
+import PartStyles from "./PartStyles";
+import PartMore from "./PartMore";
function App() {
return (
@@ -10,7 +13,9 @@ function App() {
diff --git a/src/components/app/PartInput.js b/src/components/app/PartInput.js
new file mode 100644
index 0000000..25d0f8f
--- /dev/null
+++ b/src/components/app/PartInput.js
@@ -0,0 +1,11 @@
+import React from 'react';
+import './App.css';
+import InputText from "../../containers/InputText";
+
+const PartInput = () => (
+
+
+
+)
+
+export default PartInput;
diff --git a/src/components/app/PartMore.js b/src/components/app/PartMore.js
new file mode 100644
index 0000000..e88ac14
--- /dev/null
+++ b/src/components/app/PartMore.js
@@ -0,0 +1,20 @@
+import React from 'react';
+import './App.css';
+import LinkButton from "../link/LinkButton";
+
+const PartMore = () => (
+
+)
+
+export default PartMore;
diff --git a/src/components/app/PartStyles.js b/src/components/app/PartStyles.js
new file mode 100644
index 0000000..f58c5df
--- /dev/null
+++ b/src/components/app/PartStyles.js
@@ -0,0 +1,17 @@
+import React from 'react';
+import './App.css';
+import StyleListViewer from "../../containers/StyleListViewer";
+
+const PartStyles = () => (
+
+)
+
+export default PartStyles;
diff --git a/src/components/download/DownloadButton.js b/src/components/download/DownloadButton.js
new file mode 100644
index 0000000..ce510e9
--- /dev/null
+++ b/src/components/download/DownloadButton.js
@@ -0,0 +1,16 @@
+import React from "react";
+import PropTypes from 'prop-types'
+import '../Qrcode.css';
+
+const DownloadButton = ({ onClick, value }) => (
+
+)
+
+DownloadButton.propTypes = {
+ onClick: PropTypes.func.isRequired,
+ value: PropTypes.string.isRequired
+}
+
+export default DownloadButton;
diff --git a/src/components/link/LinkButton.js b/src/components/link/LinkButton.js
new file mode 100644
index 0000000..cff0741
--- /dev/null
+++ b/src/components/link/LinkButton.js
@@ -0,0 +1,16 @@
+import React from "react";
+import PropTypes from 'prop-types'
+import '../Qrcode.css';
+
+const LinkButton = ({ href, value }) => (
+
+
+
+)
+
+LinkButton.propTypes = {
+ href: PropTypes.string.isRequired,
+ value: PropTypes.string.isRequired
+}
+
+export default LinkButton;
diff --git a/src/components/renderer/RendererBase.js b/src/components/renderer/RendererBase.js
new file mode 100644
index 0000000..6a8cdf3
--- /dev/null
+++ b/src/components/renderer/RendererBase.js
@@ -0,0 +1,30 @@
+import React from "react";
+import PropTypes from 'prop-types';
+import {defaultRenderer} from "../../utils/util";
+
+function listPoints(qrcode) {
+ if (!qrcode) return[]
+
+ const nCount = qrcode.getModuleCount();
+ const pointList = []
+ let id = 0
+
+ for (let x = 0; x < nCount; x++) {
+ for (let y = 0; y < nCount; y++) {
+ if (qrcode.isDark(x, y)) {
+ pointList.push()
+ }
+ }
+ }
+ return pointList;
+}
+
+const RendererBase = ({ qrcode }) => (
+ defaultRenderer(qrcode, listPoints(qrcode))
+);
+
+RendererBase.prototype = {
+ qrcode: PropTypes.object.isRequired
+}
+
+export default RendererBase;
diff --git a/src/components/renderer/RendererBlank.js b/src/components/renderer/RendererBlank.js
new file mode 100644
index 0000000..ebcfa51
--- /dev/null
+++ b/src/components/renderer/RendererBlank.js
@@ -0,0 +1,13 @@
+import React from "react";
+import PropTypes from 'prop-types';
+import {defaultRenderer} from "../../utils/util";
+
+const RendererBlank = ({ qrcode }) => (
+ defaultRenderer(qrcode, [])
+);
+
+RendererBlank.prototype = {
+ qrcode: PropTypes.object.isRequired
+}
+
+export default RendererBlank;
diff --git a/src/components/style/Style.js b/src/components/style/Style.js
new file mode 100644
index 0000000..83b705e
--- /dev/null
+++ b/src/components/style/Style.js
@@ -0,0 +1,30 @@
+import React from 'react'
+import PropTypes from 'prop-types'
+
+function calClassName(selected) {
+ if (selected === true) return 'Qr-item Qr-item-selected';
+ return 'Qr-item';
+}
+
+const Style = ({ value, renderer, selected, onClick }) => (
+
+);
+
+Style.propTypes = {
+ value: PropTypes.string.isRequired,
+ renderer: PropTypes.object.isRequired,
+ selected: PropTypes.bool.isRequired,
+ onClick: PropTypes.func.isRequired
+}
+
+export default Style;
diff --git a/src/components/style/StyleList.js b/src/components/style/StyleList.js
new file mode 100644
index 0000000..de01b64
--- /dev/null
+++ b/src/components/style/StyleList.js
@@ -0,0 +1,26 @@
+import React from 'react'
+import PropTypes from 'prop-types'
+import Style from "./Style";
+
+const StyleList = ({ styles, onSelected }) => (
+
+ {styles.map((style, index) =>
+