Skip to content

Commit 3b88337

Browse files
committed
refactor: update color modes handling
1 parent bf6a0f7 commit 3b88337

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

src/App.vue

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
<template>
22
<router-view />
33
</template>
4+
<script>
5+
import { onBeforeMount } from 'vue'
6+
import { useStore } from 'vuex'
7+
import { useColorModes } from '@coreui/vue'
8+
9+
export default {
10+
setup() {
11+
const { isColorModeSet, setColorMode } = useColorModes(
12+
'coreui-free-vue-admin-template-theme',
13+
)
14+
const store = useStore()
15+
16+
onBeforeMount(() => {
17+
const urlParams = new URLSearchParams(window.___location.href.split('?')[1])
18+
if (urlParams.get('theme')) {
19+
setColorMode(urlParams.get('theme'))
20+
return
21+
}
22+
23+
if (isColorModeSet()) {
24+
return
25+
}
26+
27+
setColorMode(store.state.theme)
28+
})
29+
},
30+
}
31+
</script>
432

533
<style lang="scss">
634
// Import Main styles for this application

src/components/AppHeader.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
</template>
9898

9999
<script>
100-
import { useColorModes } from '@coreui/vue/'
100+
import { useColorModes } from '@coreui/vue'
101101
import AppBreadcrumb from './AppBreadcrumb'
102102
import AppHeaderDropdownAccnt from './AppHeaderDropdownAccnt'
103103
import { logo } from '@/assets/brand/logo'

src/store/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default createStore({
44
state: {
55
sidebarVisible: '',
66
sidebarUnfoldable: false,
7+
theme: 'light',
78
},
89
mutations: {
910
toggleSidebar(state) {

src/views/widgets/WidgetsStatsTypeA.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,17 @@ export default {
386386
387387
onMounted(() => {
388388
document.documentElement.addEventListener('ColorSchemeChange', () => {
389-
widgetChartRef1.value.chart.data.datasets[0].pointBackgroundColor =
390-
getStyle('--cui-primary')
391-
widgetChartRef2.value.chart.data.datasets[0].pointBackgroundColor =
392-
getStyle('--cui-info')
393-
widgetChartRef1.value.chart.update()
394-
widgetChartRef2.value.chart.update()
389+
if (widgetChartRef1.value) {
390+
widgetChartRef1.value.chart.data.datasets[0].pointBackgroundColor =
391+
getStyle('--cui-primary')
392+
widgetChartRef1.value.chart.update()
393+
}
394+
395+
if (widgetChartRef2.value) {
396+
widgetChartRef2.value.chart.data.datasets[0].pointBackgroundColor =
397+
getStyle('--cui-info')
398+
widgetChartRef2.value.chart.update()
399+
}
395400
})
396401
})
397402

0 commit comments

Comments
 (0)