let webapi = require('./utils/webapi'); let clipboard = require('./utils/clipboard'); cc.Class({ extends: cc.Component, properties: { closeBtn: { default: null, type: cc.Node }, shareBtn: { default: null, type: cc.Node }, urlBtn: { default: null, type: cc.Node }, urlLabel: { default: null, type: cc.Label }, page: '' }, // LIFE-CYCLE CALLBACKS: onLoad () { let self = this; this.closeBtn.on('click', function () { self.node.removeFromParent(true); }); webapi.getShareUrl() .then(rep => { if (rep.errcode === 0) { self.urlLabel.string = rep.link; self.page = rep.link; } }) .catch(err => { console.log('error get share url'); }); this.shareBtn.on('click', function () { let result = clipboard.webCopyString(self.page); if (result) { alert('链接已复制至剪贴板'); } }) } });