二维码界面增加二维码颜色参数的传递

This commit is contained in:
cebgcontract 2022-06-21 17:15:58 +08:00
parent 8d7930fd08
commit 6755744114
4 changed files with 18 additions and 12 deletions

View File

@ -1,4 +1,4 @@
import QRCodeComp from "./comp/QRCodeComp";
import QRCodeComp, { IQRCfg } from "./comp/QRCodeComp";
const {ccclass, property} = cc._decorator;
@ -7,8 +7,8 @@ export default class QrNode extends cc.Component {
@property(QRCodeComp)
qrComp: QRCodeComp = null
showQr(val: string) {
this.qrComp.renderQr(val)
showQr(data: IQRCfg) {
this.qrComp.renderQr(data)
}
hideMe() {

View File

@ -87,6 +87,6 @@ export default class WalletInfo extends WalletBase {
const chainId = this.wallet.currentChain.id
let qrUrl = `ethereum:${address}@${chainId}`
// this.showQr(qrUrl)
this.wallet.mainHandlers.emit(WALLET_SHOW_QR, qrUrl)
this.wallet.mainHandlers.emit(WALLET_SHOW_QR, {val: qrUrl})
}
}

View File

@ -1,6 +1,7 @@
import { WALLET_SHOW_QR } from "../common/WalletEvent";
import JCWallet from "../JCWallet";
import ChainTab from "./ChainTab";
import { IQRCfg } from "./comp/QRCodeComp";
import ListNode from "./ListNode";
import WalletBase from "./WallerBase";
@ -69,10 +70,10 @@ export default class WalletMainPanel extends WalletBase {
node.active = true
}
showQrNode(val: string) {
showQrNode(data: IQRCfg) {
const tag = 'qr-node'
const node = this.fetchNode(tag, this.qrPreb)
node.getComponent('QrNode').showQr(val)
node.getComponent('QrNode').showQr(data)
node.active = true
}
}

View File

@ -1,6 +1,11 @@
const {ccclass, property} = cc._decorator;
import { QR } from '../../lib/qrcode';
export interface IQRCfg{
val: string
lightColor?: cc.Color
deepColor?: cc.Color
}
@ccclass
export default class QRCodeComp extends cc.Component {
@ -20,13 +25,13 @@ export default class QRCodeComp extends cc.Component {
}
// update (dt) {}
renderQr(val: string) {
if (this.preVal === val) {
renderQr(data: IQRCfg) {
if (this.preVal === data.val) {
return
}
this.preVal = val
this.preVal = data.val
var ec_level = 'Q';
var arr = QR(val, ec_level);
var arr = QR(data.val, ec_level);
// [y][x]
var ctx = this.node.getComponent(cc.Graphics);
if (!ctx) {
@ -45,9 +50,9 @@ export default class QRCodeComp extends cc.Component {
for (var col = 0; col < countX; col++) {
// ctx.fillStyle = qrcode.isDark(row, col) ? options.foreground : options.background;
if (arr[row][col]) {
ctx.fillColor = cc.Color.BLACK;
ctx.fillColor = data.deepColor || this.deepColor;
} else {
ctx.fillColor = cc.Color.WHITE;
ctx.fillColor = data.lightColor || this.lightColor;
}
var w = (Math.ceil((col + 1) * tileW) - Math.floor(col * tileW));
var h = (Math.ceil((row + 1) * tileW) - Math.floor(row * tileW));