From 7c325ee96d49b68188762d4405aaf551e5e819b8 Mon Sep 17 00:00:00 2001 From: bimei <18812666091@163.com> Date: Fri, 3 Mar 2023 13:13:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=BB=E9=A2=98=E5=88=87=E6=8D=A2XTab?= =?UTF-8?q?le=E9=A2=9C=E8=89=B2=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/XTable/src/XTable.vue | 30 ++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/components/XTable/src/XTable.vue b/src/components/XTable/src/XTable.vue index 34f91ce0..3b88266f 100644 --- a/src/components/XTable/src/XTable.vue +++ b/src/components/XTable/src/XTable.vue @@ -12,6 +12,7 @@ import { useAppStore } from '@/store/modules/app' import { useDesign } from '@/hooks/web/useDesign' import { XTableProps } from './type' import { isBoolean, isFunction } from '@/utils/is' +import styleCss from './style/dark.scss' import download from '@/utils/download' @@ -26,14 +27,39 @@ const prefixCls = getPrefixCls('x-vxe-table') const attrs = useAttrs() const emit = defineEmits(['register']) +const removeStyles = () => { + var filename = 'cssTheme' + //移除引入的文件名 + var targetelement = 'style' + var targetattr = 'id' + var allsuspects = document.getElementsByTagName(targetelement) + for (var i = allsuspects.length; i >= 0; i--) { + if ( + allsuspects[i] && + allsuspects[i].getAttribute(targetattr) != null && + allsuspects[i].getAttribute(targetattr)?.indexOf(filename) != -1 + ) { + console.log(allsuspects[i], 'node') + allsuspects[i].parentNode?.removeChild(allsuspects[i]) + } + } +} +const reImport = () => { + var head = document.getElementsByTagName('head')[0] + var style = document.createElement('style') + style.innerText = styleCss + style.id = 'cssTheme' + head.appendChild(style) +} + watch( () => appStore.getIsDark, () => { if (appStore.getIsDark == true) { - import('./style/dark.scss') + reImport() } if (appStore.getIsDark == false) { - import('./style/light.scss') + removeStyles() } }, { immediate: true }