From 9b73e2a7d3fd7ccd0f645a34062fb8e35d241cc5 Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 9 Dec 2020 20:46:57 +0800 Subject: [PATCH] feat: improve fields & views tables options --- packages/plugin-collections/package.json | 3 +- .../src/collections/fields.ts | 105 ++++++++++++++++-- .../src/collections/views.ts | 38 ++++++- packages/plugin-pages/src/actions/getView.ts | 3 + 4 files changed, 135 insertions(+), 14 deletions(-) diff --git a/packages/plugin-collections/package.json b/packages/plugin-collections/package.json index 934411ff09..965329c480 100644 --- a/packages/plugin-collections/package.json +++ b/packages/plugin-collections/package.json @@ -6,7 +6,8 @@ "dependencies": { "@nocobase/database": "^0.3.0-alpha.0", "@nocobase/resourcer": "^0.3.0-alpha.0", - "@nocobase/server": "^0.3.0-alpha.0" + "@nocobase/server": "^0.3.0-alpha.0", + "deepmerge": "^4.2.2" }, "devDependencies": { "@nocobase/actions": "^0.3.0-alpha.0" diff --git a/packages/plugin-collections/src/collections/fields.ts b/packages/plugin-collections/src/collections/fields.ts index c326a12c55..3612d7ee79 100644 --- a/packages/plugin-collections/src/collections/fields.ts +++ b/packages/plugin-collections/src/collections/fields.ts @@ -54,11 +54,39 @@ export default { name: 'interface', title: '字段类型', dataSource: options, + createOnly: true, component: { type: 'select', showInTable: true, showInDetail: true, showInForm: true, + "x-linkages": [ + { + "type": "value:visible", + "target": "precision", + "condition": "{{ ['number', 'percent'].indexOf($self.value) !== -1 }}" + }, + { + "type": "value:visible", + "target": "dataSource", + "condition": "{{ ['select', 'multipleSelect', 'radio', 'checkboxes'].indexOf($self.value) !== -1 }}" + }, + { + "type": "value:visible", + "target": "dateFormat", + "condition": "{{ ['datetime', 'createdAt', 'updatedAt'].indexOf($self.value) !== -1 }}" + }, + { + "type": "value:visible", + "target": "showTime", + "condition": "{{ ['datetime', 'createdAt', 'updatedAt'].indexOf($self.value) !== -1 }}" + }, + { + "type": "value:visible", + "target": "timeFormat", + "condition": "{{ ['time', 'datetime', 'createdAt', 'updatedAt'].indexOf($self.value) !== -1 }}" + }, + ], }, }, { @@ -110,6 +138,70 @@ export default { type: 'number', }, }, + { + interface: 'select', + type: 'virtual', + name: 'precision', + title: '精度', + defaultValue: 0, + dataSource: [ + {value: 0, label: '1'}, + {value: 1, label: '1.0'}, + {value: 2, label: '1.00'}, + {value: 3, label: '1.000'}, + {value: 4, label: '1.0000'}, + ], + component: { + type: 'number', + showInForm: true, + }, + }, + { + interface: 'select', + type: 'virtual', + name: 'dateFormat', + title: '日期格式', + defaultValue: 'YYYY-MM-DD', + dataSource: [ + {value: 'YYYY-MM-DD', label: 'YYYY-MM-DD'}, + ], + component: { + type: 'string', + showInForm: true, + }, + }, + { + interface: 'boolean', + type: 'virtual', + name: 'showTime', + title: '显示时间', + defaultValue: false, + component: { + type: 'boolean', + showInForm: true, + "x-linkages": [ + { + "type": "value:visible", + "target": "timeFormat", + "condition": "{{ ($form.values && $form.values.interface === 'time') || $self.value === true }}" + }, + ], + }, + }, + { + interface: 'select', + type: 'virtual', + name: 'timeFormat', + title: '时间格式', + defaultValue: 'HH:mm:ss', + dataSource: [ + { value: 'HH:mm:ss', label: 'HH:mm:ss' }, + ], + component: { + type: 'string', + showInForm: true, + }, + }, { interface: 'linkTo', multiple: false, @@ -137,7 +229,7 @@ export default { }, }, { - interface: 'string', + interface: 'textarea', type: 'virtual', name: 'component.tooltip', title: '提示信息', @@ -209,17 +301,6 @@ export default { type: 'drawerSelect', }, }, - { - interface: 'boolean', - type: 'virtual', - name: 'showTime', - title: '显示时间', - defaultValue: false, - component: { - type: 'boolean', - showInForm: true, - }, - }, { interface: 'boolean', type: 'boolean', diff --git a/packages/plugin-collections/src/collections/views.ts b/packages/plugin-collections/src/collections/views.ts index 941bff11d3..1843cde7b4 100644 --- a/packages/plugin-collections/src/collections/views.ts +++ b/packages/plugin-collections/src/collections/views.ts @@ -51,6 +51,7 @@ export default { title: '视图类型', dataSource: [ { label: '表格', value: 'table' }, + { label: '表单', value: 'form' }, { label: '看板', value: 'kanban', disabled: true }, { label: '日历', value: 'calendar', disabled: true }, { label: '地图', value: 'map', disabled: true }, @@ -63,10 +64,15 @@ export default { }, }, { - interface: 'string', + interface: 'select', type: 'string', name: 'template', title: '模板', + dataSource: [ + { label: '表单', value: 'DrawerForm' }, + { label: '常规表格', value: 'Table' }, + { label: '简易表格', value: 'SimpleTable' }, + ], component: { type: 'string', showInTable: true, @@ -74,6 +80,36 @@ export default { showInForm: true, }, }, + { + interface: 'radio', + type: 'virtual', + name: 'defaultPerPage', + title: '每页显示几行数据', + defaultValue: 50, + dataSource: [ + {label: '20', value: 20}, + {label: '50', value: 50}, + {label: '100', value: 100}, + ], + component: { + type: 'radio', + showInForm: true, + showInDetail: true, + }, + }, + { + interface: 'boolean', + type: 'virtual', + name: 'draggable', + title: '支持拖拽数据排序', + showInForm: true, + showInDetail: true, + component: { + type: 'checkbox', + showInForm: true, + showInDetail: true, + }, + }, { interface: 'boolean', type: 'boolean', diff --git a/packages/plugin-pages/src/actions/getView.ts b/packages/plugin-pages/src/actions/getView.ts index 240a0576aa..dfbf06cebb 100644 --- a/packages/plugin-pages/src/actions/getView.ts +++ b/packages/plugin-pages/src/actions/getView.ts @@ -37,6 +37,9 @@ const transforms = { if (mode === 'update' && field.get('createOnly')) { set(prop, 'x-component-props.disabled', true); } + if (typeof field.get('showTime') === 'boolean') { + set(prop, 'x-component-props.showTime', field.get('showTime')); + } const defaultValue = get(field.options, 'defaultValue'); if (defaultValue) { prop.default = defaultValue;