code arrangement
This commit is contained in:
parent
c7fabf6581
commit
555ef5bd04
|
@ -1,7 +1,7 @@
|
||||||
import React, {useState} from 'react';
|
import React, {useState} from 'react';
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import {isWeiXin} from "../../utils/util";
|
import {isWeiXin} from "../../utils/navigatorUtils";
|
||||||
|
|
||||||
const WxMessage = () => {
|
const WxMessage = () => {
|
||||||
if (isWeiXin()) {
|
if (isWeiXin()) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React, {useEffect, useState} from 'react';
|
import React, {useEffect, useState} from 'react';
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import StyleListViewer from "../../containers/style/StyleListViewer";
|
import StyleListViewer from "../../containers/style/StyleListViewer";
|
||||||
import {isPC} from "../../utils/util";
|
import {isPC} from "../../utils/navigatorUtils";
|
||||||
|
|
||||||
const PartStyles = ({ setParamInfo }) => {
|
const PartStyles = ({ setParamInfo }) => {
|
||||||
const [loaded, setLoaded] = useState(false);
|
const [loaded, setLoaded] = useState(false);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useEffect } from "react";
|
import React from "react";
|
||||||
import {ParamTypes} from "../../constant/ParamTypes";
|
import {ParamTypes} from "../../constant/ParamTypes";
|
||||||
import {getTypeTable, QRPointType} from "../../utils/qrcodeHandler";
|
import {getTypeTable, QRPointType} from "../../utils/qrcodeHandler";
|
||||||
import {createRenderer} from "../style/Renderer";
|
import {createRenderer} from "../style/Renderer";
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useEffect } from "react";
|
import React from "react";
|
||||||
import {defaultViewBox, rand} from "../../utils/util";
|
import {rand} from "../../utils/util";
|
||||||
import {createRenderer} from "../style/Renderer";
|
import {createRenderer} from "../style/Renderer";
|
||||||
|
|
||||||
function listPoints(qrcode, params) {
|
function listPoints(qrcode, params) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, {useEffect, useMemo, useState} from "react";
|
import React, {useEffect, useMemo, useState} from "react";
|
||||||
import {gamma} from "../../utils/util";
|
import {gamma} from "../../utils/imageUtils";
|
||||||
import {ParamTypes} from "../../constant/ParamTypes";
|
import {ParamTypes} from "../../constant/ParamTypes";
|
||||||
import {getTypeTable, QRPointType} from "../../utils/qrcodeHandler";
|
import {getTypeTable, QRPointType} from "../../utils/qrcodeHandler";
|
||||||
import {defaultResImage} from "../../constant/References";
|
import {defaultResImage} from "../../constant/References";
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {connect} from 'react-redux';
|
import {connect} from 'react-redux';
|
||||||
import {genQRInfo} from "../../actions";
|
import {genQRInfo} from "../../actions";
|
||||||
import React, {useRef} from "react";
|
import React, {useRef} from "react";
|
||||||
import {isPicture} from "../../utils/util";
|
import {isPicture} from "../../utils/imageUtils";
|
||||||
import {decodeData} from "../../utils/qrcodeHandler";
|
import {decodeData} from "../../utils/qrcodeHandler";
|
||||||
|
|
||||||
const InputText = ({dispatch}) => {
|
const InputText = ({dispatch}) => {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import {changeParam} from "../../actions";
|
import {changeParam} from "../../actions";
|
||||||
import ParamUpload from "../../components/param/ParamUpload";
|
import ParamUpload from "../../components/param/ParamUpload";
|
||||||
import {isPicture, toBase64} from "../../utils/util";
|
import {isPicture, toBase64} from "../../utils/imageUtils";
|
||||||
|
|
||||||
const mapStateToProps = (state, ownProps) => ({
|
const mapStateToProps = (state, ownProps) => ({
|
||||||
rendererIndex: ownProps.rendererIndex,
|
rendererIndex: ownProps.rendererIndex,
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
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"
|
||||||
|
|
||||||
export function isChrome() {
|
|
||||||
return navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function saveSvg(value, 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"})
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
const fileTypes =[
|
||||||
|
'image/jpeg',
|
||||||
|
'image/pjpeg',
|
||||||
|
'image/png'
|
||||||
|
]
|
||||||
|
|
||||||
|
export function isPicture(file) {
|
||||||
|
return fileTypes.includes(file.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toBase64(file, width, height) {
|
||||||
|
let canvas = document.createElement('canvas');
|
||||||
|
let ctx = canvas.getContext('2d');
|
||||||
|
let img = document.createElement('img');
|
||||||
|
|
||||||
|
canvas.setAttribute('width', width);
|
||||||
|
canvas.setAttribute('height', height);
|
||||||
|
img.setAttribute('src', URL.createObjectURL(file));
|
||||||
|
|
||||||
|
return new Promise(resolve => {
|
||||||
|
img.onload = () => {
|
||||||
|
ctx.fillStyle = 'white'
|
||||||
|
ctx.fillRect(0, 0, width, height)
|
||||||
|
ctx.drawImage(img, 0, 0, width, height);
|
||||||
|
|
||||||
|
resolve(canvas.toDataURL(file.type, 0.9));
|
||||||
|
};
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function gamma(r, g, b) {
|
||||||
|
return Math.pow((Math.pow(r, 2.2) + Math.pow(1.5 * g, 2.2) + Math.pow(0.6 * b, 2.2)) / (1 + Math.pow(1.5, 2.2) + Math.pow(0.6, 2.2)), 1/2.2)
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
export function isWeiXin(){
|
||||||
|
const ua = window.navigator.userAgent.toLowerCase();
|
||||||
|
if(ua.match(/MicroMessenger/i) == 'micromessenger'){
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isPC() {
|
||||||
|
const userAgentInfo = navigator.userAgent;
|
||||||
|
const Agents = ["Android", "iPhone",
|
||||||
|
"SymbianOS", "Windows Phone",
|
||||||
|
"iPad", "iPod"];
|
||||||
|
let flag = true;
|
||||||
|
for (let v = 0; v < Agents.length; v++) {
|
||||||
|
if (userAgentInfo.indexOf(Agents[v]) > 0) {
|
||||||
|
flag = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isChrome() {
|
||||||
|
return navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
|
||||||
|
}
|
|
@ -1,17 +1,6 @@
|
||||||
import {ParamTypes} from "../constant/ParamTypes";
|
import {ParamTypes} from "../constant/ParamTypes";
|
||||||
let seed = 0;
|
let seed = 0;
|
||||||
|
|
||||||
const fileTypes =[
|
|
||||||
'image/jpeg',
|
|
||||||
'image/pjpeg',
|
|
||||||
'image/png'
|
|
||||||
]
|
|
||||||
|
|
||||||
export function isPicture(file) {
|
|
||||||
return fileTypes.includes(file.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export function srand(sd) {
|
export function srand(sd) {
|
||||||
seed = sd;
|
seed = sd;
|
||||||
}
|
}
|
||||||
|
@ -21,47 +10,12 @@ export function rand(min, max) {
|
||||||
return min + (seed / 233280.0) * (max - min);
|
return min + (seed / 233280.0) * (max - min);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function randRGB(minR, maxR, minG, maxG, minB, maxB) {
|
|
||||||
return 'rgb(' + parseInt(minR, maxR) + ',' + parseInt(minG, maxG) + ',' + parseInt(minB, maxB) + ')';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function defaultViewBox(qrcode) {
|
|
||||||
if (!qrcode) return '0 0 0 0';
|
|
||||||
|
|
||||||
const nCount = qrcode.getModuleCount();
|
|
||||||
return String(-nCount / 5) + ' ' + String(-nCount / 5) + ' ' + String(nCount + nCount / 5 * 2) + ' ' + String(nCount + nCount / 5 * 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function fillEmptyWith(arr, value) {
|
export function fillEmptyWith(arr, value) {
|
||||||
for (let i = 0; i < arr.length; i++)
|
for (let i = 0; i < arr.length; i++)
|
||||||
if (!arr[i]) arr[i] = value;
|
if (!arr[i]) arr[i] = value;
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isWeiXin(){
|
|
||||||
const ua = window.navigator.userAgent.toLowerCase();
|
|
||||||
if(ua.match(/MicroMessenger/i) == 'micromessenger'){
|
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isPC() {
|
|
||||||
const userAgentInfo = navigator.userAgent;
|
|
||||||
const Agents = ["Android", "iPhone",
|
|
||||||
"SymbianOS", "Windows Phone",
|
|
||||||
"iPad", "iPod"];
|
|
||||||
let flag = true;
|
|
||||||
for (let v = 0; v < Agents.length; v++) {
|
|
||||||
if (userAgentInfo.indexOf(Agents[v]) > 0) {
|
|
||||||
flag = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getParamDetailedValue(item, paramValue) {
|
export function getParamDetailedValue(item, paramValue) {
|
||||||
if (item.type == ParamTypes.SELECTOR) return item.choices[paramValue];
|
if (item.type == ParamTypes.SELECTOR) return item.choices[paramValue];
|
||||||
return paramValue;
|
return paramValue;
|
||||||
|
@ -71,10 +25,6 @@ export function outerHtml(selectedIndex) {
|
||||||
return document.getElementsByClassName('Qr-item-svg')[selectedIndex].outerHTML;
|
return document.getElementsByClassName('Qr-item-svg')[selectedIndex].outerHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function gamma(r, g, b) {
|
|
||||||
return Math.pow((Math.pow(r, 2.2) + Math.pow(1.5 * g, 2.2) + Math.pow(0.6 * b, 2.2)) / (1 + Math.pow(1.5, 2.2) + Math.pow(0.6, 2.2)), 1/2.2)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getExactValue(value, defaultValue) {
|
export function getExactValue(value, defaultValue) {
|
||||||
if (typeof value != "string") return value;
|
if (typeof value != "string") return value;
|
||||||
if (value.length <= 0) value = defaultValue;
|
if (value.length <= 0) value = defaultValue;
|
||||||
|
@ -89,22 +39,3 @@ export function extend(target, options) {
|
||||||
return target
|
return target
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toBase64(file, width, height) {
|
|
||||||
let canvas = document.createElement('canvas');
|
|
||||||
let ctx = canvas.getContext('2d');
|
|
||||||
let img = document.createElement('img');
|
|
||||||
|
|
||||||
canvas.setAttribute('width', width);
|
|
||||||
canvas.setAttribute('height', height);
|
|
||||||
img.setAttribute('src', URL.createObjectURL(file));
|
|
||||||
|
|
||||||
return new Promise(resolve => {
|
|
||||||
img.onload = () => {
|
|
||||||
ctx.fillStyle = 'white'
|
|
||||||
ctx.fillRect(0, 0, width, height)
|
|
||||||
ctx.drawImage(img, 0, 0, width, height);
|
|
||||||
|
|
||||||
resolve(canvas.toDataURL(file.type, 0.9));
|
|
||||||
};
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue