install
npm install curdlayout -S
Quick Start
import Vue from 'vue'
import curdLayout from 'curdlayout'
Vue.use(curdLayout)
CURD 布局组件
封装业务相似代码,减少重复编码
最终目的时通过简单的几项配置,完成经常遇到的curd的表格业务
1.使用案例
<template>
<CurdView
:tableOptions="tableOptions"
@on-selection-change="onTableselected"
@on-change="getInputParams"
@on-row-dblclick="rowDblclick"
@on-row-click="rowClick"
>
<template v-slot:tool>
<Button type="default">新增</Button>
</template>
<template v-slot:pannel>
<Button type="default" shape="circle" icon="ios-build">日志推送</Button>
</template>
<template v-slot:action="Props">
<Button type="error" size="small" @click="remove(Props)">Delete</Button>
</template>
<template v-slot:operation="Props">
<Button type="error" size="small" @click="remove(Props)">删除</Button>
</template>
</CurdView>
</template>
<script>
const tableOptions = {
pageSize: 20,
dataUrl: "/data-project-management-service/project/getProject",
param: {},
columns: [
{ type: "selection", width: 60, align: "center" },
{ key: "creator", title: "角色名", align: "center", width: 180 },
{ key: "id", title: "角色名ID", align: "center", width: 180 },
{ key: "projectName", title: "项目名", align: "center", width: 180 },
{ key: "createDate", title: "创建时间", align: "center", width: 180 },
{ key: "description", title: "角色描述", align: "center" },
{ title: "Action", slot: "action", width: 150, align: "center" },
{ title: "操作", slot: "operation", width: 150, align: "center" }
],
searchDynamic: [
{ name: "name", type: "text", span: 6, label: "角色名" },
{ name: "description", label: "角色描述", span: 6, type: "text" }
]
};
import CurdView from "@/components/CurdView/index";
export default {
data() {
return {
tableOptions
};
},
components: { CurdView },
methods: {
onTableselected(selection) {
console.log(selection);
},
getInputParams(params) {
console.log(params);
},
rowDblclick(selection) {
console.log(selection);
},
rowClick(selection) {
console.log(selection);
},
remove(obj) {
alert(obj.rowData.index);
}
}
};
</script>
<style lang='less'>
</style>
显示如下(样式颜色可能会有不一样):

2. API
CurdView props
tableOptions:{
showPanelTool:true,
pageAlign:'center',
tableSize:'small',
pageSize:10,
showOpratingToolbar:true,
showSettingToolbar:true,
showPage:true,
lazy:false,
columns:[],
dataUrl:'',
param:{},
height:400,
searchDynamic:[],
}
treeOptions:{
dataUrl:'',
param:{},
renderFunc:Function ,
}
CurdView events
on-selection-change
on-row-dblclick
on-row-click
on-change
on-select-change
Slot 插槽
提供自定义功能
- 查询条件操作栏自定义,名称为tool得具名插槽,如下,添加一个新增按钮
<template v-slot:tool>
<Button type="default">新增</Button>
</template>
显示如下(样式颜色可能会有不一样):

- 表格操作按钮,除了添加,编辑,删除外,可自定义其他内容,名称为panel得具名插槽,如下,添加一个日志推送按钮
<template v-slot:pannel>
<Button type="default" shape="circle" icon="ios-build">日志推送</Button>
</template>
显示如下(样式颜色可能会有不一样):

- table的Render 写法不变,slot插槽主要使用了作用域插槽,
v-slot:action="Props",action即为插槽name,和clunms项的slot: 'action'必须保持一致(可看例子),
Props当前行数据 row,当前行序号 index。
因为进行了封装,所以table自定义列模板和iView有点不一样,但是Render 写法不变,可按照iView官方文档书写,
<template v-slot:action="Props">
<Button type="default" size="small" @click="getRow(Props)">刷新</Button>
</template>
<template v-slot:operation="Props">
<Button type="error" size="small" @click="getRow(Props)">删除</Button>
</template>