export default class boxSdk { constructor(name) { this.name = name, //本游戏名字 this.api = 'https://xyxbox.duowan.com/' //接口域名 this.dataList = [], //数据列表 存放图标游戏图组合列表 this.currentGroup = {} //当前选中图标游戏组合 } showAdIcon(x, y, node) { let self = this wx.request({ url: `${self.api}hz/showAd`, data: {name:self.name}, success: function ({ data }) { let meta = data.data for(let i = 0 ; i < meta.length; i++) { meta[i].small_icon = meta[i].small_icon.replace(/http\:\/\//,'https://') } self.dataList = meta self.renderIcon(x,y,node) } }) } renderIcon(x,y,parent) { let self = this let index = (new Date()).getTime() % self.dataList.length self.currentGroup = self.dataList[index] let iconNode = parent.getChildByName("adIcon"); if(iconNode) { iconNode.destroy(); } wx.downloadFile({ url: self.currentGroup.small_icon, header: {}, filePath: '', success: function (ret) { var frame = new cc.SpriteFrame(ret.tempFilePath); var node = new cc.Node('adIcon'); var sp = node.addComponent(cc.Sprite); var btn = node.addComponent(cc.Button) sp.spriteFrame = frame node.parent = parent; node.x = x node.y = y // var widget = node.addComponent(cc.Widget) // console.log(widget) // widget.isAlignTop = true // widget.isAlignLeft = true // widget.left = x // widget.top = y btn.node.on(cc.Node.EventType.TOUCH_START, function () { wx.request({ url: `${self.api}hz/static?field=img`, data: { name: self.currentGroup.name }, success: () => { } }) if(self.currentGroup.app_id) { wx.navigateToMiniProgram({ appId: self.currentGroup.app_id, path: self.currentGroup.path, extraData: {}, success(){console.log('跳转成功')} }) }else { wx.previewImage({ urls: [self.currentGroup.big_image] }) } self.renderIcon(x,y,parent) }) } }) } openQrcode() { let self = this wx.request({ url: `${self.api}hz/common`, data: {}, success: ({ data }) => { wx.previewImage({ urls: [data.data.gzh_qr_code] }) } }) } oepnGameCenter() { wx.request({ url: `${self.api}hz/common`, data: {}, success: ({ data }) => { wx.previewImage({ urls: [data.data.hz_picture] }) } }) } initSdk(sceneId, path) { let gameName = this.name if (sceneId == 1012) { wx.request({ url: `${self.api}hz/static?field=qr`, data: { name: gameName }, success: () => { }, }) } } }