mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 09:47:10 +00:00
feat: can set editable fields on tabs
This commit is contained in:
parent
1be960bebf
commit
3f7e8e9c2f
@ -16,11 +16,12 @@ import { Spin } from '@nocobase/client'
|
|||||||
import { fields2columns, components } from '@/components/views/SortableTable'
|
import { fields2columns, components } from '@/components/views/SortableTable'
|
||||||
|
|
||||||
function DraggableTableComponent(props) {
|
function DraggableTableComponent(props) {
|
||||||
const { value, onChange, disabled, rowKey = 'id', fields = [], resourceName, associatedKey, filter, labelField, valueField = 'id', objectValue, placeholder } = props;
|
const { mode = 'showInDetail', value, onChange, disabled, rowKey = 'id', fields = [], resourceName, associatedKey, filter, labelField, valueField = 'id', objectValue, placeholder } = props;
|
||||||
const { data = [], loading = true, mutate } = useRequest(() => {
|
const { data = [], loading = true, mutate } = useRequest(() => {
|
||||||
return api.resource(resourceName).list({
|
return api.resource(resourceName).list({
|
||||||
associatedKey,
|
associatedKey,
|
||||||
filter,
|
filter,
|
||||||
|
perPage: -1,
|
||||||
});
|
});
|
||||||
}, {
|
}, {
|
||||||
refreshDeps: [resourceName, associatedKey]
|
refreshDeps: [resourceName, associatedKey]
|
||||||
@ -34,7 +35,9 @@ function DraggableTableComponent(props) {
|
|||||||
selectedRowKeys: Array.isArray(value) ? value : data.map(item => item[rowKey]),
|
selectedRowKeys: Array.isArray(value) ? value : data.map(item => item[rowKey]),
|
||||||
onChange: onTableChange,
|
onChange: onTableChange,
|
||||||
}
|
}
|
||||||
const dataSource = data.filter(item => get(item, ['component', 'showInDetail']));
|
const dataSource = data.filter(item => {
|
||||||
|
return get(item, ['component', mode])
|
||||||
|
});
|
||||||
// const sortIds = get(value, 'sort')||[];
|
// const sortIds = get(value, 'sort')||[];
|
||||||
// let values = [];
|
// let values = [];
|
||||||
// sortIds.forEach(id => {
|
// sortIds.forEach(id => {
|
||||||
|
@ -42,7 +42,7 @@ export const DrawerForm = forwardRef((props: any, ref) => {
|
|||||||
const [form, setForm] = useState<any>({});
|
const [form, setForm] = useState<any>({});
|
||||||
const [changed, setChanged] = useState(false);
|
const [changed, setChanged] = useState(false);
|
||||||
console.log(associatedKey);
|
console.log(associatedKey);
|
||||||
const { title, actionDefaultParams = {}, fields: properties ={} } = props.schema||{};
|
const { title, actionDefaultParams = {}, fields = {} } = props.schema||{};
|
||||||
const [resourceKey, setResourceKey] = useState(props.resourceKey);
|
const [resourceKey, setResourceKey] = useState(props.resourceKey);
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const name = associatedName ? `${associatedName}.${resourceName}` : resourceName;
|
const name = associatedName ? `${associatedName}.${resourceName}` : resourceName;
|
||||||
@ -60,7 +60,17 @@ export const DrawerForm = forwardRef((props: any, ref) => {
|
|||||||
setVisible,
|
setVisible,
|
||||||
getData: run,
|
getData: run,
|
||||||
}));
|
}));
|
||||||
|
const { displayFormFields = [] } = activeTab;
|
||||||
|
const properties: any ={};
|
||||||
|
for (const key in fields) {
|
||||||
|
if (Object.prototype.hasOwnProperty.call(fields, key)) {
|
||||||
|
const field = fields[key];
|
||||||
|
if (Array.isArray(displayFormFields) && displayFormFields.length && displayFormFields.indexOf(field.id) === -1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
properties[key] = field;
|
||||||
|
}
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<Drawer
|
<Drawer
|
||||||
{...props}
|
{...props}
|
||||||
|
@ -79,6 +79,11 @@ export default {
|
|||||||
target: "displayFields",
|
target: "displayFields",
|
||||||
condition: "{{ $self.value === 'details' }}",
|
condition: "{{ $self.value === 'details' }}",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: "value:visible",
|
||||||
|
target: "displayFormFields",
|
||||||
|
condition: "{{ $self.value === 'details' }}",
|
||||||
|
},
|
||||||
// {
|
// {
|
||||||
// type: "value:schema",
|
// type: "value:schema",
|
||||||
// target: "association",
|
// target: "association",
|
||||||
@ -99,6 +104,16 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: "value:schema",
|
||||||
|
target: "displayFormFields",
|
||||||
|
condition: "{{ $self.value === 'details' }}",
|
||||||
|
schema: {
|
||||||
|
"x-component-props": {
|
||||||
|
associatedKey: "{{ $form.values && $form.values.associatedKey }}"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: "value:schema",
|
type: "value:schema",
|
||||||
target: "associationField",
|
target: "associationField",
|
||||||
@ -176,7 +191,7 @@ export default {
|
|||||||
interface: 'json',
|
interface: 'json',
|
||||||
type: 'json',
|
type: 'json',
|
||||||
name: 'displayFields',
|
name: 'displayFields',
|
||||||
title: '显示的字段',
|
title: '显示在详情中的字段',
|
||||||
labelField: 'title',
|
labelField: 'title',
|
||||||
// valueField: 'name',
|
// valueField: 'name',
|
||||||
component: {
|
component: {
|
||||||
@ -187,7 +202,44 @@ export default {
|
|||||||
resourceName: 'collections.fields',
|
resourceName: 'collections.fields',
|
||||||
labelField: 'title',
|
labelField: 'title',
|
||||||
valueField: 'name',
|
valueField: 'name',
|
||||||
showInDetail: true,
|
mode: 'showInDetail',
|
||||||
|
fields: [
|
||||||
|
// {
|
||||||
|
// interface: 'sort',
|
||||||
|
// name: 'sort',
|
||||||
|
// title: '排序',
|
||||||
|
// type: 'sort',
|
||||||
|
// dataIndex: ['sort'],
|
||||||
|
// className: 'drag-visible',
|
||||||
|
// },
|
||||||
|
{
|
||||||
|
interface: 'string',
|
||||||
|
name: 'title',
|
||||||
|
title: '字段名称',
|
||||||
|
type: 'string',
|
||||||
|
className: 'drag-visible',
|
||||||
|
dataIndex: ['title'],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
interface: 'json',
|
||||||
|
type: 'json',
|
||||||
|
name: 'displayFormFields',
|
||||||
|
title: '当前标签页可编辑字段',
|
||||||
|
labelField: 'title',
|
||||||
|
// valueField: 'name',
|
||||||
|
component: {
|
||||||
|
type: 'draggableTable',
|
||||||
|
showInDetail: true,
|
||||||
|
showInForm: true,
|
||||||
|
'x-component-props': {
|
||||||
|
resourceName: 'collections.fields',
|
||||||
|
labelField: 'title',
|
||||||
|
valueField: 'name',
|
||||||
|
mode: 'showInForm',
|
||||||
fields: [
|
fields: [
|
||||||
// {
|
// {
|
||||||
// interface: 'sort',
|
// interface: 'sort',
|
||||||
|
@ -145,6 +145,7 @@ const transforms = {
|
|||||||
prop.enum = field.get('dataSource');
|
prop.enum = field.get('dataSource');
|
||||||
}
|
}
|
||||||
schema[field.name] = {
|
schema[field.name] = {
|
||||||
|
id: field.id,
|
||||||
...prop,
|
...prop,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user