diff --git a/config/defaultSettings.ts b/config/defaultSettings.ts index 754152f..dfe725a 100644 --- a/config/defaultSettings.ts +++ b/config/defaultSettings.ts @@ -19,8 +19,7 @@ const Settings: ProLayoutProps & { pwa: true, logo: '/logo.svg', iconfontUrl: '', - splitMenus: true, - + // splitMenus: true, token: { // 参见ts声明,demo 见文档,通过token 修改样式 // 设置内容区域的边距 diff --git a/src/app.tsx b/src/app.tsx index 74f7407..83e48a5 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -45,6 +45,7 @@ export async function getInitialState(): Promise<{ throw new Error('No token found'); } const data = await getInfo(); + console.log(data, 'data'); wsCache.set(CACHE_KEY.USER, data); wsCache.set(CACHE_KEY.ROLE_ROUTERS, data.menus); @@ -73,7 +74,6 @@ export async function getInitialState(): Promise<{ await fetchUserInfo(); } const menus = wsCache.get(CACHE_KEY.ROLE_ROUTERS); - console.log(111); return { fetchUserInfo, currentUser, @@ -93,27 +93,14 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState, }) => { - const { wsCache } = useCache(); return { actionsRender: () => [ , , ], + menu: { locale: false, - // 关闭国际化- - // request: async () => { - // const currentUser = wsCache.get(CACHE_KEY.USER); - - // console.log("菜单请求被调用", initialState?.menus, currentUser); - // if (currentUser.menus) { - // const menuData = loopMenuItem(currentUser.menus); - // // console.log('转换后的菜单数据:', menuData); - // // const r = loopMenuItem(currentUser.menus); - // return menuData; - // } - // return []; - // }, }, avatarProps: { src: initialState?.currentUser?.user.avatar, @@ -159,8 +146,8 @@ export const layout: RunTimeLayoutConfig = ({ useRoutes: true, }, menuHeaderRender: undefined, - // 自定义 403 页面 - unAccessible:
unAccessible
, + // // 自定义 403 页面 + // unAccessible:
unAccessible
, // 增加一个 loading 的状态 childrenRender: (children) => { // if (initialState?.loading) return ; diff --git a/src/components/GroupTag/GroupTagCore.tsx b/src/components/GroupTag/GroupTagCore.tsx index 9c150ac..b5c98f4 100644 --- a/src/components/GroupTag/GroupTagCore.tsx +++ b/src/components/GroupTag/GroupTagCore.tsx @@ -36,6 +36,7 @@ const GroupTagCore: React.FC = (props) => { const [currentId, setCurrentId] = useState(); const [tagsModalValue, setTagsModalValue] = useState<{ tagName?: string; + groupName?: string; groupIds?: number[]; id?: number; }>({}); @@ -86,7 +87,7 @@ const GroupTagCore: React.FC = (props) => { useEffect(() => { if (modalType === 'edit' && visible) { if (type === 'group' && currentGroup) { - setName(currentGroup.groupName); + setName(currentGroup.groupName || ''); } else if (type === 'tag' && tagsModalValue) { setName(tagsModalValue.tagName || ''); } @@ -95,12 +96,16 @@ const GroupTagCore: React.FC = (props) => { setName(''); } }, [type, modalType, currentGroup, tagsModalValue, visible]); - const handleGroup = (type: 'add' | 'edit' | 'delete') => { + const handleGroup = (type: 'add' | 'edit' | 'delete', group?: GroupItem) => { setType('group'); setModalType(type); if (type === 'add' || type === 'edit') { setVisible(true); } + if (type === 'edit') { + console.log('group', group); + setTagsModalValue({ groupName: group?.groupName, id: group?.id }); + } }; const handleTag = (type: 'add' | 'edit' | 'delete', tag?: TagItem) => { @@ -115,9 +120,8 @@ const GroupTagCore: React.FC = (props) => { }; const handleAdd = async (value: { - groupName?: string; groupIds?: number[]; - tagName?: string; + groupName?: string; }) => { if (type === 'group') { const id = await groupsApi.create({ groupName: value.groupName }); @@ -132,15 +136,18 @@ const GroupTagCore: React.FC = (props) => { const handleEdit = async (value: { tagName?: string; + groupName?: string; groupIds?: number[]; }) => { if (type === 'group') { try { - setLoading(true); - await groupsApi.update({ id: currentGroup?.id, groupName: name }); + await groupsApi.update({ + id: currentGroup?.id, + groupName: value.groupName, + }); const newData = groups.map((item) => { if (item.id === currentGroup?.id) { - const itemData = { ...item, groupName: name }; + const itemData = { ...item, groupName: value.groupName }; setCurrentGroup(itemData); return itemData; } else { @@ -148,8 +155,8 @@ const GroupTagCore: React.FC = (props) => { } }); setGroups(newData); - } finally { - setLoading(false); + } catch (error) { + message.success('修改失败'); } } else { await tagsApi.update({ @@ -157,7 +164,7 @@ const GroupTagCore: React.FC = (props) => { id: tagsModalValue?.id, ...value, }); - message.success('修改成功'); + const newTag = currentGroup?.tags?.map((tag) => { if (tag.id === tagsModalValue?.id) { return { ...tag, tagName: value.tagName }; @@ -170,6 +177,7 @@ const GroupTagCore: React.FC = (props) => { setCurrentGroup(newGroup as GroupItem); } setVisible(false); + message.success('修改成功'); }; const handleDelete = async (type: 'group' | 'tag', id: number) => { @@ -187,7 +195,7 @@ const GroupTagCore: React.FC = (props) => { }; const handleConfirm = useCallback( - async (value: { tagName?: string; groupIds?: number[] }) => { + async (value: { groupIds?: number[]; name?: string }) => { if (modalType === 'add') { await handleAdd(value); } @@ -201,6 +209,7 @@ const GroupTagCore: React.FC = (props) => { const handleCancle = useCallback(() => { setVisible(false); + setTagsModalValue({}); }, [visible]); const onTagItemChange = (tag: TagItem, e: CheckboxChangeEvent) => { @@ -284,7 +293,7 @@ const GroupTagCore: React.FC = (props) => { groups, currentId, onGroupClick, - onEdit: () => handleGroup('edit'), + onEdit: (groud) => handleGroup('edit', groud), onDelete: (id) => handleDelete('group', id), })} diff --git a/src/components/GroupTag/TagsModal.tsx b/src/components/GroupTag/TagsModal.tsx index ee5adaa..1f3cef3 100644 --- a/src/components/GroupTag/TagsModal.tsx +++ b/src/components/GroupTag/TagsModal.tsx @@ -6,14 +6,17 @@ interface TagsModalProps { type: 'group' | 'tag'; modalType?: 'add' | 'edit' | 'delete'; onCancel: () => void; - groups: { id: number; groupName: string }[]; + groups: { id?: number; groupName?: string }[]; value: { id?: number; tagName?: string; groupIds?: number[]; groupName?: string; }; - onConfirm: (values: { tagName: string; groupIds?: number[] }) => void; + onConfirm: ( + values: { groupIds?: number[]; name: string }, + type: 'group' | 'tag', + ) => void; } const TagsModal = (props: TagsModalProps) => { const [form] = Form.useForm(); @@ -32,7 +35,7 @@ const TagsModal = (props: TagsModalProps) => { try { setLoading(true); const values = await form.validateFields(); - await onConfirm(values); + await onConfirm(values, type); } finally { setLoading(false); } diff --git a/src/components/GroupTag/component.tsx b/src/components/GroupTag/component.tsx index 47d96f6..ea6f16d 100644 --- a/src/components/GroupTag/component.tsx +++ b/src/components/GroupTag/component.tsx @@ -19,7 +19,7 @@ interface GroupsProps { total?: number; loadMoreData?: () => void; pageSize?: number; - onEdit?: () => void; + onEdit?: (group: GroupItem) => void; onDelete?: (id: number) => void; } export const renderGroups = (data: GroupsProps) => { @@ -67,7 +67,7 @@ export const renderGroups = (data: GroupsProps) => { icon={} onClick={(e) => { e.stopPropagation(); - onEdit?.(); + onEdit?.(item); }} />