mirror of
https://github.com/NetEase/tango.git
synced 2026-09-01 15:03:03 +08:00
131 lines
2.2 KiB
Plaintext
131 lines
2.2 KiB
Plaintext
# 常用的工具函数
|
|
|
|
tango-boot 提供了一组便捷的工具函数,用于应对日常开发过程中的典型操作逻辑。
|
|
|
|
### `getUser()`
|
|
|
|
> 从 v1.15.0 开始提供
|
|
|
|
获取当前的登录用户
|
|
|
|
```js
|
|
const user = tango.getUser();
|
|
```
|
|
|
|
### `checkPrivilege({ appCode, privilegeCode })`
|
|
|
|
> 从 v1.15.0 开始提供
|
|
|
|
检查 PMS 权限
|
|
|
|
```js
|
|
const test = await tango.checkPrivilege({ appCode, privilegeCode });
|
|
```
|
|
|
|
### `copyToClipboard(text: string)`
|
|
|
|
复制文本到剪贴板
|
|
|
|
```js
|
|
tango.copyToClipboard('hello world');
|
|
```
|
|
|
|
### `navigateTo(link: string, data?: object)`
|
|
|
|
导航到其他前端路由
|
|
|
|
```js
|
|
// 基本用法
|
|
tango.navigateTo('/about');
|
|
|
|
// 带路由参数
|
|
tango.navigateTo('/about', { the: 'query' }); // /about?the=query
|
|
```
|
|
|
|
### `showToast(text: string, type: string, time: number)`
|
|
|
|
- text 消息正文
|
|
- type 消息类型 `success | error | warn`
|
|
- time 消息展示的时间,单位秒,默认为 3 秒
|
|
|
|
消息提示
|
|
|
|
```js
|
|
tango.showToast('hello world');
|
|
|
|
tango.showToast('something is error', 'error', 3);
|
|
```
|
|
|
|
### `openModal(modalId: string)`
|
|
|
|
根据弹层 ID 唤起目标弹层
|
|
|
|
```js
|
|
tango.openModal('modal123');
|
|
```
|
|
|
|
### `closeModal(modalId: string)`
|
|
|
|
根据弹层 ID 关闭目标弹层
|
|
|
|
```js
|
|
tango.closeModal('modal123');
|
|
```
|
|
|
|
### `formatDate(date, format)`
|
|
|
|
- date: `number | string | Moment` 日期值
|
|
- format: `string` 格式化,取值参考 https://momentjs.com/docs/#/displaying/format/
|
|
|
|
格式化日期值
|
|
|
|
```js
|
|
tango.formatDate(1659496225323, 'YYYY-MM-DD HH:mm:ss'); // 2022-08-03 11:10:25
|
|
|
|
tango.formatDate('2022-11-11', 'X'); // 1668096000
|
|
```
|
|
|
|
### `formatNumber(number, locale, options)`
|
|
|
|
- number: `number`
|
|
- locale: `string`
|
|
- options: `Intl.NumberFormatOptions`,参考取值 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat
|
|
|
|
格式化数字
|
|
|
|
```js
|
|
tango.formatNumber(99999); // 99,999
|
|
```
|
|
|
|
### `getCurrentLanguage`
|
|
|
|
获取当前语种
|
|
|
|
```js
|
|
tango.getCurrentLanguage(); // en-US
|
|
```
|
|
|
|
### `setLanguage(localeCode)`
|
|
|
|
设置当前语种
|
|
|
|
```js
|
|
tango.setLanguage('en-US');
|
|
```
|
|
|
|
### `getLanguageList`
|
|
|
|
获取当前应用可用语种列表
|
|
|
|
```js
|
|
tango.getLanguageList();
|
|
```
|
|
|
|
### `trans(module:key)`
|
|
|
|
根据多语言 key 获取当前语种文案
|
|
|
|
```js
|
|
tango.trans('common:add'); // 新增
|
|
```
|