Skip to content

ActionSheet 动作面板

预览
01:38

组件名:rice-action-sheet

底部弹起的模态面板,包含与当前情境相关的多个选项。支持使用 API 的方式进行调用

平台兼容性

uni-app x

AndroidiOS鸿蒙Next微信小程序h5

基础使用

vue
<template>
	<rice-navbar title="ActionSheet 动作面板"></rice-navbar>
	<demo-page :row-gap="false">
		<rice-notice-bar message="支持组件调用和API调用两种方式" type="primary" right-icon="arrow-right"
			@click="toApi"></rice-notice-bar>
		<demo-block-title title="基础使用" row-gap show-set />

		<rice-cell-group radius="8px" :custom-style="{margin:'0 16px'}">
			<rice-cell title="基础用法" arrow @click="show=!show" />
			<rice-cell title="显示标题" arrow @click="showTitle=!showTitle" />
			<rice-cell title="展示图标" arrow @click="showIcon=!showIcon" />
			<rice-cell title="展示描述信息" arrow @click="openDesc(false)" />
			<rice-cell title="渐变过渡" arrow :border="false" @click="openDesc(true)" />
		</rice-cell-group>

		<rice-action-sheet v-model:show="show" :actions="actions" @select="onSelect" />
		<rice-action-sheet v-model:show="showTitle" title="一段标题" :actions="actions" />
		<rice-action-sheet v-model:show="showIcon" :actions="actionsIcon" />
		<rice-action-sheet v-model:show="showDesc" :actions="actionsDesc" :opacity="opacity" />

		<demo-block-title title="选项状态" row-gap />
		<rice-cell-group radius="8px" :custom-style="{margin:'0 16px'}">
			<rice-cell title="选项状态" arrow @click="openState(true)" />
			<rice-cell title="点击选项不关闭" arrow :border="false" @click="openState(false)" />
		</rice-cell-group>

		<rice-action-sheet v-model:show="showState" :close-on-click-action="closeOnClickAction" :actions="actionsState"
			@select="onSelect" />

	</demo-page>
</template>

<script setup lang="ts">
import { useNavbarAndTabbarStyle } from "@/store/theme"
import { ActionSheetAction } from "@/uni_modules/rice-ui"
useNavbarAndTabbarStyle()

const show = ref(false)
const showTitle = ref(false)
const showIcon = ref(false)
const showDesc = ref(false)
const opacity = ref(false)
const showState = ref(false)
const closeOnClickAction = ref(true)

const openDesc = (flag : boolean) => {
  opacity.value = flag
  showDesc.value = true
}

const openState = (flag : boolean) => {
  closeOnClickAction.value = flag
  showState.value = true
}

const actions = ref<ActionSheetAction[]>([
  { name: '选项一' },
  { name: '选项二' },
  { name: '选项三' },
])

//带图标
const actionsIcon = ref<ActionSheetAction[]>([
  { name: '选项一', icon: 'star', iconSize: '20px' },
  { name: '选项二', icon: 'shopping', iconSize: '20px' },
  { name: '选项三', icon: 'camera', iconSize: '20px' },
])

//带描述
const actionsDesc = ref<ActionSheetAction[]>([
  { name: '选项一', subname: '这是一段描述' },
  { name: '选项二', subname: '这是一段超长的描述这是一段超长的描述这是一段超长的描述这是一段超长的描述' },
  { name: '选项三' },
])

//选项状态
const actionsState = ref<ActionSheetAction[]>([
  { name: '选项一', color: '#f10a24', icon: 'star', iconSize: '18px'  },
  { name: '选项二', color: '#07c160', icon: 'trophy', iconSize: '18px' },
  { name: '选项三', },
  { name: '选项四', subname: '禁用', disabled: true, icon: 'voice-off' },
])


let timer : number | null = null
const onSelect = (action : ActionSheetAction, index : number) => {
  if (timer != null) clearTimeout(timer!)
  timer = setTimeout(() => {
    uni.showToast({
      title: `点击了:${action.name},索引:${index}`,
      icon: 'none',
      duration: 2500,
    })
  }, 10)
}

const toApi = () => {
  uni.navigateTo({
    url: '/pages/api/action-sheet'
  })
}

onUnload(() => {
  if (timer != null) clearTimeout(timer!)
})
</script>

<style scoped lang="scss">
.flex {
  flex-direction: row;
  flex-wrap: wrap;
}
</style>

API调用

vue
<script setup lang="ts">
import { showActionSheet, hideActionSheet, ActionSheetAction } from "@/uni_modules/rice-ui"

const actions = ref<ActionSheetAction[]>([
  { name: '选项一' },
  { name: '选项二' },
  { name: '选项三' },
])
showActionSheet({
  actions: params,
  select: (action : ActionSheetAction, index : number) => {
    if (timer != null) clearTimeout(timer!)
    timer = setTimeout(() => {
      uni.showToast({
        title: `点击了:${action.name},索引:${index}`,
        icon: 'none',
        duration: 2500,
      })
    }, 10)
  },
  cancel: () => {
    console.log('点击了取消')
  }
})

</script>

Api

Props

属性名类型说明默认值
v-model:show/showBoolean是否显示-
actionsActionSheetAction[]面板选项列表,数据格式见下方类型-
titleString面板标题-
show-cancelBoolean是否显示取消按钮-
cancel-textString取消按钮文字-
durationNumber动画时长,单位ms,默认300ms-
z-indexNumberz-index的值-
opacityBoolean是否使用渐变过渡-
overlayBoolean是否显示遮罩-
overlay-bg-colorString遮罩层的背景色-
close-on-click-actionBoolean点击选项后是否关闭-
close-on-click-overlayBoolean点击遮罩是否关闭-
radiusString|Number圆角值-
safe-area-inset-bottomBoolean是否开启底部安全区-
use-dialog-pageBoolean是否使用dialogPage,仅APP支持-
custom-styleObject自定义样式-

Events

事件名说明回调参数
select选择了选项时触发(action:ActionSheetAction,index:number)
cancel点击取消按钮时触发-
open打开时触发-
close关闭时触发-
opened打开动画结束时触发-
closed关闭动画结束时触发-
clickOverlay点击遮罩层时触发-

类型定义

ts
type ActionSheetAction = {
	name : string,
	subname ?: string,
	color ?: string,
	icon ?: string,
	iconSize ?: string | number,
	disabled ?: boolean,
}

组件导出如下类型

ts
// 组件类型
const actionSheetRef = ref<RiceActionSheetComponentPublicInstance | null>(null)