@liujitcn/kratos-taro-app-core 0.0.79 → 0.0.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build.mjs +4 -2
- package/package.json +1 -1
- package/src/components/BootstrapStatus.scss +3 -3
- package/src/components/BootstrapStatus.tsx +3 -1
- package/src/components/KratosTabBar.scss +32 -13
- package/src/components/KratosTabBar.tsx +34 -3
- package/src/components/MfaRecoveryCodesDialog.scss +11 -10
- package/src/components/MfaSetupPanel.scss +4 -4
- package/src/components/PasswordVerifyDialog.scss +21 -21
- package/src/navigation.ts +6 -3
- package/src/pages.ts +4 -2
- package/src/rpc/base/v1/config.ts +1 -1
- package/src/rpc/base/v1/file.ts +1 -1
- package/src/rpc/base/v1/language.ts +1 -1
- package/src/rpc/base/v1/login.ts +1 -1
- package/src/rpc/base/v1/mcp.ts +1 -1
- package/src/rpc/base/v1/mfa.ts +1 -1
- package/src/rpc/base/v1/oauth.ts +1 -1
- package/src/rpc/base/v1/secret_crypto.ts +1 -1
- package/src/rpc/base/v1/sse.ts +1 -1
- package/src/rpc/common/v1/common.ts +1 -1
- package/src/rpc/common/v1/types.ts +1 -1
- package/src/rpc/google/protobuf/empty.ts +1 -1
- package/src/rpc/google/protobuf/struct.ts +2 -2
- package/src/rpc/google/protobuf/wrappers.ts +1 -1
- package/src/rpc/system/app/v1/auth.ts +1 -1
- package/src/rpc/system/app/v1/base_area.ts +1 -1
- package/src/rpc/system/app/v1/base_dict.ts +1 -1
- package/src/rpc/system/app/v1/base_menu.ts +1 -1
- package/src/rpc/system/common/v1/common.ts +1 -1
- package/src/stores/index.ts +1 -0
- package/src/stores/theme.ts +108 -0
- package/src/styles/base.scss +90 -5
- package/src/styles/components.scss +765 -0
- package/src/utils/http.ts +3 -0
- package/src/utils/index.ts +19 -0
- package/src/utils/navigation.ts +12 -0
- package/src/views/pages/index/index.scss +69 -73
- package/src/views/pages/index/index.tsx +50 -34
- package/src/views/pages/login/login.scss +109 -142
- package/src/views/pages/login/login.tsx +142 -82
- package/src/views/pages/login/protocal.scss +14 -14
- package/src/views/pages/login/protocal.tsx +16 -3
- package/src/views/pages/webview/webview.scss +6 -5
- package/src/views/pages/webview/webview.tsx +3 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import Taro from '@tarojs/taro'
|
|
2
|
+
import { create } from 'zustand'
|
|
3
|
+
|
|
4
|
+
/** 主题模式:暗黑、明亮、跟随系统。 */
|
|
5
|
+
export type ThemeMode = 'dark' | 'light' | 'auto'
|
|
6
|
+
/** 实际生效的主题。 */
|
|
7
|
+
export type ResolvedTheme = 'dark' | 'light'
|
|
8
|
+
|
|
9
|
+
const THEME_MODE_STORAGE_KEY = 'kratos_theme_mode'
|
|
10
|
+
const DEFAULT_THEME_MODE: ThemeMode = 'light'
|
|
11
|
+
|
|
12
|
+
/** 读取系统主题;系统未上报时回退明亮。 */
|
|
13
|
+
const readSystemTheme = (): ResolvedTheme => {
|
|
14
|
+
if (process.env.TARO_ENV === 'h5' && typeof window !== 'undefined') {
|
|
15
|
+
return window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
return Taro.getSystemInfoSync().theme === 'dark' ? 'dark' : 'light'
|
|
19
|
+
} catch {
|
|
20
|
+
return 'light'
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** 读取本地持久化的主题模式。 */
|
|
25
|
+
const readStoredMode = (): ThemeMode => {
|
|
26
|
+
try {
|
|
27
|
+
const stored = Taro.getStorageSync(THEME_MODE_STORAGE_KEY)
|
|
28
|
+
if (stored === 'dark' || stored === 'light' || stored === 'auto') return stored
|
|
29
|
+
} catch {
|
|
30
|
+
// 存储读取失败时使用默认主题。
|
|
31
|
+
}
|
|
32
|
+
return DEFAULT_THEME_MODE
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 主题实际生效时给导航栏与页面底色染色,覆盖全局配置的静态浅色。 */
|
|
36
|
+
const applyChrome = (theme: ResolvedTheme) => {
|
|
37
|
+
try {
|
|
38
|
+
const backgroundColor = theme === 'light' ? '#f4f9fd' : '#060a12'
|
|
39
|
+
void Taro.setNavigationBarColor({
|
|
40
|
+
frontColor: theme === 'light' ? '#000000' : '#ffffff',
|
|
41
|
+
backgroundColor,
|
|
42
|
+
fail: () => undefined,
|
|
43
|
+
})
|
|
44
|
+
void Taro.setBackgroundColor({ backgroundColor, fail: () => undefined })
|
|
45
|
+
} catch {
|
|
46
|
+
// 部分平台/版本未暴露导航栏染色 API,跳过不影响主题类。
|
|
47
|
+
}
|
|
48
|
+
// H5 弹层(showModal/showToast)挂在 body 下,取不到页面根类,把主题类镜像到 html 上。
|
|
49
|
+
if (process.env.TARO_ENV === 'h5' && typeof document !== 'undefined') {
|
|
50
|
+
document.documentElement.classList.toggle('theme-dark', theme === 'dark')
|
|
51
|
+
document.documentElement.classList.toggle('theme-light', theme === 'light')
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 订阅系统深浅色变化;H5 用 matchMedia,小程序用 onThemeChange。 */
|
|
56
|
+
const watchSystemTheme = (onChange: (theme: ResolvedTheme) => void) => {
|
|
57
|
+
if (process.env.TARO_ENV === 'h5') {
|
|
58
|
+
if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {
|
|
59
|
+
const media = window.matchMedia('(prefers-color-scheme: light)')
|
|
60
|
+
const listener = (event: MediaQueryListEvent) => onChange(event.matches ? 'light' : 'dark')
|
|
61
|
+
if (typeof media.addEventListener === 'function') {
|
|
62
|
+
media.addEventListener('change', listener)
|
|
63
|
+
} else if (typeof media.addListener === 'function') {
|
|
64
|
+
media.addListener(listener)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
Taro.onThemeChange?.((result) => onChange(result.theme === 'light' ? 'light' : 'dark'))
|
|
71
|
+
} catch {
|
|
72
|
+
// 平台不支持系统主题回调时保持启动时读取的值。
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** 全局主题状态及操作。 */
|
|
77
|
+
export interface ThemeStoreState {
|
|
78
|
+
mode: ThemeMode
|
|
79
|
+
theme: ResolvedTheme
|
|
80
|
+
setMode: (mode: ThemeMode) => void
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 全局主题 Zustand Store:模式持久化存储,auto 跟随系统深浅色。 */
|
|
84
|
+
export const useThemeStore = create<ThemeStoreState>((set) => ({
|
|
85
|
+
mode: readStoredMode(),
|
|
86
|
+
theme: 'dark',
|
|
87
|
+
setMode(mode) {
|
|
88
|
+
const theme = mode === 'auto' ? readSystemTheme() : mode
|
|
89
|
+
try {
|
|
90
|
+
Taro.setStorageSync(THEME_MODE_STORAGE_KEY, mode)
|
|
91
|
+
} catch {
|
|
92
|
+
// 存储写入失败不影响当前会话主题。
|
|
93
|
+
}
|
|
94
|
+
set({ mode, theme })
|
|
95
|
+
},
|
|
96
|
+
}))
|
|
97
|
+
|
|
98
|
+
// 初始化:解析启动主题、染色导航栏并订阅系统主题变化。
|
|
99
|
+
const initialMode = useThemeStore.getState().mode
|
|
100
|
+
const initialTheme = initialMode === 'auto' ? readSystemTheme() : initialMode
|
|
101
|
+
useThemeStore.setState({ theme: initialTheme })
|
|
102
|
+
watchSystemTheme((theme) => {
|
|
103
|
+
if (useThemeStore.getState().mode === 'auto') useThemeStore.setState({ theme })
|
|
104
|
+
})
|
|
105
|
+
useThemeStore.subscribe((state, prev) => {
|
|
106
|
+
if (state.theme !== prev.theme) applyChrome(state.theme)
|
|
107
|
+
})
|
|
108
|
+
applyChrome(initialTheme)
|
package/src/styles/base.scss
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
@use './components.scss';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* H5 的 pxtransform 结果使用 rem。根字号与 uni-app H5 保持同一套
|
|
5
|
+
* 375 设计宽度规则;根字号脚本未能从部署子路径加载时仍能正确缩放。
|
|
6
|
+
*/
|
|
7
|
+
/* #ifdef h5 */
|
|
8
|
+
html {
|
|
9
|
+
font-size: 5.333333vw;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@media screen and (min-width: 961px) {
|
|
13
|
+
html {
|
|
14
|
+
font-size: 20PX;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/* #endif */
|
|
18
|
+
|
|
1
19
|
page,
|
|
2
20
|
body {
|
|
3
21
|
min-height: 100%;
|
|
@@ -31,11 +49,6 @@ button::after {
|
|
|
31
49
|
overflow-y: auto !important;
|
|
32
50
|
}
|
|
33
51
|
|
|
34
|
-
// Taro H5 的默认确认色与 uni-app H5 不同,统一为基线平台色。
|
|
35
|
-
.taro-model__confirm {
|
|
36
|
-
color: #007aff !important;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
52
|
// H5 ScrollView 使用内部滚动,隐藏其滚动条避免额外占用内容宽度。
|
|
40
53
|
.taro-scroll-view__scroll-y {
|
|
41
54
|
scrollbar-width: none;
|
|
@@ -46,3 +59,75 @@ button::after {
|
|
|
46
59
|
width: 0;
|
|
47
60
|
height: 0;
|
|
48
61
|
}
|
|
62
|
+
|
|
63
|
+
html.theme-light body,
|
|
64
|
+
html.theme-light page {
|
|
65
|
+
background: #eef3f8;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
html.theme-dark body,
|
|
69
|
+
html.theme-dark page {
|
|
70
|
+
background: #060a12;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/* ============================================================
|
|
74
|
+
* H5 系统弹层随主题:Taro.showModal/showToast 渲染在 body 下,
|
|
75
|
+
* 取不到页面根类,用 theme store 镜像到 html 上的主题类着色。
|
|
76
|
+
* ============================================================ */
|
|
77
|
+
/* #ifdef h5 */
|
|
78
|
+
html.theme-dark .taro-modal__mask {
|
|
79
|
+
background: var(--kratos-color-mask) !important;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
html.theme-dark .taro-modal__content {
|
|
83
|
+
background: var(--kratos-color-surface-solid) !important;
|
|
84
|
+
color: var(--kratos-color-text);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
html.theme-dark .taro-modal__title {
|
|
88
|
+
color: var(--kratos-color-text);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
html.theme-dark .taro-modal__text {
|
|
92
|
+
color: var(--kratos-color-text-muted) !important;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
html.theme-dark .taro-modal__foot::after,
|
|
96
|
+
html.theme-dark .taro-model__btn::after {
|
|
97
|
+
border-color: var(--kratos-color-border);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
html.theme-dark .taro-model__btn:active {
|
|
101
|
+
background: var(--kratos-color-surface-2);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
html.theme-dark .taro-model__btn.taro-model__cancel {
|
|
105
|
+
color: var(--kratos-color-text-muted) !important;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
html.theme-dark .taro__actionSheet > div:first-child {
|
|
109
|
+
background: var(--kratos-color-mask) !important;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
html.theme-dark .taro__actionSheet > div:last-child {
|
|
113
|
+
background: var(--kratos-color-background) !important;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
html.theme-dark .taro__actionSheet > div:last-child > div {
|
|
117
|
+
background: var(--kratos-color-surface-solid) !important;
|
|
118
|
+
color: var(--kratos-color-text) !important;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
html.theme-dark .taro__actionSheet .taro-actionsheet__cell:first-child {
|
|
122
|
+
color: var(--kratos-color-text-muted) !important;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
html.theme-dark .taro__actionSheet .taro-actionsheet__cell::after {
|
|
126
|
+
border-color: var(--kratos-color-border);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
html.theme-dark .taro__toast > div:last-child {
|
|
130
|
+
background: rgba(10, 18, 30, 0.9) !important;
|
|
131
|
+
color: var(--kratos-color-text) !important;
|
|
132
|
+
}
|
|
133
|
+
/* #endif */
|