laya-coreui-es
Version:
laya核心库、ui库es版本,剔除了媒体、TTF等功能。基于 LayaAir-release_2.12.0 修改
179 lines (178 loc) • 6.09 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdvImage = void 0;
const Image_1 = require("./Image");
const Event_1 = require("../events/Event");
const LocalStorage_1 = require("../net/LocalStorage");
const Browser_1 = require("../utils/Browser");
const ILaya_1 = require("../../ILaya");
class AdvImage extends Image_1.Image {
constructor(skin = null) {
super();
this.advsListArr = [];
this.resUrl = "https://unioncdn.layabox.com/config/iconlist.json";
this._http = new Browser_1.Browser.window.XMLHttpRequest();
this._data = [];
this._resquestTime = 360000;
this._playIndex = 0;
this._lunboTime = 5000;
this.skin = skin;
this.setLoadUrl();
this.init();
this.size(120, 120);
}
setLoadUrl() {
}
init() {
if (this.isSupportJump()) {
if (Browser_1.Browser.onMiniGame || Browser_1.Browser.onBDMiniGame) {
ILaya_1.ILaya.timer.loop(this._resquestTime, this, this.onGetAdvsListData);
}
this.onGetAdvsListData();
this.initEvent();
}
else
this.visible = false;
}
initEvent() {
this.on(Event_1.Event.CLICK, this, this.onAdvsImgClick);
}
onAdvsImgClick() {
var currentJumpUrl = this.getCurrentAppidObj();
if (currentJumpUrl)
this.jumptoGame();
}
revertAdvsData() {
if (this.advsListArr[this._playIndex]) {
this.visible = true;
this.skin = this.advsListArr[this._playIndex];
}
}
isSupportJump() {
if (Browser_1.Browser.onMiniGame) {
var isSupperJump = window.wx.navigateToMiniProgram instanceof Function;
return isSupperJump;
}
else if (Browser_1.Browser.onBDMiniGame)
return true;
return false;
}
jumptoGame() {
var advsObj = this.advsListArr[this._playIndex];
var desGameId = parseInt(advsObj.gameid);
var extendInfo = advsObj.extendInfo;
var path = advsObj.path;
if (Browser_1.Browser.onMiniGame) {
if (this.isSupportJump()) {
window.wx.navigateToMiniProgram({
appId: this._appid,
path: "",
extraData: "",
envVersion: "release",
success: () => {
console.log("-------------跳转成功--------------");
},
fail: () => {
console.log("-------------跳转失败--------------");
},
complete: () => {
console.log("-------------跳转接口调用成功--------------");
this.updateAdvsInfo();
}
});
}
}
else if (Browser_1.Browser.onBDMiniGame) {
}
else {
this.visible = false;
}
}
updateAdvsInfo() {
this.visible = false;
this.onLunbo();
ILaya_1.ILaya.timer.loop(this._lunboTime, this, this.onLunbo);
}
onLunbo() {
if (this._playIndex >= this.advsListArr.length - 1)
this._playIndex = 0;
else
this._playIndex += 1;
this.visible = true;
this.revertAdvsData();
}
getCurrentAppidObj() {
return this.advsListArr[this._playIndex];
}
onGetAdvsListData() {
var _this = this;
var random = AdvImage.randRange(10000, 1000000);
var url = this.resUrl + "?" + random;
this._http.open("get", url, true);
this._http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
this._http.responseType = "text";
this._http.onerror = function (e) {
_this._onError(e);
};
this._http.onload = function (e) {
_this._onLoad(e);
};
this._http.send(null);
}
static randRange(minNum, maxNum) {
return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
}
_onError(e) {
this.error("Request failed Status:" + this._http.status + " text:" + this._http.statusText);
}
_onLoad(e) {
var http = this._http;
var status = http.status !== undefined ? http.status : 200;
if (status === 200 || status === 204 || status === 0) {
this.complete();
}
else {
this.error("[" + http.status + "]" + http.statusText + ":" + http.responseURL);
}
}
error(message) {
this.event(Event_1.Event.ERROR, message);
}
complete() {
var flag = true;
try {
this._data = this._http.response || this._http.responseText;
this._data = JSON.parse(this._data);
this.advsListArr = this._data.list;
this._appid = this._data.appid;
this.updateAdvsInfo();
this.revertAdvsData();
}
catch (e) {
flag = false;
this.error(e.message);
}
}
getAdvsQArr(data) {
var tempArr = [];
var gameAdvsObj = LocalStorage_1.LocalStorage.getJSON("gameObj");
for (var key in data) {
var tempObj = data[key];
if (gameAdvsObj && gameAdvsObj[tempObj.gameid] && !tempObj.isQiangZhi)
continue;
tempArr.push(tempObj);
}
return tempArr;
}
clear() {
var http = this._http;
http.onerror = http.onabort = http.onprogress = http.onload = null;
}
destroy(destroyChild = true) {
ILaya_1.ILaya.timer.clear(this, this.onLunbo);
super.destroy(true);
this.clear();
ILaya_1.ILaya.timer.clear(this, this.onGetAdvsListData);
}
}
exports.AdvImage = AdvImage;