@x-edu/functions
v0.1.9
Published
常用工具库
Maintainers
Keywords
Readme
@x-edu/functions
发布
发布到 npm 官方 registry 上,注意不要发到 npm.sdp.nd 上
npm publish发布后需要同步版本,依次访问如下地址,进行同步
- https://npmmirror.com/sync/@x-edu/functions
- http://npm.sdp.nd/sync/@x-edu/functions 访问 https://npmmirror.com/package/functions 查看版本是否正确
API
API
Auth
Auth 类用于处理用户认证相关的操作。
| 方法名 | 描述 | 参数 | 返回值 |
|------------------|------------------------------------------------------------|--------------|--------------|
| getLoginState | 获取用户的登录状态。 | 无 | 登录状态信息 |
| getAuthHeader | 获取认证头部信息。 | 无 | 认证头部对象 |
| getUserInfo | 获取用户信息。 | 无 | 用户信息对象 |
| getRegisterUrl | 获取注册URL。 | 跳转地址:redirectUrl | 注册URL |
| getLoginUrl | 获取登录URL。 | 跳转地址:redirectUrl、天喻需要的参数:state、是否需要闲跳转天喻的登出页面:shouldLogout | 登录URL |
| logout | 登出当前用户。 | 无 | 操作结果 |
网络请求 (Request)
Request 类包含网络请求相关的操作。
| 方法名 | 描述 | 参数 | 返回值 |
|------------------|------------------------------------------------------------|--------------|--------------|
| rawAPI | 原始的API请求对象。 | 根据具体API | 请求对象 |
| generateCommonAPIWithUC | 生成带有UC认证的通用API请求对象。 | 根据具体API | 请求对象 |
Bridge 工具
bridge 工具用于不同应用或组件之间的桥接。
app Bridge
| 方法名 | 描述 | 参数 | 返回值 |
|------------------|------------------------------------------------------------|--------------|--------------|
| gotoCmp | 跳转cmp地址 | {target:string,path:string,query:Recrod<string,string>} | 无 |
| generateCmp | 整合cmp地址 | {target:string,path:string,query:Recrod<string,string>} | 无 |
| getAppFactory | 获取app工厂的实例 | 无 | Promise |
| getProvider | 获取移动端提供的provider的值 | {toolName: string, providerName: string, providerKey:string} | provider提供的值 |
app EventBus
| 方法 | 参数类型 | 参数描述 | 返回值类型 | 描述 | | ------------- | ---------------------------- | -------------------------------- | ---------- | ------------------------------------------------------------ | | on | (name: string, handler: (data: any) => void) | 事件名和处理函数 | Off | 监听指定名称的事件,返回取消监听的函数 | | off | (name: string, handler: (data: any) => void) | 事件名和处理函数 | 无 | 取消监听指定名称的事件 | | emit | (name: string, data: any) | 事件名和要传递的数据 | 无 | 触发指定名称的事件,并将数据传递给监听者 | | destroy | | | 无 | 移除所有的事件监听器 | | request | (name: string, data: any) | 请求的事件名和要发送的数据 | Promise | 发送一个请求,并返回一个Promise,用于接收响应 | | onRequest | (name: string, handler: (data: any) => Promise) | 请求的事件名和处理函数 | 无 | 监听指定名称的请求事件,并返回一个Promise,用于异步处理请求并发送响应 |
electron Bridge
| 方法 | 参数类型 | 返回值类型 | 描述 | |-------------------------|---------------------------------------------|------------------|--------------------------------------------------------------| | getAccountInfo | void | Promise | 获取账户信息 | | triggerLogout | errorMsg: string | Promise | 触发登出操作,可传入错误信息 | | onAccountChange | handler: (accountInfo: AccountInfo) => void | void | 监听账户信息变化 | | offAccountChange | handler: (accountInfo: AccountInfo) => void | void | 取消监听账户信息变化 | | setUnreadMessageCount | count: number | Promise | 设置未读消息数量 | | blinkTray | info: BallonInfo | Promise | 闪烁托盘图标,传入提示信息 | | stopBlinkTray | void | Promise | 停止闪烁托盘图标 | | getWebContentOffset | void | Promise<[x: number, y: number]> | 获取网页内容的偏移量 | | openInWorkTable | workTableTabInfo: WorkTableTabInfo | Promise | 在工作台标签页中打开 | | openInPopup | popupInfo: PopupInfo | Promise | 在弹出窗口中打开 | | closePopup | void | Promise | 关闭弹出窗口 | | setDefaultWindowOpen | style: WindowOpenStyle | Promise | 设置默认的窗口打开方式 | | addTrayMessage | info: TrayMessageInfo | Promise | 添加托盘消息 | | deleteTrayMessage | info: TrayMessageInfo | Promise | 删除托盘消息 | | onTrayMessageClick | handler: (info: TrayMessageInfo) => Promise | Promise | 监听托盘消息点击事件 |
env 工具
env 工具用于环境检测。
| 方法名 | 返回类型 | 描述 |
|------------------|----------|--------------------------------------------------------------|
| inWX | boolean | 检测是否在微信环境中。 |
| inH5 | boolean | 检测是否在H5环境中。 |
| inMobile | boolean | 检测是否在移动设备环境中,且屏幕宽度小于等于960px。 |
| isIE | boolean | 检测是否在IE浏览器中。 |
| isWin7 | boolean | 检测是否在Windows 7操作系统中。 |
| inAndroid | boolean | 检测是否在Android操作系统中。 |
| iniOS | boolean | 检测是否在iOS设备中。 |
| inAndroidPad | boolean | 检测是否在Android平板中。 |
| inIpad | boolean | 检测是否在iPad设备中。 |
| inFireFox | boolean | 检测是否在Firefox浏览器中。 |
| inApp | boolean | 检测是否在工程院App中。 |
| inMicro | boolean | 检测是否在微前端环境下。 |
| inElectron | boolean | 检测是否在Electron环境中。 |
图片url工具
图片URL工具主要用于处理图片URL,特别是与WebP格式相关的操作。
| 方法名 | 返回类型 | 描述 |
|------------------|----------|--------------------------------------------------------------|
| isSupportWebp | boolean | 检测浏览器是否支持WebP格式。 |
URL工具
URL工具用于处理URL查询参数。
| 方法名 | 描述 | 参数 | 返回值 |
|------------------|------------------------------------------------------------|--------------|--------------|
| getUrlQuery | 获取当前URL的查询参数。 | 无 | 查询参数对象 |
| setQueryInUrl | 设置当前URL中的search参数。 | 参数键值对 | 修改后的URL |
| removeQueryFromUrl | 移除当前URL上的参数。 | 参数名 | 修改后的URL |
资源跳转
资源跳转相关操作,具体设计方案见提供的链接。
初始化
| 方法名 | 描述 | 参数类型 | 返回类型 |
|----------------------|--------------------------------------------------------------|------------------------------------------|-----------|
| init | 初始化ResourceUrl类的单例实例。 | ResourceUrlConfig[] (可选) | ResourceUrl实例 |
实例方法
| 方法名 | 描述 | 参数类型 | 返回类型 |
|----------------------|--------------------------------------------------------------|------------------------------------------|-----------|
| getTargetUrl | 根据提供的参数生成目标URL。 | data, uniqKey, type, platform | string |
IndexDB工具
IndexDB工具提供对IndexedDB的Promise封装。
| 方法名 | 描述 | 参数类型 | 返回类型 |
|----------------------|--------------------------------------------------------------|------------------------------------------|-----------|
| checkDB | 检查数据库并执行传入的checker函数。 | string, Function | - |
| openDB | 打开或创建一个新的IndexedDB数据库。 | string, string, Object[], string[] | Promise<IDB> |
| bulkInsert | 批量插入数据到指定的表。 | string, Object[], Function | Promise<void> |
| count | 获取指定表的数据数量。 | string | Promise<number> |
| getByfilter | 根据过滤条件搜索指定表内的数据。 | string 或 string[], Function | Promise<Object[]> |
| _getByfilter | 根据过滤条件搜索单个表内的数据。 | string, Function | Promise<Object[]> |
| removeByKey | 删除指定表的特定键的数据。 | string, string 或 string[] | Promise<void> |
| put | 插入或更新指定表的数据。 | string, string, any | Promise<void> |
download工具
download工具用于处理下载相关
| 方法名 | 描述 | 参数 | 返回值 |
|------------------|------------------------------------------------------------|--------------|--------------|
| getDownloadCenterUrl | 前往下载中心地址 | { uc: UC, env: string, host?: string, sdpAppId?: string, sdpOrgId?: string } | 下载中心地址 |
