// Learn cc.Class: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html // Learn Attribute: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html cc.Class({ extends: cc.Component, properties: { myInviteValue: { default: null, type: cc.Label // optional, default is typeof default }, parentInviteValue: { default: null, type: cc.Label // optional, default is typeof default }, inputInviteValue:'', }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, start() { this.myInviteValue.string = GlobalD.Dapp.UserInfo.invite_code; if (GlobalD.Dapp.UserInfo.parent) { this.parentInviteValue.string = GlobalD.Dapp.UserInfo.parent; } }, inputInvite(value,e){ console.log(value); this.inputInviteValue = value; }, onBindInviteInfo() { console.log('绑定的inputInviteValue:'+ this.inputInviteValue); GlobalD.dapp.bindParent(this.inputInviteValue).then(( err, res)=>{ if (err === null) { // 返回成功,见下面消息体 console.log(res) } else { //TODO 服务错误 console.log(err) } }) }, onClose(){ this.node.active = false; }, webCopyString(){ console.log('复制'); var input = GlobalD.Dapp.UserInfo.invite_code + ''; const el = document.createElement('textarea'); el.value = input; el.setAttribute('readonly', ''); el.style.contain = 'strict'; el.style.position = 'absolute'; el.style.left = '-9999px'; el.style.fontSize = '12pt'; // Prevent zooming on iOS const selection = getSelection(); var originalRange = false; if (selection.rangeCount > 0) { originalRange = selection.getRangeAt(0); } document.body.appendChild(el); el.select(); el.selectionStart = 0; el.selectionEnd = input.length; var success = false; try { success = document.execCommand('copy'); } catch (err) {} document.body.removeChild(el); if (originalRange) { selection.removeAllRanges(); selection.addRange(originalRange); } return success; }, // update (dt) {}, });