mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
chore: 当页面中没有对应id元素时才删除改id的样式 (#8213)
Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com>
This commit is contained in:
parent
921ea09052
commit
07fb301da7
@ -15,6 +15,8 @@ interface CustomStyleProps {
|
||||
env: RendererEnv;
|
||||
}
|
||||
|
||||
export const styleIdCount = new Map();
|
||||
|
||||
export default function (props: CustomStyleProps) {
|
||||
const {config, env} = props;
|
||||
const {themeCss, classNames, id, defaultData, wrapperCustomStyle} = config;
|
||||
@ -22,6 +24,22 @@ export default function (props: CustomStyleProps) {
|
||||
return null;
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (styleIdCount.has(id)) {
|
||||
styleIdCount.set(id, styleIdCount.get(id) + 1);
|
||||
} else if (id) {
|
||||
styleIdCount.set(id, 1);
|
||||
}
|
||||
return () => {
|
||||
if (styleIdCount.has(id)) {
|
||||
styleIdCount.set(id, styleIdCount.get(id) - 1);
|
||||
if (styleIdCount.get(id) === 0) {
|
||||
styleIdCount.delete(id);
|
||||
}
|
||||
}
|
||||
};
|
||||
}, [id]);
|
||||
|
||||
useEffect(() => {
|
||||
if (themeCss && id) {
|
||||
insertCustomStyle(
|
||||
@ -35,7 +53,7 @@ export default function (props: CustomStyleProps) {
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (id) {
|
||||
if (id && !styleIdCount.get(id)) {
|
||||
removeCustomStyle('', id, env.getModalContainer?.().ownerDocument);
|
||||
}
|
||||
};
|
||||
@ -51,7 +69,7 @@ export default function (props: CustomStyleProps) {
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (id) {
|
||||
if (id && !styleIdCount.get(id)) {
|
||||
removeCustomStyle(
|
||||
'wrapperCustomStyle',
|
||||
id,
|
||||
|
Loading…
Reference in New Issue
Block a user