feat: 支持跟随系统深色/浅色模式(darkmode + theme.json + 主题检测)
This commit is contained in:
@@ -16,6 +16,7 @@ const config = {
|
||||
patterns: [
|
||||
{ from: 'src/img', to: 'dist/img' },
|
||||
{ from: 'src/icon', to: 'dist/icon' }
|
||||
,{ from: 'src/theme.json', to: 'dist/theme.json' }
|
||||
],
|
||||
options: {
|
||||
}
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
@@ -1 +1 @@
|
||||
{"pages":["pages/index/index","pages/shop/index","pages/shop/detail/index","pages/product/index","pages/diy/index","pages/diy/stickerEdit/index","pages/checkout/index","pages/designList/index","pages/orders/index","pages/profile/index","pages/service/index","pages/wordcloud/index","pages/orderDetail/index","pages/address/index","pages/settings/index","pages/agreement/index","pages/userDatabase/index"],"window":{"backgroundTextStyle":"dark","navigationStyle":"custom","navigationBarTextStyle":"black"},"tabBar":{"custom":true,"list":[{"pagePath":"pages/index/index","text":"首页"},{"pagePath":"pages/shop/index","text":"商品"},{"pagePath":"pages/designList/index","text":"设计清单"},{"pagePath":"pages/orders/index","text":"订单"},{"pagePath":"pages/profile/index","text":"我的"}]}}
|
||||
{"darkmode":true,"themeLocation":"theme.json","pages":["pages/index/index","pages/shop/index","pages/shop/detail/index","pages/product/index","pages/diy/index","pages/diy/stickerEdit/index","pages/checkout/index","pages/designList/index","pages/orders/index","pages/profile/index","pages/service/index","pages/wordcloud/index","pages/orderDetail/index","pages/address/index","pages/settings/index","pages/agreement/index","pages/userDatabase/index"],"window":{"backgroundTextStyle":"dark","navigationStyle":"custom","navigationBarTextStyle":"black"},"tabBar":{"custom":true,"list":[{"pagePath":"pages/index/index","text":"首页"},{"pagePath":"pages/shop/index","text":"商品"},{"pagePath":"pages/designList/index","text":"设计清单"},{"pagePath":"pages/orders/index","text":"订单"},{"pagePath":"pages/profile/index","text":"我的"}]}}
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"light": {
|
||||
"navBgColor": "#ffffff",
|
||||
"navTxtStyle": "black",
|
||||
"bgColor": "#ffffff",
|
||||
"bgTxtStyle": "dark",
|
||||
"bgColorTop": "#ffffff",
|
||||
"bgColorBottom": "#ffffff",
|
||||
"tabBarColor": "#b08d8d",
|
||||
"tabBarSelectedColor": "#ff9a9e",
|
||||
"tabBarBgColor": "#ffffff",
|
||||
"tabBarBorderStyle": "black"
|
||||
},
|
||||
"dark": {
|
||||
"navBgColor": "#1e1e2f",
|
||||
"navTxtStyle": "white",
|
||||
"bgColor": "#1e1e2f",
|
||||
"bgTxtStyle": "light",
|
||||
"bgColorTop": "#1e1e2f",
|
||||
"bgColorBottom": "#1e1e2f",
|
||||
"tabBarColor": "#a0a0c0",
|
||||
"tabBarSelectedColor": "#ff7eb3",
|
||||
"tabBarBgColor": "#1e1e2f",
|
||||
"tabBarBorderStyle": "white"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
export default defineAppConfig({
|
||||
darkmode: true,
|
||||
themeLocation: 'theme.json',
|
||||
pages: [
|
||||
'pages/index/index',
|
||||
'pages/shop/index',
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"light": {
|
||||
"navBgColor": "#ffffff",
|
||||
"navTxtStyle": "black",
|
||||
"bgColor": "#ffffff",
|
||||
"bgTxtStyle": "dark",
|
||||
"bgColorTop": "#ffffff",
|
||||
"bgColorBottom": "#ffffff",
|
||||
"tabBarColor": "#b08d8d",
|
||||
"tabBarSelectedColor": "#ff9a9e",
|
||||
"tabBarBgColor": "#ffffff",
|
||||
"tabBarBorderStyle": "black"
|
||||
},
|
||||
"dark": {
|
||||
"navBgColor": "#1e1e2f",
|
||||
"navTxtStyle": "white",
|
||||
"bgColor": "#1e1e2f",
|
||||
"bgTxtStyle": "light",
|
||||
"bgColorTop": "#1e1e2f",
|
||||
"bgColorBottom": "#1e1e2f",
|
||||
"tabBarColor": "#a0a0c0",
|
||||
"tabBarSelectedColor": "#ff7eb3",
|
||||
"tabBarBgColor": "#1e1e2f",
|
||||
"tabBarBorderStyle": "white"
|
||||
}
|
||||
}
|
||||
@@ -262,9 +262,15 @@ export function setTheme(theme: ThemeMode) {
|
||||
/** 根据自动模式解析实际生效主题 */
|
||||
export function resolveTheme(mode: ThemeMode): 'light' | 'dark' {
|
||||
if (mode === 'auto') {
|
||||
// 需 app.json 开启 darkmode 后 theme 字段才有效;getSystemInfoSync 已废弃,改用 getAppBaseInfo
|
||||
try {
|
||||
const info = Taro.getAppBaseInfo()
|
||||
return info.theme === 'dark' ? 'dark' : 'light'
|
||||
} catch {
|
||||
const info = Taro.getSystemInfoSync()
|
||||
return info.theme === 'dark' ? 'dark' : 'light'
|
||||
}
|
||||
}
|
||||
return mode
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user