View

cl-view-group

左右两侧布局,以兼容手机端

PC 端:

手机端:

使用:

<cl-view-group ref="ViewGroup">
	<template #right>
		<cl-crud></cl-crud>
	</template>
</cl-view-group>

<script setup lang="ts">
	import { useViewGroup } from "/$/base";

	const { ViewGroup } = useViewGroup();
</script>

参考 /src/modules/dict/views/list.vue、/src/modules/iot/views/device.vue

Options

参数说明类型可选值默认值
label左侧标题string
leftWidth左侧宽度string300px
title右侧标题string列表
data请求附带的数据object{}
enableContextMenu开启右键菜单booleantrue
enableRefresh开启刷新按钮booleantrue
enableAdd开启新增按钮booleantrue
service服务Service
onSelect选择事件(item: ClViewGroup.Item)
onEdit编辑事件(item?: ClViewGroup.Item) => DeepPartial<ClForm.Options>
onContextMenu右键事件(item: ClViewGroup.Item) => ClContextMenu.Options
onData数据事件(list: any[]) => any[]

插槽

插槽名说明作用域
left左侧菜单
item左侧列表项{ item, selected, index }
item-name左侧列表项名称{ item, selected, index }
right右侧内容
title右侧标题{ selected }
<cl-view-group ref="ViewGroup">
	<template #item="{ item, selected, index }"> {{ item.name }} </template>
</cl-view-group>

Ref

参数说明类型可选值默认值
selected选中值
isExpand是否展开状态booleantrue
expand展开、收起function(status?: boolean)
select选择某一项function(item: any)
edit编辑某一项, item 为空则是新增function(item?: any)
remove删除某一项function(item: any)
onSelect

选择后触发,可以用来刷新右侧的列表等操作

const { ViewGroup } = useViewGroup({
	onSelect(item) {
		refresh({
			typeId: item.id,
			page: 1
		});
	}
});
onEdit

表单编辑时触发,返回值与 OpenOptions 一致

const { ViewGroup } = useViewGroup({
	onEdit(item) {
		return {
			title: "标题",
			width: "500px",
			props: {
				labelWidth: "60px"
			},
			items: [
				{
					label: "名称",
					prop: "name",
					component: {
						name: "el-input",
						props: {
							maxlength: 20
						}
					},
					required: true
				}
			]
		};
	}
});
onContextMenu

默认带有 编辑删除。如需自定义右键菜单,返回值与 cl-context-menu 一致。

const { ViewGroup } = useViewGroup({
	onContextMenu(item) {
		return {
			list: [
				{
					label: "编辑",
					callback(done) {
						done();
						ViewGroup.value?.edit(item);
					}
				},
				{
					label: "删除",
					callback(done) {
						done();
						ViewGroup.value?.remove(item);
					}
				}
			]
		};
	}
});
onData

处理左侧列表数据,由 service 中的 page 接口返回

const { ViewGroup } = useViewGroup({
	onData(list) {
		return list.map((e) => {
			return {
				...e,
				name: "-" + e.name + "-"
			};
		});
	}
});
Last Updated: