Complete main UI #37
@@ -11,6 +11,7 @@ import {
|
|||||||
DATABASE_UPDATE_SUCCESS
|
DATABASE_UPDATE_SUCCESS
|
||||||
} from '@/constants/common.constants'
|
} from '@/constants/common.constants'
|
||||||
import { utcToLocalTime } from '@/utils/common'
|
import { utcToLocalTime } from '@/utils/common'
|
||||||
|
import { useUpdatedEffect } from '@/utils/hooks'
|
||||||
import {
|
import {
|
||||||
r_sys_group_add,
|
r_sys_group_add,
|
||||||
r_sys_group_change_status,
|
r_sys_group_change_status,
|
||||||
@@ -174,6 +175,9 @@ const Group: React.FC = () => {
|
|||||||
form.setFieldValue('name', newFormValues?.name)
|
form.setFieldValue('name', newFormValues?.name)
|
||||||
form.setFieldValue('roleIds', newFormValues?.roleIds)
|
form.setFieldValue('roleIds', newFormValues?.roleIds)
|
||||||
form.setFieldValue('enable', newFormValues?.enable ?? true)
|
form.setFieldValue('enable', newFormValues?.enable ?? true)
|
||||||
|
if (!roleData || !roleData.length) {
|
||||||
|
getRoleData()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleOnListDeleteBtnClick = () => {
|
const handleOnListDeleteBtnClick = () => {
|
||||||
@@ -220,6 +224,9 @@ const Group: React.FC = () => {
|
|||||||
value.roles.map((role) => role.id)
|
value.roles.map((role) => role.id)
|
||||||
)
|
)
|
||||||
form.setFieldValue('enable', value.enable)
|
form.setFieldValue('enable', value.enable)
|
||||||
|
if (!roleData || !roleData.length) {
|
||||||
|
getRoleData()
|
||||||
|
}
|
||||||
void form.validateFields()
|
void form.validateFields()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -469,11 +476,7 @@ const Group: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [formValues])
|
}, [formValues])
|
||||||
|
|
||||||
useEffect(() => {
|
useUpdatedEffect(() => {
|
||||||
getRoleData()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
getGroup()
|
getGroup()
|
||||||
}, [
|
}, [
|
||||||
JSON.stringify(tableParams.filters),
|
JSON.stringify(tableParams.filters),
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
DATABASE_SELECT_SUCCESS
|
DATABASE_SELECT_SUCCESS
|
||||||
} from '@/constants/common.constants'
|
} from '@/constants/common.constants'
|
||||||
import { dayjsToUtc, utcToLocalTime } from '@/utils/common'
|
import { dayjsToUtc, utcToLocalTime } from '@/utils/common'
|
||||||
|
import { useUpdatedEffect } from '@/utils/hooks'
|
||||||
import { r_sys_log_get } from '@/services/system'
|
import { r_sys_log_get } from '@/services/system'
|
||||||
import FitFullScreen from '@/components/common/FitFullScreen'
|
import FitFullScreen from '@/components/common/FitFullScreen'
|
||||||
import Card from '@/components/common/Card'
|
import Card from '@/components/common/Card'
|
||||||
@@ -256,7 +257,7 @@ const Log: React.FC = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useUpdatedEffect(() => {
|
||||||
getLog()
|
getLog()
|
||||||
}, [
|
}, [
|
||||||
JSON.stringify(tableParams.filters),
|
JSON.stringify(tableParams.filters),
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
DATABASE_UPDATE_SUCCESS
|
DATABASE_UPDATE_SUCCESS
|
||||||
} from '@/constants/common.constants'
|
} from '@/constants/common.constants'
|
||||||
import { utcToLocalTime, powerListToPowerTree } from '@/utils/common'
|
import { utcToLocalTime, powerListToPowerTree } from '@/utils/common'
|
||||||
|
import { useUpdatedEffect } from '@/utils/hooks'
|
||||||
import {
|
import {
|
||||||
r_sys_role_add,
|
r_sys_role_add,
|
||||||
r_sys_role_change_status,
|
r_sys_role_change_status,
|
||||||
@@ -166,6 +167,9 @@ const Role: React.FC = () => {
|
|||||||
form.setFieldValue('name', newFormValues?.name)
|
form.setFieldValue('name', newFormValues?.name)
|
||||||
form.setFieldValue('powerIds', newFormValues?.powerIds)
|
form.setFieldValue('powerIds', newFormValues?.powerIds)
|
||||||
form.setFieldValue('enable', newFormValues?.enable ?? true)
|
form.setFieldValue('enable', newFormValues?.enable ?? true)
|
||||||
|
if (!powerTreeData || !powerTreeData.length) {
|
||||||
|
getPowerTreeData()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleOnListDeleteBtnClick = () => {
|
const handleOnListDeleteBtnClick = () => {
|
||||||
@@ -212,6 +216,9 @@ const Role: React.FC = () => {
|
|||||||
value.operations.map((operation) => operation.id)
|
value.operations.map((operation) => operation.id)
|
||||||
)
|
)
|
||||||
form.setFieldValue('enable', value.enable)
|
form.setFieldValue('enable', value.enable)
|
||||||
|
if (!powerTreeData || !powerTreeData.length) {
|
||||||
|
getPowerTreeData()
|
||||||
|
}
|
||||||
void form.validateFields()
|
void form.validateFields()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -478,11 +485,7 @@ const Role: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [formValues])
|
}, [formValues])
|
||||||
|
|
||||||
useEffect(() => {
|
useUpdatedEffect(() => {
|
||||||
getPowerTreeData()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
getRole()
|
getRole()
|
||||||
}, [
|
}, [
|
||||||
JSON.stringify(tableParams.filters),
|
JSON.stringify(tableParams.filters),
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
DATABASE_UPDATE_SUCCESS
|
DATABASE_UPDATE_SUCCESS
|
||||||
} from '@/constants/common.constants'
|
} from '@/constants/common.constants'
|
||||||
import { utcToLocalTime, isPastTime, localTimeToUtc, dayjsToUtc, getNowUtc } from '@/utils/common'
|
import { utcToLocalTime, isPastTime, localTimeToUtc, dayjsToUtc, getNowUtc } from '@/utils/common'
|
||||||
|
import { useUpdatedEffect } from '@/utils/hooks'
|
||||||
import {
|
import {
|
||||||
r_sys_group_get_list,
|
r_sys_group_get_list,
|
||||||
r_sys_role_get_list,
|
r_sys_role_get_list,
|
||||||
@@ -259,6 +260,12 @@ const User: React.FC = () => {
|
|||||||
form.setFieldValue('roleIds', newFormValues?.roleIds)
|
form.setFieldValue('roleIds', newFormValues?.roleIds)
|
||||||
form.setFieldValue('groupIds', newFormValues?.groupIds)
|
form.setFieldValue('groupIds', newFormValues?.groupIds)
|
||||||
|
|
||||||
|
if (!roleData || !roleData.length) {
|
||||||
|
getRoleData()
|
||||||
|
}
|
||||||
|
if (!groupData || !groupData.length) {
|
||||||
|
getGroupData()
|
||||||
|
}
|
||||||
getAvatar()
|
getAvatar()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -429,6 +436,12 @@ const User: React.FC = () => {
|
|||||||
'groupIds',
|
'groupIds',
|
||||||
value.groups.map((group) => group.id)
|
value.groups.map((group) => group.id)
|
||||||
)
|
)
|
||||||
|
if (!roleData || !roleData.length) {
|
||||||
|
getRoleData()
|
||||||
|
}
|
||||||
|
if (!groupData || !groupData.length) {
|
||||||
|
getGroupData()
|
||||||
|
}
|
||||||
void form.validateFields()
|
void form.validateFields()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -718,11 +731,7 @@ const User: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [formValues])
|
}, [formValues])
|
||||||
|
|
||||||
useEffect(() => {
|
useUpdatedEffect(() => {
|
||||||
handleOnDrawerRefresh()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
getUser()
|
getUser()
|
||||||
}, [
|
}, [
|
||||||
JSON.stringify(tableParams.filters),
|
JSON.stringify(tableParams.filters),
|
||||||
|
|||||||
16
src/utils/hooks.tsx
Normal file
16
src/utils/hooks.tsx
Normal 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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user