操作栏配置

暂无数据

<template>
	<div>
		<qv-crud
			ref="avueRef"
			:data="config.data"
			:option="option"
			@refresh-change="refreshChange"
			@row-save="rowSave"
			@row-update="rowUpdate"
			@row-del="rowDel">
			<template #menu>
				<el-button link>自定义</el-button>
			</template>
		</qv-crud>
	</div>
</template>

<script lang="ts" setup>
import { reactive, computed, ref, onMounted, nextTick } from 'vue'

const ElementPlus = ref()
onMounted(() => {
	import('element-plus').then(module => {
		ElementPlus.value = module
	})
})

const avueRef: Ref<CrudInstance | undefined> = ref()
let config = reactive({
	data: [
		{ name: '张三', age: 12, address: '码云的地址' },
		{ name: '李四', age: 13, address: '码云的地址' }
	]
})
const option = computed(() => {
	return {
		height: 200,
		viewBtn: true,
		editBtn: false,
		delBtn: false,
		copyBtn: true,
		column: [
			{ label: '姓名', prop: 'name' },
			{ label: '年龄', prop: 'age' },
			{ label: '地址', span: 24, prop: 'address', type: 'textarea' }
		]
	}
})
const refreshChange = () => {
	const { ElMessage } = ElementPlus.value
	ElMessage.success('刷新回调')
}
const rowSave = (form, done, loading) => {
	const { ElMessage } = ElementPlus.value
	form.id = new Date().getTime()
	ElMessage.success('模拟网络请求')
	setTimeout(() => {
		ElMessage.success('关闭按钮等待')
		loading()
	}, 1000)
	setTimeout(() => {
		ElMessage.success('新增数据' + JSON.stringify(form))
		done(form)
	}, 2000)
}
const rowDel = (form, index, done) => {
	const { ElMessage, ElMessageBox } = ElementPlus.value
	ElMessageBox.confirm('此操作将永久删除该文件, 是否继续?', '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning'
	})
		.then(() => {
			done(form)
			ElMessage({ type: 'success', message: '删除成功!' })
		})
		.catch(() => {})
}
const rowUpdate = (form, index, done, loading) => {
	const { ElMessage } = ElementPlus.value
	ElMessage.success('模拟网络请求')
	setTimeout(() => {
		ElMessage.success('关闭按钮等待')
		loading()
	}, 1000)
	setTimeout(() => {
		ElMessage.success('编辑数据' + JSON.stringify(form) + '数据序号' + index)
		done(form)
	}, 2000)
}
</script>

属性

属性名称类型说明及注意事项
menuboolean是否显示操作栏
menuWidthnumber string操作栏宽度
viewBtnboolean是否显示详情按钮
addBtnboolean是否显示新增按钮
editBtnboolean是否显示编辑按钮
copyBtnboolean是否显示复制按钮
delBtnboolean是否显示删除按钮
menuAlignstring操作栏布局
menuHeaderAlignstring操作栏头部布局

方法

方法名称回调参数说明及注意事项
row-saveform,done,loading点击新增保存回调
row-updateform,index,done,loading点击编辑回调
row-delform,index点击删除回调
refresh-change点击刷新回调