Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@gsp-sys/stores

Package Overview
Dependencies
Maintainers
7
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gsp-sys/stores

共享状态管理库

latest
npmnpm
Version
0.0.6
Version published
Maintainers
7
Created
Source

@gsp-sys/stores

共享状态管理库,基于Pinia实现,为微应用框架提供统一的状态管理解决方案。

导出的Store

useTabsStore

标签页管理Store,用于管理应用中的标签页状态。

状态:

  • activeTab - 当前激活的标签页
  • tabsList - 所有标签页列表
  • installAppMap - 已安装的应用映射
  • keepAliveList - 需要保持状态的页面
  • globalData - 全局数据,包括:
    • number - 数值
    • showTabBar - 是否显示标签栏(仍保留在tabsStore中)

使用方法:

import { useTabsStore } from '@gsp-sys/stores';

const tabsStore = useTabsStore();

// 获取激活的标签页
const activeTab = tabsStore.activeTab;

// 获取所有标签页
const allTabs = tabsStore.tabsList;

// 获取全局数据
const globalData = tabsStore.globalData;

useContextStore

公共上下文存储,用于管理应用的公共上下文信息,包括国际化和主题变量。

状态:

  • currentLocale - 当前语言代码('zh'或'en')
  • primaryColor - 主题主色
  • globalContextData - 全局上下文数据,包括:
    • theme_primary_color - 主题主色
    • language - 当前语言
    • themeName - 主题名称
  • isInitialized - 是否已初始化

计算属性:

  • locale - 当前语言(别名)
  • primaryColorValue - 主题主色(别名)
  • globalData - 全局数据(别名)
  • currentTheme - 当前主题名称

方法:

  • setLocale(locale) - 设置当前语言
  • updateLanguage(lang) - 更新语言(兼容原方法名)
  • setPrimaryColor(color) - 设置主题主色
  • initContext() - 初始化上下文设置

使用方法:

import { useContextStore } from '@gsp-sys/stores';

const contextStore = useContextStore();

// 设置语言
contextStore.setLocale('en');

// 更新语言(兼容方法)
contextStore.updateLanguage('zh');

// 设置主题主色
contextStore.setPrimaryColor('#2A87FF');

// 获取当前语言
const currentLang = contextStore.currentLocale;

useUserStore

用户状态Store,用于管理用户相关的状态。

状态:

  • userInfo - 用户信息
  • token - 认证令牌

计算属性:

  • isLoggedIn - 是否已登录
  • hasRole(role) - 检查用户是否拥有指定角色

方法:

  • login(token, userInfo) - 登录
  • logout() - 登出
  • updateUserInfo(info) - 更新用户信息

使用方法:

import { useUserStore } from '@gsp-sys/stores';

const userStore = useUserStore();

// 登录
userStore.login('token-value', { id: '1', name: 'User', roles: ['admin'] });

// 检查是否登录
if (userStore.isLoggedIn) {
  // 执行登录后的操作
}

// 检查权限
if (userStore.hasRole('admin')) {
  // 显示管理员功能
}

// 登出
userStore.logout();

注意事项

  • 所有Store都使用Composition API风格定义
  • 使用前确保已在应用中正确安装和配置Pinia
  • 跨包使用时,确保已通过workspace协议正确安装依赖

FAQs

Package last updated on 08 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts