Skip to content

Commit

Permalink
fix: CrudTable支持传入columns @0.9.2-4
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBoooooo committed Mar 22, 2021
1 parent 805bbff commit 347ea93
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "element-pro-crud",
"version": "0.9.2-3",
"version": "0.9.2-4",
"author": "BoBo<[email protected]>",
"main": "lib/ProCrud.umd.min.js",
"files": [
Expand Down
64 changes: 45 additions & 19 deletions src/component/crud-table/src/CrudTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ import {
columns, DataSource, DML, Params,
} from '@/types/common';
import VueCompositionApi, {
reactive, computed, ref, defineComponent, Ref, watch,
reactive, computed, ref, defineComponent, Ref, watch, PropType,
} from '@vue/composition-api';
import GenerateFormDialog from './GenerateFormDialog.vue';
import ProTable from '../../pro-table';
Expand Down Expand Up @@ -249,6 +249,10 @@ export default defineComponent({
type: Boolean,
default: false,
},
columns: {
type: Object as PropType<columns>,
default: null,
},
},
emits: ['form-btn-on-click', 'form-change', 'selection-change'],
setup(props: CrudTableProps, {
Expand Down Expand Up @@ -314,26 +318,35 @@ export default defineComponent({
const tableReload = () => {
proTableRef.value.tableReload();
};

const { columns: propsColumns } = props;
console.log(propsColumns);
// 如果外侧传入了columns则不发起请求
if (propsColumns) {
tableConfig.columns = propsColumns.columns;
tableConfig.name = propsColumns.name;
tableConfig.position = propsColumns.position;
} else {
// 初始化表格json
const promise = $PROCRUD.getTableDetail(props.tableDesignerName ? props.tableDesignerName : props.tableName);
// 加载表格结构
promise.then((res) => {
const _tableConfig = JSON.parse(res.data.formJson);
// eslint-disable-next-line no-shadow
const { columns, name, position } = _tableConfig;
tableConfig.columns = columns;
tableConfig.name = name;
tableConfig.position = position;
// 如果显示指明了操作列列宽
if (props.actionColumnWidth) {
const actionColumn = tableConfig.columns.find(_ => _.slotName === 'actionColumn');
if (actionColumn) {
actionColumn.width = props.actionColumnWidth;
actionColumn.minWidth = props.actionColumnWidth;
const promise = $PROCRUD.getTableDetail(props.tableDesignerName ? props.tableDesignerName : props.tableName);
// 加载表格结构
promise.then((res) => {
const _tableConfig = JSON.parse(res.data.formJson);
// eslint-disable-next-line no-shadow
const { columns, name, position } = _tableConfig;
tableConfig.columns = columns;
tableConfig.name = name;
tableConfig.position = position;
// 如果显示指明了操作列列宽
if (props.actionColumnWidth) {
const actionColumn = tableConfig.columns.find(_ => _.slotName === 'actionColumn');
if (actionColumn) {
actionColumn.width = props.actionColumnWidth;
actionColumn.minWidth = props.actionColumnWidth;
}
}
}
});
});
}


// 懒加载
const treeload = (tree, treeNode?: any, resolve?: any) => {
Expand Down Expand Up @@ -601,6 +614,19 @@ export default defineComponent({
emit('form-change', val);
},
};

// 监听
watch(
() => props.columns,
(val) => {
// eslint-disable-next-line no-shadow
const { columns, name, position } = val;
tableConfig.columns = columns;
tableConfig.name = name;
tableConfig.position = position;
},
);

return {
tableReload,
...handlerButtonMethods,
Expand Down
1 change: 0 additions & 1 deletion src/component/pro-table/src/ProTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ export default defineComponent({
watch(
() => props.columns,
(val) => {
// 此处语法待优化
// eslint-disable-next-line no-shadow
const { columns, name, position } = val;
tableConfig.columns = columns;
Expand Down
1 change: 0 additions & 1 deletion src/demo/component/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@
tableName="person"
:size="size"
:textMap="textMap"
:columns="columns"
:readOnly="readOnly"
:show-header="showHeader"
:showPagination="showPagination"
Expand Down

0 comments on commit 347ea93

Please sign in to comment.