@pisell/pisellos
Version:
一个可扩展的前端模块化SDK框架,支持插件系统
110 lines (108 loc) • 3.28 kB
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/modules/Account/index.ts
var Account_exports = {};
__export(Account_exports, {
AccountModule: () => AccountModule
});
module.exports = __toCommonJS(Account_exports);
var import_BaseModule = require("../BaseModule");
var import_types = require("./types");
__reExport(Account_exports, require("./types"), module.exports);
var AccountModule = class extends import_BaseModule.BaseModule {
constructor(name, version) {
super(name, version);
this.defaultName = "account";
this.defaultVersion = "1.0.0";
this.isGuest = false;
this.store = {
accountInfo: null,
isLoggedIn: false,
active: false
};
}
async initialize(core, options) {
this.core = core;
this.store = options == null ? void 0 : options.store;
this.store.isLoggedIn = false;
}
getId() {
var _a;
return ((_a = this.store.accountInfo) == null ? void 0 : _a.id) || "";
}
async login(credentials) {
const account = {
id: "1",
// 实际应该从 API 返回
username: credentials.username,
email: `${credentials.username}@example.com`,
name: credentials.username,
isGuest: false,
type: "account"
};
this.store.accountInfo = account;
this.store.isLoggedIn = true;
await this.core.effects.emit(import_types.AccountHooks.OnLogin, account);
}
getCurrentAccount() {
return this.store.accountInfo;
}
async updateProfile(updates) {
if (!this.store.accountInfo)
return;
this.store.accountInfo = {
...this.store.accountInfo,
...updates
};
await this.core.effects.emit(
import_types.AccountHooks.OnProfileUpdate,
this.store.accountInfo
);
}
isLoggedIn() {
return this.store.isLoggedIn;
}
getLoginStatus() {
return this.store.isLoggedIn;
}
getAccount() {
return this.store.accountInfo;
}
setAccountInfo(account) {
this.store.accountInfo = account;
if (account.isGuest) {
this.isGuest = true;
}
}
setActive(active) {
this.store.active = active;
}
isActive() {
return this.store.active;
}
isLogin() {
var _a;
return ((_a = this.store.accountInfo) == null ? void 0 : _a.isLogin) || false;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
AccountModule,
...require("./types")
});