123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- export default class boxSdk {
- constructor(name) {
- // this.cache = wx.getStorageSync('sdkStorage')
- this.heziUrl = '',
- this.name = name,
- this.api = 'https://www.27l.com/'
- this.img = null
- }
- showAdIcon(x, y, node) {
- let self = this
- // var img = wx.createImage()
- // if (self.cache && self.cache.ad_icon) {
- // img.src = self.cache.ad_icon.small_icon
- // img.onload = function() {
- // self.renderIcon(x, y, canvas, img)
- // }
- // }
- wx.request({
- url: `${self.api}hz/common`,
- data: {},
- success: function ({ data }) {
- console.log(data)
- self.heziUrl = data.data.hz_picture
- //获取图片进一步操作
- let icon = data.data.ad_icon.small_icon.replace(/http\:\/\//,'https://')
- // img.src = icon
- self.renderIcon(x, y, icon, node)
- }
- })
- }
- renderIcon(x, y, texture, parent) {
- var self = this
- var img = wx.createImage()
- img.src = texture
- self.img = img
- wx.downloadFile({
- url: texture,
- header: {},
- filePath: '',
- success: function (ret) {
- console.log(ret)
- var frame = new cc.SpriteFrame(ret.tempFilePath);
- // self.node.getComponent('adIcon').spriteFrame=frame;
- var node = new cc.Node('adIcon');
- var sp = node.addComponent(cc.Sprite);
- var widget = node.addComponent(cc.Widget)
- var btn = node.addComponent(cc.Button)
- btn.node.on(cc.Node.EventType.TOUCH_START, function () {
- wx.previewImage({
- urls: [self.heziUrl]
- })
- wx.request({
- url: `${self.api}hz/static?field=img`,
- data: { name: self.name },
- success: () => { }
- })
- })
- widget.isAlignTop = true
- widget.isAlignLeft = true
- widget.left = x
- widget.top = y
- sp.spriteFrame = frame
- node.parent = parent;
- console.log(widget)
- console.log(sp)
-
- }
- })
- }
- 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: () => { },
- })
- }
- }
- }
|