diff --git a/shared/components/FastForm/index.tsx b/shared/components/FastForm/index.tsx index 577803f0..ddad647d 100644 --- a/shared/components/FastForm/index.tsx +++ b/shared/components/FastForm/index.tsx @@ -1,4 +1,4 @@ -import React, { useMemo, useState } from 'react'; +import React, { useEffect, useLayoutEffect, useMemo, useState } from 'react'; import { useFormik } from 'formik'; import _isNil from 'lodash/isNil'; import _fromPairs from 'lodash/fromPairs'; @@ -22,6 +22,7 @@ export interface FastFormProps { schema?: ObjectSchema; // yup schame object 用于表单校验 layout?: 'horizontal' | 'vertical'; // 布局方式(默认水平) submitLabel?: string; // 提交按钮的标签名 + initialValues?: any; onSubmit: (values: any) => Promise | void; // 点击提交按钮的回调 onChange?: (values: any) => void; // 数据更新回调 } @@ -32,13 +33,21 @@ export interface FastFormProps { */ export const FastForm: React.FC = React.memo((props) => { const initialValues = useMemo(() => { - return _fromPairs( - props.fields.map((field) => [field.name, field.defaultValue ?? '']) - ); - }, [props.fields]); + return { + ..._fromPairs( + props.fields.map((field) => [field.name, field.defaultValue ?? '']) + ), + ...props.initialValues, + }; + }, [props.fields, props.initialValues]); const [loading, setLoading] = useState(false); + useLayoutEffect(() => { + // 加载时提交一次initialValues + typeof props.onChange === 'function' && props.onChange(initialValues); + }, []); + const formik = useFormik({ initialValues, validationSchema: props.schema, diff --git a/shared/index.tsx b/shared/index.tsx index 283a14a0..965594c7 100644 --- a/shared/index.tsx +++ b/shared/index.tsx @@ -110,6 +110,7 @@ export { applyGroupInvite, modifyGroupField, createGroupPanel, + modifyGroupPanel, deleteGroupPanel, } from './model/group'; export type { GroupPanel, GroupInfo, GroupBasicInfo } from './model/group'; diff --git a/shared/model/group.ts b/shared/model/group.ts index 11faee10..2396f05f 100644 --- a/shared/model/group.ts +++ b/shared/model/group.ts @@ -170,6 +170,27 @@ export async function createGroupPanel( }); } +/** + * 创建群组面板 + */ +export async function modifyGroupPanel( + groupId: string, + panelId: string, + options: { + name: string; + parentId?: string; + provider?: string; + pluginPanelName?: string; + meta?: Record; + } +) { + await request.post('/api/group/modifyGroupPanel', { + ...options, + groupId, + panelId, + }); +} + /** * 删除群组面板 * @param groupId 群组Id diff --git a/web/src/components/modals/GroupDetail/Panel/GroupPanelTree.tsx b/web/src/components/modals/GroupDetail/Panel/GroupPanelTree.tsx index bbf0ce0e..28eb6c63 100644 --- a/web/src/components/modals/GroupDetail/Panel/GroupPanelTree.tsx +++ b/web/src/components/modals/GroupDetail/Panel/GroupPanelTree.tsx @@ -10,6 +10,8 @@ import type { DataNode } from 'antd/lib/tree'; import { buildTreeDataWithGroupPanel } from './utils'; import { Icon } from '@iconify/react'; import { useGroupPanelTreeDrag } from './useGroupPanelTreeDrag'; +import { closeModal, openModal } from '@/components/Modal'; +import { ModalModifyGroupPanel } from '../../GroupPanel/ModifyGroupPanel'; interface GroupPanelTree { groupId: string; @@ -25,6 +27,19 @@ export const GroupPanelTree: React.FC = React.memo((props) => { [props.groupPanels] ); + const handleModifyPanel = useCallback( + (panelId: string) => { + const key = openModal( + closeModal(key)} + /> + ); + }, + [props.groupId] + ); + const handleDeletePanel = useCallback( (panelId: string, panelName: string, isGroup: boolean) => { showAlert({ @@ -47,6 +62,17 @@ export const GroupPanelTree: React.FC = React.memo((props) => {
{node.title}
+