Complete main UI #37

Merged
FatttSnake merged 192 commits from FatttSnake into dev 2024-02-23 16:31:17 +08:00
5 changed files with 48 additions and 16 deletions
Showing only changes of commit bf8f915b15 - Show all commits

View File

@@ -11,6 +11,7 @@ import {
DATABASE_UPDATE_SUCCESS
} from '@/constants/common.constants'
import { utcToLocalTime } from '@/utils/common'
import { useUpdatedEffect } from '@/utils/hooks'
import {
r_sys_group_add,
r_sys_group_change_status,
@@ -174,6 +175,9 @@ const Group: React.FC = () => {
form.setFieldValue('name', newFormValues?.name)
form.setFieldValue('roleIds', newFormValues?.roleIds)
form.setFieldValue('enable', newFormValues?.enable ?? true)
if (!roleData || !roleData.length) {
getRoleData()
}
}
const handleOnListDeleteBtnClick = () => {
@@ -220,6 +224,9 @@ const Group: React.FC = () => {
value.roles.map((role) => role.id)
)
form.setFieldValue('enable', value.enable)
if (!roleData || !roleData.length) {
getRoleData()
}
void form.validateFields()
}
}
@@ -469,11 +476,7 @@ const Group: React.FC = () => {
}
}, [formValues])
useEffect(() => {
getRoleData()
}, [])
useEffect(() => {
useUpdatedEffect(() => {
getGroup()
}, [
JSON.stringify(tableParams.filters),

View File

@@ -6,6 +6,7 @@ import {
DATABASE_SELECT_SUCCESS
} from '@/constants/common.constants'
import { dayjsToUtc, utcToLocalTime } from '@/utils/common'
import { useUpdatedEffect } from '@/utils/hooks'
import { r_sys_log_get } from '@/services/system'
import FitFullScreen from '@/components/common/FitFullScreen'
import Card from '@/components/common/Card'
@@ -256,7 +257,7 @@ const Log: React.FC = () => {
})
}
useEffect(() => {
useUpdatedEffect(() => {
getLog()
}, [
JSON.stringify(tableParams.filters),

View File

@@ -11,6 +11,7 @@ import {
DATABASE_UPDATE_SUCCESS
} from '@/constants/common.constants'
import { utcToLocalTime, powerListToPowerTree } from '@/utils/common'
import { useUpdatedEffect } from '@/utils/hooks'
import {
r_sys_role_add,
r_sys_role_change_status,
@@ -166,6 +167,9 @@ const Role: React.FC = () => {
form.setFieldValue('name', newFormValues?.name)
form.setFieldValue('powerIds', newFormValues?.powerIds)
form.setFieldValue('enable', newFormValues?.enable ?? true)
if (!powerTreeData || !powerTreeData.length) {
getPowerTreeData()
}
}
const handleOnListDeleteBtnClick = () => {
@@ -212,6 +216,9 @@ const Role: React.FC = () => {
value.operations.map((operation) => operation.id)
)
form.setFieldValue('enable', value.enable)
if (!powerTreeData || !powerTreeData.length) {
getPowerTreeData()
}
void form.validateFields()
}
}
@@ -478,11 +485,7 @@ const Role: React.FC = () => {
}
}, [formValues])
useEffect(() => {
getPowerTreeData()
}, [])
useEffect(() => {
useUpdatedEffect(() => {
getRole()
}, [
JSON.stringify(tableParams.filters),

View File

@@ -12,6 +12,7 @@ import {
DATABASE_UPDATE_SUCCESS
} from '@/constants/common.constants'
import { utcToLocalTime, isPastTime, localTimeToUtc, dayjsToUtc, getNowUtc } from '@/utils/common'
import { useUpdatedEffect } from '@/utils/hooks'
import {
r_sys_group_get_list,
r_sys_role_get_list,
@@ -259,6 +260,12 @@ const User: React.FC = () => {
form.setFieldValue('roleIds', newFormValues?.roleIds)
form.setFieldValue('groupIds', newFormValues?.groupIds)
if (!roleData || !roleData.length) {
getRoleData()
}
if (!groupData || !groupData.length) {
getGroupData()
}
getAvatar()
}
@@ -429,6 +436,12 @@ const User: React.FC = () => {
'groupIds',
value.groups.map((group) => group.id)
)
if (!roleData || !roleData.length) {
getRoleData()
}
if (!groupData || !groupData.length) {
getGroupData()
}
void form.validateFields()
}
}
@@ -718,11 +731,7 @@ const User: React.FC = () => {
}
}, [formValues])
useEffect(() => {
handleOnDrawerRefresh()
}, [])
useEffect(() => {
useUpdatedEffect(() => {
getUser()
}, [
JSON.stringify(tableParams.filters),

16
src/utils/hooks.tsx Normal file
View File

@@ -0,0 +1,16 @@
import React from 'react'
export const useUpdatedEffect = (
effect: React.EffectCallback,
dependencies: React.DependencyList
) => {
const isFirstRender = useRef(true)
useEffect(() => {
if (isFirstRender.current) {
isFirstRender.current = false
} else {
effect()
}
}, dependencies)
}