Skip to content

Commit 7853c58

Browse files
committed
perf: 优化CrudTable插槽传入方式,修复 @0.9.2-2
1 parent a3064ef commit 7853c58

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "element-pro-crud",
3-
"version": "0.9.2-1",
3+
"version": "0.9.2-2",
44
"author": "BoBo<[email protected]>",
55
"main": "lib/ProCrud.umd.min.js",
66
"files": [

Diff for: src/component/crud-table/src/CrudTable.vue

+7-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<slot name="append"></slot>
2828
</template>
2929
<template #btnBarPrevBtn>
30+
<slot name="btnBarPrevBtn" />
3031
<!-- 批量删除按钮 -->
3132
<el-button v-if="view.btnDel" @click="btnDeletesOnClick" type="danger" size="mini" icon="el-icon-delete">{{ text.multiDel }}</el-button>
3233
<!-- 添加按钮 -->
@@ -36,8 +37,9 @@
3637
<template #_action_header v-if="view.btnAddOnColumnHeader">
3738
<el-button icon="el-icon-plus" size="mini" type="primary" style="color:white" @click.stop="btnAdd"></el-button>
3839
</template>
39-
<template #columnFormatter="{row,prop}">
40-
<slot name="columnFormatter" :row="row" :prop="prop"></slot>
40+
<!-- 表格自定义列/表头插槽,动态传入 -->
41+
<template :slot="slotName" slot-scope="scope" v-for="(slotName) in Object.keys(slots).filter(key=> !['btnCustom','append','btnBarPrevBtn','dialogFooter'].includes(key))">
42+
<slot :name="slotName" :row="scope.row" :prop="scope.prop" :column="scope.column"></slot>
4143
</template>
4244
<template slot-scope="scope" slot="actionColumn">
4345
<!-- 操作列-添加按钮 -->
@@ -250,7 +252,7 @@ export default defineComponent({
250252
},
251253
emits: ['form-btn-on-click', 'form-change', 'selection-change'],
252254
setup(props: CrudTableProps, {
253-
listeners, attrs, emit, root,
255+
listeners, attrs, emit, root, slots,
254256
}) {
255257
const {
256258
$PROCRUD, $message, $confirm,
@@ -302,7 +304,7 @@ export default defineComponent({
302304
}
303305
// 操作列是否隐藏
304306
if (!viewObj.actionColumn) {
305-
tableConfig.columns = tableConfig.columns.filter((item: any) => item.slotName !== 'actionColumn');
307+
tableConfig.columns = tableConfig.columns.filter(item => item.slotName !== 'actionColumn');
306308
}
307309

308310
return viewObj;
@@ -611,6 +613,7 @@ export default defineComponent({
611613
text,
612614
request,
613615
treeload,
616+
slots: ref(slots),
614617
};
615618
},
616619
});

Diff for: src/component/pro-table/src/ProTable.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ export default defineComponent({
204204
},
205205
},
206206
emits: ['done', 'selection-change'],
207-
setup(props: ProTableProps, { listeners, emit, attrs }) {
207+
setup(props: ProTableProps, {
208+
listeners, emit, attrs, root, slots,
209+
}) {
208210
// 表格数据总数
209211
const total = ref(0);
210212
// 是否在加载
@@ -404,6 +406,7 @@ export default defineComponent({
404406
fetchHandler(true);
405407
// 自适应分页组件按钮;
406408
window.addEventListener('resize', resizeHandler);
409+
console.log(slots);
407410
});
408411

409412
onBeforeUnmount(() => {

Diff for: src/demo/component/PersonCrudTable.vue

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
<template>
99
<CrudTable ref="table" tableName="person" tableTitle="员工管理" fullHeight orderCondition="timestamp desc" :visibleList="visibleList" v-bind="$attrs" v-on="$listeners">
10+
<template #btnBarPrevBtn>
11+
<el-button size="mini" @click="()=>$alert('btnBarPrevBtn插槽可自定义功能按钮')">自定义功能按钮</el-button>
12+
</template>
1013
<template #columnFormatter="{row,prop}">
1114
<el-tag v-if="prop === 'jobno'">{{ row.jobno }}</el-tag>
1215
<span v-if="prop === 'personname'"><i class="el-icon el-icon-user" style="color: red"></i>{{ row.personname }}</span>

0 commit comments

Comments
 (0)