mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 12:06:47 +00:00
feat: improve code
This commit is contained in:
parent
08fcee6d90
commit
982c7a3038
@ -4,10 +4,23 @@ import { useMenuItems } from '.';
|
||||
import { useAPIClient, useRequest } from '../../api-client';
|
||||
import { useRecord } from '../../record-provider';
|
||||
|
||||
const findUids = (items) => {
|
||||
if (!Array.isArray(items)) {
|
||||
return [];
|
||||
}
|
||||
const uids = [];
|
||||
for (const item of items) {
|
||||
uids.push(item.uid);
|
||||
uids.push(...findUids(item.children));
|
||||
}
|
||||
return uids;
|
||||
};
|
||||
|
||||
export const MenuConfigure = () => {
|
||||
const record = useRecord();
|
||||
const api = useAPIClient();
|
||||
const items = useMenuItems();
|
||||
const allUids = findUids(items);
|
||||
const [uids, setUids] = useState([]);
|
||||
const { loading, refresh } = useRequest(
|
||||
{
|
||||
@ -25,7 +38,7 @@ export const MenuConfigure = () => {
|
||||
},
|
||||
);
|
||||
const resource = api.resource('roles.menuUiSchemas', record.name);
|
||||
const allChecked = items.length === uids.length;
|
||||
const allChecked = allUids.length === uids.length;
|
||||
return (
|
||||
<Table
|
||||
loading={loading}
|
||||
@ -52,7 +65,7 @@ export const MenuConfigure = () => {
|
||||
});
|
||||
} else {
|
||||
await resource.set({
|
||||
values: items.map((item) => item.uid),
|
||||
values: allUids,
|
||||
});
|
||||
}
|
||||
refresh();
|
||||
@ -62,7 +75,8 @@ export const MenuConfigure = () => {
|
||||
允许访问
|
||||
</>
|
||||
),
|
||||
render: (checked, schema) => {
|
||||
render: (_, schema) => {
|
||||
const checked = uids.includes(schema.uid);
|
||||
return (
|
||||
<Checkbox
|
||||
checked={checked}
|
||||
@ -86,10 +100,7 @@ export const MenuConfigure = () => {
|
||||
},
|
||||
},
|
||||
]}
|
||||
dataSource={items.map((item) => {
|
||||
const accessible = uids.includes(item.uid);
|
||||
return { ...item, accessible };
|
||||
})}
|
||||
dataSource={items}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { css } from '@emotion/css';
|
||||
import { observer, RecursionField, useField, useFieldSchema } from '@formily/react';
|
||||
import { Modal } from 'antd';
|
||||
import classNames from 'classnames';
|
||||
import React from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { useActionContext } from '.';
|
||||
@ -27,8 +28,18 @@ export const ActionModal: ComposedActionDrawer = observer((props) => {
|
||||
destroyOnClose
|
||||
visible={visible}
|
||||
onCancel={() => setVisible(false)}
|
||||
className={classNames(
|
||||
others.className,
|
||||
css`
|
||||
&.nb-action-popup {
|
||||
.ant-modal-body {
|
||||
background: #f0f2f5;
|
||||
}
|
||||
}
|
||||
`,
|
||||
)}
|
||||
footer={
|
||||
footerSchema && (
|
||||
footerSchema ? (
|
||||
<div
|
||||
className={css`
|
||||
display: flex;
|
||||
@ -48,6 +59,8 @@ export const ActionModal: ComposedActionDrawer = observer((props) => {
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
false
|
||||
)
|
||||
}
|
||||
>
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { css } from '@emotion/css';
|
||||
import { FormLayout } from '@formily/antd';
|
||||
import { observer, RecursionField, useFieldSchema } from '@formily/react';
|
||||
import { Card } from 'antd';
|
||||
@ -27,6 +28,18 @@ export const KanbanCard: any = observer((props: any) => {
|
||||
hoverable
|
||||
style={{ cursor: 'pointer', overflow: 'hidden' }}
|
||||
bodyStyle={{ paddingBottom: 0 }}
|
||||
className={css`
|
||||
.ant-description-input {
|
||||
text-overflow: ellipsis;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
.ant-description-textarea {
|
||||
text-overflow: ellipsis;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
`}
|
||||
>
|
||||
<SchemaComponentOptions components={{}}>
|
||||
<DndContext
|
||||
|
@ -123,6 +123,7 @@ Upload.Attachment = connect((props: UploadProps) => {
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{!disabled && (multiple || toArr(value).length < 1) && (
|
||||
<div className={'ant-upload-list-picture-card-container'}>
|
||||
<AntdUpload
|
||||
{...useUploadProps({ ...props })}
|
||||
@ -157,6 +158,7 @@ Upload.Attachment = connect((props: UploadProps) => {
|
||||
)}
|
||||
</AntdUpload>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{visible && (
|
||||
|
@ -80,7 +80,7 @@ export const DragHandler = (props) => {
|
||||
{...listeners}
|
||||
{...attributes}
|
||||
>
|
||||
<span style={{ cursor: 'move', fontSize: 12 }}>{props.children}</span>
|
||||
<span style={{ cursor: 'move', fontSize: 14 }}>{props.children}</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user