Skip to content

UI

The UI API provides interface interactions: toasts, loading, dialogs, the navigation bar, the tab bar, and more.

Try it online

Live execution

The buttons below call the SDK mock and produce real on-page UI feedback.

showToastToast (none)showLoading
showDialogalertActionSheet

Feedback API demo

Click the buttons to see Toast, Loading, Dialog, and ActionSheet.

Import

ts
import woo from 'mini-sdk'
// 或
import { ui } from 'mini-sdk'

Feedback APIs

showToast

Shows a light-weight toast.

ts
woo.showToast(options?: string | ShowToastOptions): Promise<void>

Parameters:

FieldTypeRequiredDefaultDescription
titlestringYes""Text
iconstringNo"none"Icon type
durationnumberNo2000Duration (ms)
ts
// 简写
await woo.showToast('操作成功')

// 完整参数
await woo.showToast({
  title: '保存成功',
  icon: 'success',
  duration: 1500,
})

hideToast

Hides the current toast.

ts
await woo.hideToast()

showLoading

Shows a loading indicator.

ts
woo.showLoading(options?: string | ShowLoadingOptions): Promise<void>

Parameters:

FieldTypeRequiredDefaultDescription
titlestringNo""Text
maskbooleanNotrueWhether to show a mask
ts
woo.showLoading('加载中...')

// 异步操作
await fetchData()

woo.hideLoading()

hideLoading

Hides the loading indicator.

ts
await woo.hideLoading()

showDialog

Shows a modal dialog and waits for user action.

ts
woo.showDialog(options?: ShowDialogOptions): Promise<ShowDialogResult>

Parameters:

FieldTypeRequiredDefaultDescription
titlestringNo""Title
contentstringNo""Message
cancelTextstringNo""Cancel label (if empty, hidden)
confirmTextstringNo""Confirm label

Return value:

ts
interface ShowDialogResult {
  confirm: boolean  // 用户是否点击了确认
  cancel: boolean   // 用户是否点击了取消
}
ts
const { confirm } = await woo.showDialog({
  title: '确认删除',
  content: '删除后无法恢复,是否继续?',
  cancelText: '取消',
  confirmText: '删除',
})

if (confirm) {
  await deleteItem()
  woo.showToast('删除成功')
}

alert

Shows a simple alert (single button).

ts
woo.alert(options?: string | AlertOptions): Promise<void>

Parameters:

FieldTypeRequiredDefaultDescription
titlestringNo""Title
contentstringNo""Message
buttonTextstringNo"OK"Button label
ts
// 简写
await woo.alert('操作完成')

// 完整参数
await woo.alert({
  title: '提示',
  content: '您的积分不足',
  buttonText: '知道了',
})

showActionSheet

Shows a bottom action sheet.

ts
woo.showActionSheet(options: ShowActionSheetOptions): Promise<ShowActionSheetResult>

Parameters:

FieldTypeRequiredDescription
itemListstring[]YesList of item labels

Return value:

ts
interface ShowActionSheetResult {
  index: number  // 用户选择的菜单项索引
}
ts
const { index } = await woo.showActionSheet({
  itemList: ['拍照', '从相册选择', '保存图片'],
})

switch (index) {
  case 0: await takePhoto(); break
  case 1: await chooseFromAlbum(); break
  case 2: await saveImage(); break
}

setNavigationBarTitle

Sets the page title at runtime.

ts
await woo.setNavigationBarTitle({ title: '新标题' })

setNavigationBarColor

Sets navigation bar colors.

ts
await woo.setNavigationBarColor({
  frontColor: '#ffffff',       // 前景色(标题、按钮)
  backgroundColor: '#6366f1', // 背景色
})

showNavigationBarLoading / hideNavigationBarLoading

Shows or hides the navigation bar loading indicator.

ts
woo.showNavigationBarLoading()
await fetchData()
woo.hideNavigationBarLoading()

TabBar API

showTabBar / hideTabBar

Shows or hides the bottom tab bar.

ts
await woo.hideTabBar()  // 隐藏
await woo.showTabBar()  // 显示

setTabBarBadge / removeTabBarBadge

Sets or removes a tab badge.

ts
// 设置第 2 个 Tab 的徽标
await woo.setTabBarBadge({ index: 1, text: '99+' })

// 移除
await woo.removeTabBarBadge({ index: 1 })

setTabBarItem

Updates a tab item at runtime.

ts
await woo.setTabBarItem({
  index: 0,
  text: '新首页',
  iconPath: '/static/icons/new-home.png',
  selectedIconPath: '/static/icons/new-home-active.png',
})

setTabBarStyle

Updates tab bar styling.

ts
await woo.setTabBarStyle({
  color: '#999999',
  selectedColor: '#6366f1',
  backgroundColor: '#ffffff',
  borderStyle: 'white',
})

showTabBarRedDot / hideTabBarRedDot

Shows or hides a small red dot on a tab.

ts
await woo.showTabBarRedDot({ index: 2 })
await woo.hideTabBarRedDot({ index: 2 })

Image preview

previewImage

Previews images full screen.

ts
await woo.previewImage({
  urls: [
    'https://example.com/img/1.jpg',
    'https://example.com/img/2.jpg',
    'https://example.com/img/3.jpg',
  ],
  current: 'https://example.com/img/2.jpg', // 当前显示的图片
})

API quick reference

MethodDescriptionSignature
showToastShow a toast({ title, icon?, duration? }) → Promise<void>
hideToastHide toast() → Promise<void>
showLoadingShow loading({ title }) → Promise<void>
hideLoadingHide loading() → Promise<void>
showModalShow a modal({ title, content, ... }) → Promise<{ confirm, cancel }>
showActionSheetShow an action sheet({ itemList }) → Promise<{ tapIndex }>
setNavigationBarTitleSet the nav bar title({ title }) → Promise<void>
setNavigationBarColorSet the nav bar colors({ frontColor, backgroundColor }) → Promise<void>
showTabBar / hideTabBarShow or hide the TabBar() → Promise<void>
setTabBarBadge / removeTabBarBadgeSet or remove a tab badge({ index, text? }) → Promise<void>
setTabBarStyleSet TabBar style({ color, selectedColor, ... }) → Promise<void>
showTabBarRedDot / hideTabBarRedDotShow or hide a tab red dot({ index }) → Promise<void>
previewImageFull-screen image preview({ urls, current? }) → Promise<void>

MiniDev Studio — Mini-app Development Toolkit