@gsp-sys/utils
v0.0.7
Published
通用工具函数库
Keywords
Readme
@gsp-sys/utils
通用工具函数库,为微应用框架提供各种常用工具函数。
目录结构
├── src/
│ ├── auth/ # 认证相关工具函数
│ ├── common/ # 通用工具函数
│ ├── network/ # 网络请求工具
│ ├── storage/ # 存储相关工具
│ ├── theme/ # 主题相关工具
│ └── index.ts # 导出文件主要功能模块
认证工具 (auth)
getToken()- 获取认证TokensetToken(token)- 设置认证TokenremoveToken()- 移除认证Token
通用工具 (common)
dateFormat(fmt, date)- 日期格式化addZero(num)- 数字补零formatDateTime(date)- 时间格式化getPrecision(value)- 获取数值精度numberFormat(value, precision)- 数字精度控制getWeekStartDate(val, firstDayOfWeek)- 获取周起始日期downloadFile(res, fileName)- 文件下载evil(fn)- 安全执行代码字符串getSearchCondValueByName(name)- 获取保存的查询条件
加密工具 (common/crypto)
encryption(sourceData)- AES加密decryption(sourceData)- AES解密
网络请求 (network)
request(options)- 基础请求函数get(url, params, config)- GET请求post(url, data, config)- POST请求put(url, data, config)- PUT请求del(url, params, config)- DELETE请求
主题工具 (theme)
getCssVariableValue(variableName)- 获取CSS变量值setCssVariableValue(variableName, newValue)- 设置CSS变量值setCssVariables(variables)- 批量设置CSS变量getCssVariables(variableNames)- 获取多个CSS变量
使用方法
在项目中导入所需的工具函数:
// 导入单个函数
import { getToken, setToken } from '@gsp-sys/utils';
// 导入请求模块
import { request, get, post } from '@gsp-sys/utils';
// 使用示例
const token = getToken();
setToken('new-token-value');
// 发送请求
const data = await get('/api/data', { id: 1 });注意事项
- 所有工具函数都已添加TypeScript类型定义
- 在使用网络请求函数时,确保已正确配置全局的
window.webConfig.serviceAddress - CSS变量工具函数需要在浏览器环境中运行
