import { defineStore } from 'pinia'; const IDENTITY_LABELS = { 1: "超管", 2: "管理员", 3: "代理", 4: "运营" }; function parseComma(val) { if (!val) return []; return val.split(",").map((s) => s.trim()).filter(Boolean); } function saveToStorage(data) { } const useAuthStore = defineStore("auth", { state: () => ({ token: "", account: "", identity: 0, access: [], apps: [], regions: [], products: [], appbinds: [], currentAppId: 0, siteTitle: "" }), getters: { isSuperAdmin() { return this.identity === 1; }, isAdmin() { return this.identity === 1 || this.identity === 2; }, identityLabel() { return IDENTITY_LABELS[this.identity] ?? ""; }, isLoggedIn() { return !!this.token; } }, actions: { setLoginData(data) { this.token = data.token; this.account = data.account; this.identity = data.identity; this.access = parseComma(data.access); this.apps = parseComma(data.apps); this.regions = parseComma(data.regions); this.products = parseComma(data.products); this.appbinds = data.appbinds ?? []; if (this.appbinds.length > 0 && !this.currentAppId) { this.currentAppId = this.appbinds[0].id; } saveToStorage({ token: this.token, account: this.account, identity: this.identity, access: this.access, apps: this.apps, regions: this.regions, products: this.products, appbinds: this.appbinds, currentAppId: this.currentAppId, siteTitle: this.siteTitle }); }, setCurrentApp(id) { this.currentAppId = id; saveToStorage({ token: this.token, account: this.account, identity: this.identity, access: this.access, apps: this.apps, regions: this.regions, products: this.products, appbinds: this.appbinds, currentAppId: this.currentAppId, siteTitle: this.siteTitle }); }, setSiteTitle(title) { this.siteTitle = title; saveToStorage({ token: this.token, account: this.account, identity: this.identity, access: this.access, apps: this.apps, regions: this.regions, products: this.products, appbinds: this.appbinds, currentAppId: this.currentAppId, siteTitle: this.siteTitle }); }, logout() { this.token = ""; this.account = ""; this.identity = 0; this.access = []; this.apps = []; this.regions = []; this.products = []; this.appbinds = []; this.currentAppId = 0; this.siteTitle = ""; }, restore() { return; }, hasAccess(pageId) { if (this.identity === 1) return true; return this.access.includes(pageId); } } }); export { useAuthStore as u }; //# sourceMappingURL=auth-QFkCoU1C.mjs.map