Merge branch 'dev-redux' of https://github.com/ciaochaos/qrbtf into dev-redux

This commit is contained in:
CPunisher 2020-05-13 17:45:30 +08:00
commit 552e0b4de6
6 changed files with 286 additions and 8 deletions

37
.github/workflows/nodejs-dev.yml vendored Normal file
View File

@ -0,0 +1,37 @@
name: Continuous Integration Dev #action名称
on:
push:
branches:
- dev-redux
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout dev-redux
uses: actions/checkout@v2
with:
ref: dev-redux
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: "12.x"
- name: Build project
run: yarn && yarn build
env:
CI: false
- name: Authenticate
run: sudo chmod 775 ./build/ && ls
- name: Upload COS
uses: ciaochaos/tencent-cos-action@master
with:
args: delete -r -f / && upload -r ./build/ /
secret_id: ${{ secrets.SECRET_ID }}
secret_key: ${{ secrets.SECRET_KEY }}
bucket: ${{ secrets.BUCKET_DEV }}
region: ap-shanghai

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptLibraryMappings">
<file url="file://$PROJECT_DIR$" libraries="{qrbtf/node_modules}" />
<file url="PROJECT" libraries="{qrbtf/node_modules}" />
</component>
</project>

View File

@ -0,0 +1,85 @@
import React from "react";
import './Qrcode.css'
import {getTypeTable, QRPointType} from "../utils/qrcodeHandler";
import {defaultRenderer, defaultViewBox, rand} from "../utils/util";
function listPoint(props) {
if (!props.qrcode) return []
const qrcode = props.qrcode;
const nCount = qrcode.getModuleCount();
const typeTable = getTypeTable(qrcode);
const pointList = new Array(nCount);
let size = 1.001;
let size2 = 1.001;
let height = props.params[0];
let height2 = props.params[1];
let id = 0;
const vw = [3, -3];
const vh = [3, -3];
const X = [-Math.sqrt(3)/2, 1/2];
const Y = [ Math.sqrt(3)/2, 1/2];
const Z = [0, 0];
const matrixString = 'matrix(' + String(X[0]) + ', ' + String(X[1]) + ', ' + String(Y[0]) + ', ' + String(Y[1]) + ', ' + String(Z[0]) + ', ' + String(Z[1]) + ')'
if (height <= 0) height = 1.0;
if (height2 <= 0) height2 = 1.0;
for (let x = 0; x < nCount; x++) {
for (let y = 0; y < nCount; y++) {
if (qrcode.isDark(x, y) == false) continue;
else if (typeTable[x][y] == QRPointType.POS_OTHER || typeTable[x][y] == QRPointType.POS_CENTER) {
pointList.push(<rect width={size2} height={size2} key={id++} fill="#FF7F89" x={x + (1 - size2)/2} y={y + (1 - size2)/2} transform={matrixString}/>);
pointList.push(<rect width={height2} height={size2} key={id++} fill="#FFEBF3" x={0} y={0} transform={matrixString+'translate('+String(x + (1 - size2)/2 + size2)+','+String(y + (1 - size2)/2)+') '+'skewY(45) '}/>);
pointList.push(<rect width={size2} height={height2} key={id++} fill="#FFD7D9" x={0} y={0} transform={matrixString+'translate('+String(x + (1 - size2)/2)+','+String(y + size2 + (1 - size2)/2)+') '+'skewX(45) '}/>);
}
else {
pointList.push(<rect width={size} height={size} key={id++} fill="#FF7F89" x={x + (1 - size)/2} y={y + (1 - size)/2} transform={matrixString}/>);
pointList.push(<rect width={height} height={size} key={id++} fill="#FFEBF3" x={0} y={0} transform={matrixString+'translate('+String(x + (1 - size)/2 + size)+','+String(y + (1 - size)/2)+') '+'skewY(45) '}/>);
pointList.push(<rect width={size} height={height} key={id++} fill="#FFD7D9" x={0} y={0} transform={matrixString+'translate('+String(x + (1 - size)/2)+','+String(y + size + (1 - size)/2)+') '+'skewX(45) '}/>);
}
}
}
return pointList;
}
function viewBox(qrcode) {
if (!qrcode) return '0 0 0 0';
const nCount = qrcode.getModuleCount();
return String(-nCount) + ' ' + String(-nCount / 2) + ' ' + String(nCount * 2) + ' ' + String(nCount * 2);
}
export default class QrRenderer25D extends React.Component {
constructor(props) {
super(props);
if (this.props.setParamInfo) {
this.props.setParamInfo([
{
key: '柱体高度',
default: 0.5,
},
{
key: '定位点柱体高度',
default: 0.5,
},
]
);
}
}
render() {
return (
<svg className="Qr-item-svg" width="100%" height="100%" viewBox={viewBox(this.props.qrcode)} fill="white"
xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink">
{listPoint(this.props)}
</svg>
);
}
}

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,5 @@
import {increaseDownloadData} from "../api/db";
const svgHead = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n " + const svgHead = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n " +
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n" "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"
@ -5,21 +7,23 @@ export function isChrome() {
return navigator.userAgent.toLowerCase().indexOf('chrome') > -1; return navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
} }
export function saveSvg(filename, content) { export function saveSvg(value, content) {
let htmlContent = [svgHead + content] let htmlContent = [svgHead + content]
let bl = new Blob(htmlContent, {type: "image/svg+xml"}) let bl = new Blob(htmlContent, {type: "image/svg+xml"})
let a = document.createElement("a") let a = document.createElement("a")
filename = "QRcode_" + filename + ".svg" let filename = "QRcode_" + value + ".svg"
a.href = URL.createObjectURL(bl) a.href = URL.createObjectURL(bl)
a.download = filename a.download = filename
a.hidden = true a.hidden = true
a.click() a.click()
increaseDownloadData(value, new Date().toString())
} }
export function saveImg(filename, content, width, height) { export function saveImg(value, content, width, height) {
// Finish creating downloadable data // Finish creating downloadable data
filename = "QRcode_" + filename + ".jpg"; let filename = "QRcode_" + value + ".jpg";
const wrap = document.createElement('div'); const wrap = document.createElement('div');
wrap.innerHTML = content; wrap.innerHTML = content;
@ -59,4 +63,6 @@ export function saveImg(filename, content, width, height) {
}; };
img.setAttribute('src', 'data:image/svg+xml;base64,' + btoa(svgData)); img.setAttribute('src', 'data:image/svg+xml;base64,' + btoa(svgData));
increaseDownloadData(value, new Date().toString())
} }

View File

@ -62,8 +62,9 @@ export function getTypeTable(qrcode) {
for (let i = 0; i < PD.length; i++) { for (let i = 0; i < PD.length; i++) {
typeTable[PD[i][0]][PD[i][1]] = QRPointType.POS_CENTER typeTable[PD[i][0]][PD[i][1]] = QRPointType.POS_CENTER
for (let r = -3; r <= 3; r++) { for (let r = -4; r <= 4; r++) {
for (let c = -3; c <= 3; c++) { for (let c = -4; c <= 4; c++) {
if (PD[i][0] + r >= 0 && PD[i][0] + r < nCount && PD[i][1] + c >=0 && PD[i][1] + c < nCount)
if (!(r == 0 && c == 0)) if (!(r == 0 && c == 0))
typeTable[PD[i][0] + r][PD[i][1] + c] = QRPointType.POS_OTHER; typeTable[PD[i][0] + r][PD[i][1] + c] = QRPointType.POS_OTHER;
} }