Files
UserhomeFront/public/js/bschload.original.js
chenxing 4279f99be1
deploy-userbase-front / build-and-deploy (push) Failing after 1m54s
build / build (push) Successful in 3m36s
feat: 接入 UserHome 前端业务代码(含真实 src/依赖,保留 projman 标准 CI)
2026-09-09 22:37:59 +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;
}
}