Files
UserhomeFront/dist_harness_before/js/bschload.original.js
T
chenxing 19e1bbc9d7
build / build (push) Successful in 1m8s
设置界面更新
2026-10-08 10:08:22 +08:00

107 lines
2.8 KiB
JavaScript

/**
* 数字基座内嵌加载帮助类
*/
class BschLoadUtil {
#isDev = false;
#appId = null;
constructor() {
if (!BschLoadUtil.instance) {
this.isSelf = window.self === window.top;
this.#appId = this.uuid();
this.ticket = null;
this.roleInfo = {
userId: null,
roleId: null,
schId: null,
childId: null,
};
BschLoadUtil.instance = this;
}
return BschLoadUtil.instance;
}
getTicket() {
if (!this.#isDev) {
const ticket = this.getUrlParam("ticket"),
roleInfoStr = this.getUrlParam("role");
var roleInfo = this.roleDecode(roleInfoStr);
this.ticket = ticket;
this.roleInfo = roleInfo;
}
return { ticket: this.ticket, roleInfo: this.roleInfo };
}
goBackDesktop() {
if (this.#isDev) {
console.error("调试模式,无效操作!");
return;
}
parent.postMessage(JSON.stringify({ id: this.#appId, code: 1 }), "*");
}
reloadParent() {
if (this.#isDev) {
console.error("调试模式,无效操作!");
return;
}
parent.postMessage(JSON.stringify({ id: this.#appId, code: 2 }), "*");
}
showUserInfo() {
if (this.#isDev) {
console.error("调试模式,无效操作!");
return;
}
parent.postMessage(JSON.stringify({ id: this.#appId, code: 3 }), "*");
}
roleDecode(roleInfoStr) {
try {
var str = window.atob(roleInfoStr);
str = decodeURIComponent(str);
var obj = JSON.parse(str);
return obj;
} catch (error) {
console.error(error);
return {
id: null,
ticket: "",
roleInfo: {},
};
}
}
setDevTicket(ticket, roleInfo) {
if (this.isSelf) {
this.ticket = ticket;
this.roleInfo = roleInfo;
this.#isDev = true;
}
}
getIsSelf() {
if (this.#isDev) return false;
else return this.isSelf;
}
getUrlParam(name) {
let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
let r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
else return null;
}
uuid() {
return "xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g, function (c) {
let r = (Math.random() * 16) | 0,
v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
static getInstance() {
if (!this.instance) {
return (this.instance = new BschLoadUtil());
}
return this.instance;
}
}