Skip to content

Commit 347ea93

Browse files
committed
fix: CrudTable支持传入columns @0.9.2-4
1 parent 805bbff commit 347ea93

File tree

4 files changed

+46
-22
lines changed

4 files changed

+46
-22
lines changed

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-3",
3+
"version": "0.9.2-4",
44
"author": "BoBo<[email protected]>",
55
"main": "lib/ProCrud.umd.min.js",
66
"files": [

src/component/crud-table/src/CrudTable.vue

+45-19
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ import {
9292
columns, DataSource, DML, Params,
9393
} from '@/types/common';
9494
import VueCompositionApi, {
95-
reactive, computed, ref, defineComponent, Ref, watch,
95+
reactive, computed, ref, defineComponent, Ref, watch, PropType,
9696
} from '@vue/composition-api';
9797
import GenerateFormDialog from './GenerateFormDialog.vue';
9898
import ProTable from '../../pro-table';
@@ -249,6 +249,10 @@ export default defineComponent({
249249
type: Boolean,
250250
default: false,
251251
},
252+
columns: {
253+
type: Object as PropType<columns>,
254+
default: null,
255+
},
252256
},
253257
emits: ['form-btn-on-click', 'form-change', 'selection-change'],
254258
setup(props: CrudTableProps, {
@@ -314,26 +318,35 @@ export default defineComponent({
314318
const tableReload = () => {
315319
proTableRef.value.tableReload();
316320
};
317-
321+
const { columns: propsColumns } = props;
322+
console.log(propsColumns);
323+
// 如果外侧传入了columns则不发起请求
324+
if (propsColumns) {
325+
tableConfig.columns = propsColumns.columns;
326+
tableConfig.name = propsColumns.name;
327+
tableConfig.position = propsColumns.position;
328+
} else {
318329
// 初始化表格json
319-
const promise = $PROCRUD.getTableDetail(props.tableDesignerName ? props.tableDesignerName : props.tableName);
320-
// 加载表格结构
321-
promise.then((res) => {
322-
const _tableConfig = JSON.parse(res.data.formJson);
323-
// eslint-disable-next-line no-shadow
324-
const { columns, name, position } = _tableConfig;
325-
tableConfig.columns = columns;
326-
tableConfig.name = name;
327-
tableConfig.position = position;
328-
// 如果显示指明了操作列列宽
329-
if (props.actionColumnWidth) {
330-
const actionColumn = tableConfig.columns.find(_ => _.slotName === 'actionColumn');
331-
if (actionColumn) {
332-
actionColumn.width = props.actionColumnWidth;
333-
actionColumn.minWidth = props.actionColumnWidth;
330+
const promise = $PROCRUD.getTableDetail(props.tableDesignerName ? props.tableDesignerName : props.tableName);
331+
// 加载表格结构
332+
promise.then((res) => {
333+
const _tableConfig = JSON.parse(res.data.formJson);
334+
// eslint-disable-next-line no-shadow
335+
const { columns, name, position } = _tableConfig;
336+
tableConfig.columns = columns;
337+
tableConfig.name = name;
338+
tableConfig.position = position;
339+
// 如果显示指明了操作列列宽
340+
if (props.actionColumnWidth) {
341+
const actionColumn = tableConfig.columns.find(_ => _.slotName === 'actionColumn');
342+
if (actionColumn) {
343+
actionColumn.width = props.actionColumnWidth;
344+
actionColumn.minWidth = props.actionColumnWidth;
345+
}
334346
}
335-
}
336-
});
347+
});
348+
}
349+
337350

338351
// 懒加载
339352
const treeload = (tree, treeNode?: any, resolve?: any) => {
@@ -601,6 +614,19 @@ export default defineComponent({
601614
emit('form-change', val);
602615
},
603616
};
617+
618+
// 监听
619+
watch(
620+
() => props.columns,
621+
(val) => {
622+
// eslint-disable-next-line no-shadow
623+
const { columns, name, position } = val;
624+
tableConfig.columns = columns;
625+
tableConfig.name = name;
626+
tableConfig.position = position;
627+
},
628+
);
629+
604630
return {
605631
tableReload,
606632
...handlerButtonMethods,

src/component/pro-table/src/ProTable.vue

-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@ export default defineComponent({
414414
watch(
415415
() => props.columns,
416416
(val) => {
417-
// 此处语法待优化
418417
// eslint-disable-next-line no-shadow
419418
const { columns, name, position } = val;
420419
tableConfig.columns = columns;

src/demo/component/Dashboard.vue

-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@
195195
tableName="person"
196196
:size="size"
197197
:textMap="textMap"
198-
:columns="columns"
199198
:readOnly="readOnly"
200199
:show-header="showHeader"
201200
:showPagination="showPagination"

0 commit comments

Comments
 (0)