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

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; const {ccclass, property} = cc._decorator;
@ -7,8 +7,8 @@ export default class QrNode extends cc.Component {
@property(QRCodeComp) @property(QRCodeComp)
qrComp: QRCodeComp = null qrComp: QRCodeComp = null
showQr(val: string) { showQr(data: IQRCfg) {
this.qrComp.renderQr(val) this.qrComp.renderQr(data)
} }
hideMe() { hideMe() {

View File

@ -87,6 +87,6 @@ export default class WalletInfo extends WalletBase {
const chainId = this.wallet.currentChain.id const chainId = this.wallet.currentChain.id
let qrUrl = `ethereum:${address}@${chainId}` let qrUrl = `ethereum:${address}@${chainId}`
// this.showQr(qrUrl) // 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 { WALLET_SHOW_QR } from "../common/WalletEvent";
import JCWallet from "../JCWallet"; import JCWallet from "../JCWallet";
import ChainTab from "./ChainTab"; import ChainTab from "./ChainTab";
import { IQRCfg } from "./comp/QRCodeComp";
import ListNode from "./ListNode"; import ListNode from "./ListNode";
import WalletBase from "./WallerBase"; import WalletBase from "./WallerBase";
@ -69,10 +70,10 @@ export default class WalletMainPanel extends WalletBase {
node.active = true node.active = true
} }
showQrNode(val: string) { showQrNode(data: IQRCfg) {
const tag = 'qr-node' const tag = 'qr-node'
const node = this.fetchNode(tag, this.qrPreb) const node = this.fetchNode(tag, this.qrPreb)
node.getComponent('QrNode').showQr(val) node.getComponent('QrNode').showQr(data)
node.active = true node.active = true
} }
} }

View File

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