sdk.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. export default class boxSdk {
  2. constructor(name) {
  3. this.name = name, //本游戏名字
  4. this.api = 'https://xyxbox.duowan.com/' //接口域名
  5. this.dataList = [], //数据列表 存放图标游戏图组合列表
  6. this.currentGroup = {} //当前选中图标游戏组合
  7. }
  8. showAdIcon(x, y, node) {
  9. let self = this
  10. wx.request({
  11. url: `${self.api}hz/showAd`,
  12. data: {name:self.name},
  13. success: function ({ data }) {
  14. let meta = data.data
  15. for(let i = 0 ; i < meta.length; i++) {
  16. meta[i].small_icon = meta[i].small_icon.replace(/http\:\/\//,'https://')
  17. }
  18. self.dataList = meta
  19. self.renderIcon(x,y,node)
  20. }
  21. })
  22. }
  23. renderIcon(x,y,parent) {
  24. let self = this
  25. let index = (new Date()).getTime() % self.dataList.length
  26. self.currentGroup = self.dataList[index]
  27. let iconNode = parent.getChildByName("adIcon");
  28. if(iconNode) {
  29. iconNode.destroy();
  30. }
  31. wx.downloadFile({
  32. url: self.currentGroup.small_icon,
  33. header: {},
  34. filePath: '',
  35. success: function (ret) {
  36. var frame = new cc.SpriteFrame(ret.tempFilePath);
  37. var node = new cc.Node('adIcon');
  38. var sp = node.addComponent(cc.Sprite);
  39. var btn = node.addComponent(cc.Button)
  40. sp.spriteFrame = frame
  41. node.parent = parent;
  42. node.x = x
  43. node.y = y
  44. // var widget = node.addComponent(cc.Widget)
  45. // console.log(widget)
  46. // widget.isAlignTop = true
  47. // widget.isAlignLeft = true
  48. // widget.left = x
  49. // widget.top = y
  50. btn.node.on(cc.Node.EventType.TOUCH_START, function () {
  51. wx.request({
  52. url: `${self.api}hz/static?field=img`,
  53. data: { name: self.currentGroup.name },
  54. success: () => { }
  55. })
  56. if(self.currentGroup.app_id) {
  57. wx.navigateToMiniProgram({
  58. appId: self.currentGroup.app_id,
  59. path: self.currentGroup.path,
  60. extraData: {},
  61. success(){console.log('跳转成功')}
  62. })
  63. }else {
  64. wx.previewImage({
  65. urls: [self.currentGroup.big_image]
  66. })
  67. }
  68. self.renderIcon(x,y,parent)
  69. })
  70. }
  71. })
  72. }
  73. openQrcode() {
  74. let self = this
  75. wx.request({
  76. url: `${self.api}hz/common`,
  77. data: {},
  78. success: ({ data }) => {
  79. wx.previewImage({
  80. urls: [data.data.gzh_qr_code]
  81. })
  82. }
  83. })
  84. }
  85. oepnGameCenter() {
  86. wx.request({
  87. url: `${self.api}hz/common`,
  88. data: {},
  89. success: ({ data }) => {
  90. wx.previewImage({
  91. urls: [data.data.hz_picture]
  92. })
  93. }
  94. })
  95. }
  96. initSdk(sceneId, path) {
  97. let gameName = this.name
  98. if (sceneId == 1012) {
  99. wx.request({
  100. url: `${self.api}hz/static?field=qr`,
  101. data: { name: gameName },
  102. success: () => { },
  103. })
  104. }
  105. }
  106. }