@@ -92,7 +92,7 @@ import {
92
92
columns, DataSource, DML, Params,
93
93
} from '@/types/common';
94
94
import VueCompositionApi, {
95
- reactive, computed, ref, defineComponent, Ref, watch,
95
+ reactive, computed, ref, defineComponent, Ref, watch, PropType,
96
96
} from '@vue/composition-api';
97
97
import GenerateFormDialog from './GenerateFormDialog.vue';
98
98
import ProTable from '../../pro-table';
@@ -249,6 +249,10 @@ export default defineComponent({
249
249
type: Boolean,
250
250
default: false,
251
251
},
252
+ columns: {
253
+ type: Object as PropType<columns>,
254
+ default: null,
255
+ },
252
256
},
253
257
emits: ['form-btn-on-click', 'form-change', 'selection-change'],
254
258
setup(props: CrudTableProps, {
@@ -314,26 +318,35 @@ export default defineComponent({
314
318
const tableReload = () => {
315
319
proTableRef.value.tableReload();
316
320
};
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 {
318
329
// 初始化表格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
+ }
334
346
}
335
- }
336
- });
347
+ });
348
+ }
349
+
337
350
338
351
// 懒加载
339
352
const treeload = (tree, treeNode?: any, resolve?: any) => {
@@ -601,6 +614,19 @@ export default defineComponent({
601
614
emit('form-change', val);
602
615
},
603
616
};
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
+
604
630
return {
605
631
tableReload,
606
632
...handlerButtonMethods,
0 commit comments