67 lines
2.1 KiB
JavaScript
67 lines
2.1 KiB
JavaScript
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
// src/index.tsx
|
|
var src_exports = {};
|
|
__export(src_exports, {
|
|
default: () => src_default
|
|
});
|
|
module.exports = __toCommonJS(src_exports);
|
|
var import_antd = require("antd");
|
|
var import_func = require("@zhst/func");
|
|
var Slave = class {
|
|
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
|
constructor() {
|
|
this.token = null;
|
|
this.jumpUrl = void 0;
|
|
}
|
|
async init(opt = {}) {
|
|
const {
|
|
jumpToLogin = true,
|
|
jumpUrl,
|
|
tokenKey,
|
|
showMsg = true,
|
|
msgText
|
|
} = opt;
|
|
let _token = (0, import_func.getValueByUrl)(tokenKey || "token", location.href) || localStorage.getItem("ZHST_AUTH_TOKEN");
|
|
this.token = _token;
|
|
localStorage.setItem("ZHST_AUTH_TOKEN", _token);
|
|
this.checkEnv({ showMsg, msgText });
|
|
if (jumpToLogin && jumpUrl && !_token) {
|
|
let jumpUrlObj = new URL(jumpUrl);
|
|
if (jumpUrlObj.origin === location.origin) {
|
|
history.pushState("", "", jumpUrl);
|
|
} else {
|
|
location.href = jumpUrl;
|
|
}
|
|
}
|
|
}
|
|
// 判端是否登录
|
|
checkEnv(_opt) {
|
|
if (!this.token && _opt.showMsg) {
|
|
import_antd.message.error(_opt.msgText || "请先登录!");
|
|
return;
|
|
}
|
|
}
|
|
logOut() {
|
|
localStorage.removeItem("ZHST_AUTH_TOKEN");
|
|
location.replace(location.origin + location.pathname);
|
|
}
|
|
};
|
|
var src_default = new Slave();
|