diff --git a/assets/comp/wallet/scripts/ui/QrNode.ts b/assets/comp/wallet/scripts/ui/QrNode.ts index c10ba2b..0211a31 100644 --- a/assets/comp/wallet/scripts/ui/QrNode.ts +++ b/assets/comp/wallet/scripts/ui/QrNode.ts @@ -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() { diff --git a/assets/comp/wallet/scripts/ui/WalletInfo.ts b/assets/comp/wallet/scripts/ui/WalletInfo.ts index e2c6f27..937eaf1 100644 --- a/assets/comp/wallet/scripts/ui/WalletInfo.ts +++ b/assets/comp/wallet/scripts/ui/WalletInfo.ts @@ -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}) } } diff --git a/assets/comp/wallet/scripts/ui/WalletMainPanel.ts b/assets/comp/wallet/scripts/ui/WalletMainPanel.ts index c21f285..465f6e6 100644 --- a/assets/comp/wallet/scripts/ui/WalletMainPanel.ts +++ b/assets/comp/wallet/scripts/ui/WalletMainPanel.ts @@ -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 } } diff --git a/assets/comp/wallet/scripts/ui/comp/QRCodeComp.ts b/assets/comp/wallet/scripts/ui/comp/QRCodeComp.ts index 4444408..ae6a276 100644 --- a/assets/comp/wallet/scripts/ui/comp/QRCodeComp.ts +++ b/assets/comp/wallet/scripts/ui/comp/QRCodeComp.ts @@ -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));