Skip to content

Commit

Permalink
fixbug: html添加Theme
Browse files Browse the repository at this point in the history
  • Loading branch information
jsxiaosi committed Jul 10, 2022
1 parent e773d80 commit 3462251
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
10 changes: 9 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,15 @@
<div></div>
</div>
</div>
<script></script>
<script>
window.onload = function () {
const stora = localStorage.getItem('appConfigMode');
if (stora) {
const appConfigMode = JSON.parse(stora);
document.body.style.background = appConfigMode.themeMode === 'dark' ? '#000' : '';
}
};
</script>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
12 changes: 4 additions & 8 deletions src/components/Application/AppTheme.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@
</template>

<script setup lang="ts">
import { ref } from 'vue';
import SvgIcon from '../SvgIcon/index.vue';
import { getAppCollapseMenu } from '@/hooks/userAppWindow';
import { useColorMode } from '@vueuse/core';
import { useAppStoreHook } from '@/store/modules/app';
const { appConfigMode } = getAppCollapseMenu();
const isDark = ref<string>(appConfigMode.value.themeMode);
isDark.value = appConfigMode.value.themeMode;
const appStore = useAppStoreHook();
const color = useColorMode();
const toggleDarkMode = () => {
isDark.value = isDark.value === 'day' ? 'dark' : 'day';
color.value = color.value === 'dark' ? 'light' : 'dark';
appStore.appConfigMode.themeMode = color.value;
appStore.setAppConfigMode(appStore.appConfigMode);
};
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/userAppWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export const getAppCollapseMenu = () => {
// const store = useStore()
const appStore = useAppStoreHook();
const appConfigMode = computed<appConfig>(() => appStore.getAppConfigMode);
return { appConfigMode };
return { appConfigMode, appStore };
};
1 change: 1 addition & 0 deletions src/store/modules/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const useAppStore = defineStore({
},
actions: {
setAppConfigMode(appConfigMode: appConfig): void {
console.log(appConfigMode);
localStorage.setItem('appConfigMode', JSON.stringify(appConfigMode));
this.appConfigMode = appConfigMode;
},
Expand Down

0 comments on commit 3462251

Please sign in to comment.