Skip to main content

常用的工具函数

tango-boot 提供了一组便捷的工具函数,用于应对日常开发过程中的典型操作逻辑。

getUser()

从 v1.15.0 开始提供

获取当前的登录用户

const user = tango.getUser();

checkPrivilege({ appCode, privilegeCode })

从 v1.15.0 开始提供

检查 PMS 权限

const test = await tango.checkPrivilege({ appCode, privilegeCode });

copyToClipboard(text: string)

复制文本到剪贴板

tango.copyToClipboard('hello world');

导航到其他前端路由

// 基本用法
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 秒

消息提示

tango.showToast('hello world');

tango.showToast('something is error', 'error', 3);

openModal(modalId: string)

根据弹层 ID 唤起目标弹层

tango.openModal('modal123');

closeModal(modalId: string)

根据弹层 ID 关闭目标弹层

tango.closeModal('modal123');

formatDate(date, format)

格式化日期值

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)

格式化数字

tango.formatNumber(99999); // 99,999

getCurrentLanguage

获取当前语种

tango.getCurrentLanguage(); // en-US

setLanguage(localeCode)

设置当前语种

tango.setLanguage('en-US');

getLanguageList

获取当前应用可用语种列表

tango.getLanguageList();

trans(module:key)

根据多语言 key 获取当前语种文案

tango.trans('common:add'); // 新增