Skip to content

Commit 2c456d0

Browse files
committed
feat: add dark mode close #6
1 parent 5765c92 commit 2c456d0

File tree

12 files changed

+117
-51
lines changed

12 files changed

+117
-51
lines changed

.eslintrc.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ module.exports = {
2121
'import/namespace': [2, { allowComputed: true }],
2222
'import/no-named-as-default-member': 'off',
2323
'import/no-unresolved': 'off',
24-
'@typescript-eslint/consistent-type-imports': 'off',
25-
'@typescript-eslint/no-unused-vars': 'off',
2624
// enUS: all rules docs https://eslint.org/docs/rules/
2725
// zhCN: 所有规则文档 https://eslint.bootcss.com/docs/rules/
2826
// 基础规则 全部 ES 项目通用
@@ -35,6 +33,12 @@ module.exports = {
3533
'no-unused-vars': ['off'],
3634
// 强制在代码块中开括号前和闭括号后有空格
3735
'block-spacing': ['error', 'always'],
38-
'object-curly-spacing': ['error', 'always']
36+
'object-curly-spacing': ['error', 'always'],
37+
/* typescript */
38+
'@typescript-eslint/ban-ts-ignore': 'off',
39+
'@typescript-eslint/no-var-requires': 'off',
40+
'@typescript-eslint/no-explicit-any': 'off',
41+
'@typescript-eslint/consistent-type-imports': 'off',
42+
'@typescript-eslint/no-unused-vars': 'off',
3943
},
4044
}

components.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ import '@vue/runtime-core'
66
declare module '@vue/runtime-core' {
77
export interface GlobalComponents {
88
VanButton: typeof import('vant/es')['Button']
9+
VanCell: typeof import('vant/es')['Cell']
10+
VanCellGroup: typeof import('vant/es')['CellGroup']
911
VanConfigProvider: typeof import('vant/es')['ConfigProvider']
12+
VanIcon: typeof import('vant/es')['Icon']
13+
VanNavBar: typeof import('vant/es')['NavBar']
1014
VanSwitch: typeof import('vant/es')['Switch']
15+
VanTag: typeof import('vant/es')['Tag']
1116
}
1217
}
1318

src/App.vue

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
<template>
22
<van-config-provider :theme="theme">
3-
<van-switch v-model="checked" />
43
<router-view />
54
</van-config-provider>
65
</template>
76

87
<script setup lang="ts">
9-
import { ref, watch } from 'vue'
8+
import { ref, computed, watch } from 'vue'
109
import type { ConfigProviderTheme } from 'vant'
10+
import { localStorage } from '@/utils/local-storage'
11+
import { useStore } from '@/stores'
1112
12-
const theme = ref<ConfigProviderTheme>('light')
13-
const checked = ref<boolean>(false)
13+
const store = useStore()
14+
const res = localStorage.get('theme')
15+
const theme = ref<ConfigProviderTheme>(res)
16+
const mode = computed(() => store.mode)
1417
15-
watch(checked,() => {
16-
if(checked.value) {
18+
watch(mode, (val) => {
19+
if(val === 'dark') {
1720
theme.value = 'dark'
1821
document.querySelector('html')
19-
.setAttribute('data-theme', 'data-theme-dark')
22+
.setAttribute('data-theme', 'dark')
2023
} else {
2124
theme.value = 'light'
2225
document.querySelector('html')
23-
.setAttribute('data-theme', 'data-theme-light')
26+
.setAttribute('data-theme', 'light')
2427
}
25-
})
28+
}, { immediate: true })
29+
2630
</script>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import request from '@/utils/request'
2-
3-
export async function queryProjectNotice(): Promise<any> {
4-
return request('/project/notice')
1+
import request from '@/utils/request'
2+
3+
export async function queryProjectNotice(): Promise<any> {
4+
return request('/project/notice')
55
}

src/app.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ body {
1313
box-sizing: border-box;
1414
}
1515

16-
[data-theme='data-theme-dark'] {
16+
[data-theme='dark'] {
1717
&,
1818
* {
1919
color-scheme: dark !important;

src/router/index.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
1-
1+
// https://router.vuejs.org/zh/
22
import { createRouter, createWebHistory } from 'vue-router'
33
import NProgress from 'nprogress'
44
import 'nprogress/nprogress.css'
55
NProgress.configure({ showSpinner: true })
66

77
// 导入路由组件
8-
import Dashboard from '../views/dashboard/analysis/index.vue'
9-
import Workplace from '../views/dashboard/workplace/index.vue'
8+
import mian from '@/views/index.vue'
9+
import mock from '@/views/mock/index.vue'
1010

1111
// 定义路由,每个路由都需要映射到一个组件
1212
const routes = [
1313
{
1414
path: '/',
15-
name: 'dashboard',
16-
component: Dashboard
15+
name: 'main',
16+
component: mian
1717
}, {
18-
path: '/workplace',
19-
name: 'workplace',
20-
component: Workplace
18+
path: '/mock',
19+
name: 'mock',
20+
component: mock
2121
}
2222
]
2323

2424
// 创建路由实例并传递 `routes` 配置
2525
const router = createRouter({
2626
history: createWebHistory(),
27-
routes
27+
routes,
28+
scrollBehavior() {
29+
// 始终滚动到顶部
30+
return { top: 0 }
31+
},
2832
})
2933

3034
router.beforeEach((_to, _from, next) => {

src/stores/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineStore } from 'pinia'
2+
3+
export const useStore = defineStore({
4+
id: 'index',
5+
state: () => ({
6+
mode: 'light'
7+
})
8+
})

src/utils/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { AxiosRequestConfig, AxiosError } from 'axios'
22
import axios, { AxiosResponse } from 'axios'
33
import type { ResponseBody } from '@/api/typing'
44
import { localStorage } from '@/utils/local-storage'
5-
import { STORAGE_TOKEN_KEY } from '@/store/mutation-type'
5+
import { STORAGE_TOKEN_KEY } from '@/stores/mutation-type'
66
import { Notify } from 'vant'
77

88
// 这里是用于设定请求后端时,所用的 Token KEY

src/views/dashboard/analysis/index.vue

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)