atomm 对象
atomm 是平台 SDK(platform-sdk.js)加载后注入到页面的全局对象,提供平台能力与 UI 工具。在生成器代码中可直接使用。
生命周期 lifecycle
通过 lifecycle.on 注册平台生命周期钩子:
atomm.lifecycle.on('export', async () => { ... })
UI 工具 ui
弹出平台全局提示(toast)。参数为对象:
type:可选success/warning/error/info,默认successmessage:提示文案duration:可选,展示时长,单位秒,0表示不自动关闭;不传默认 3 秒
toast() 返回本条提示的 id;用 closeToast(id) 主动关闭。duration: 0 的常驻提示必须这样关,否则会一直挂着。
atomm.ui.toast({ type: 'success', message: '已完成' })
// 指定展示 5 秒
atomm.ui.toast({ type: 'info', message: '正在处理…', duration: 5 })
// duration: 0 常驻不自动关闭,任务完成后用 closeToast 关掉
const id = await atomm.ui.toast({ type: 'info', message: '导出中…', duration: 0 })
// …任务完成…
await atomm.ui.closeToast(id)
toast 必须传对象
传字符串(如 toast('已完成'))不会生效——平台只读取对象上的 message 与 type,字符串会被当成空消息。ui 命名空间目前提供 toast(返回提示 id)与 closeToast。
应用信息 app
// 当前语言短码(zh / en / ja… 共 17 种)
const locale = await atomm.app.getLocale()
// 全部受支持语言(短码 + 展示名),用于做与平台一致的语言选择器
const locales = await atomm.app.getSupportedLocales()
// → [{ code: 'zh', name: '简体中文' }, { code: 'en', name: 'English' }, …]
用户 user
// 当前是否已登录(只回布尔,不含 token 与个人信息)
const loggedIn = await atomm.user.isLoggedIn()
// 未登录时主动拉起登录弹窗,等用户登录完成后继续;返回最终是否已登录
if (!loggedIn) {
const ok = await atomm.user.login()
if (!ok) return // 用户取消或登录失败
}
// 到这里已登录,继续你的逻辑
login 在用户手势里调用
login() 会弹出登录窗口,请在用户点击等手势的回调里调用,避免被浏览器弹窗拦截。登录是耗时交互,平台已为它放宽超时(约 5 分钟),无需你自己加超时。
安全调用
不确定是否运行在平台内时,用可选链避免报错:
window.atomm?.ui?.toast?.({ type: 'info', message: 'hi' })