Skip to content

ActionSheet 操作菜单

从底部弹出的一个操作菜单,类似于 uni.showActionSheetAPI,同时添加新的支持。

方法

事件名称说明参数
open打开function(option: Options)

Options 有效值

参数说明类型可选值默认值
list菜单列表array
close-on-click-modal点击遮罩层是否关闭booleantrue
callback回调functionfunction({ action })
before-close关闭前回调functionfunction({ action,done })
show-cancel是否显示取消按钮booleantrue
cancel-text取消按钮文本内容string取消

示例

callback 为点击回掉,action 为当前点击 list 的下标

html
<template>
	<cl-page :padding="20">
		<cl-action-sheet ref="ActionSheet" />

		<cl-card label="基础用法">
			<cl-button @tap="open">打开</cl-button>
		</cl-card>
	</cl-page>
</template>

<script lang="ts" setup>
	import { ref } from "vue";

	const ActionSheet = ref<ClActionSheet.Ref>();

	function open() {
		ActionSheet.value?.open({
			list: [
				{
					label: "删除好友"
				}
			],
			callback(action) {
				console.log(action);
			}
		});
	}
</script>

添加样式

html
<template>
	<cl-page :padding="20">
		<cl-action-sheet ref="ActionSheet" />

		<cl-card label="基础用法">
			<cl-button @tap="open">打开</cl-button>
		</cl-card>
	</cl-page>
</template>

<script lang="ts" setup>
	import { ref } from "vue";

	const ActionSheet = ref<ClActionSheet.Ref>();

	function open2() {
		ActionSheet.value?.open({
			list: [
				{
					label: "删除好友",
					color: "red",
					size: "40rpx"
				}
			]
		});
	}
</script>

添加禁用

html
<template>
	<cl-page :padding="20">
		<cl-action-sheet ref="ActionSheet" />

		<cl-card label="基础用法">
			<cl-button @tap="open">打开</cl-button>
		</cl-card>
	</cl-page>
</template>

<script lang="ts" setup>
	import { ref } from "vue";

	const ActionSheet = ref<ClActionSheet.Ref>();

	function open() {
		ActionSheet.value?.open({
			list: [
				{
					label: "删除好友会同时删除所有聊天记录",
					disabled: true
				},
				{
					label: "删除好友",
					color: "red"
				}
			]
		});
	}
</script>

关闭前回掉

配置 beforeClose 参数,done 方法为关闭窗口

html
<template>
	<cl-page :padding="20">
		<cl-action-sheet ref="ActionSheet" />

		<cl-card label="基础用法">
			<cl-button @tap="open">打开</cl-button>
		</cl-card>
	</cl-page>
</template>

<script lang="ts" setup>
	import { ref } from "vue";
	import { useCool } from "/@/cool";

	const { ui } = useCool();

	const ActionSheet = ref<ClActionSheet.Ref>();

	function open() {
		ActionSheet.value?.open({
			closeOnClickModal: false,
			list: [
				{
					label: "删除好友",
					color: "red"
				}
			],
			beforeClose(index, done) {
				ui.showConfirm({
					title: "提示",
					message: "是否删除该联系人",
					callback(action) {
						if (action == "confirm") {
							ui.showToast("删除成功");
							done();
						}
					}
				});
			}
		});
	}
</script>