瀏覽代碼

fix: 修复状态条主题切换无响应

王家程 10 月之前
父節點
當前提交
0801e0073c
共有 3 個文件被更改,包括 28 次插入6 次删除
  1. 2 2
      src/components/MNavBar/index.vue
  2. 1 1
      src/pages.json
  3. 25 3
      src/sys.vue

+ 2 - 2
src/components/MNavBar/index.vue

@@ -2,13 +2,13 @@
  * @Author: wjc
  * @Date: 2024-07-03 10:35:44
  * @LastEditors: wjc
- * @LastEditTime: 2024-07-10 17:20:56
+ * @LastEditTime: 2024-07-10 17:52:38
  * @Description: 
 -->
 <template>
   <up-navbar ref="mNavBarRef" v-bind="$attrs" class="m-navbar" placeholder :bg-color="bgColor">
     <template #left>
-      <view v-if="notBack" class="wh-24px"></view>
+      <view v-if="notBack"></view>
       <view v-else class="i-ep-arrow-left wh-24px cursor-pointer" @click="goBack"></view>
     </template>
     <template #center>

+ 1 - 1
src/pages.json

@@ -86,7 +86,7 @@
 	],
 	"globalStyle": {
 		"navigationBarTextStyle": "black",
-		"navigationBarTitleText": "uni-app",
+		"navigationBarTitleText": "绘管家",
 		"navigationBarBackgroundColor": "#F8F8F8",
 		"backgroundColor": "#F8F8F8"
 	},

+ 25 - 3
src/sys.vue

@@ -1,3 +1,10 @@
+<!--
+ * @Author: wjc
+ * @Date: 2024-07-10 10:35:44
+ * @LastEditors: wjc
+ * @LastEditTime: 2024-07-10 17:56:50
+ * @Description: 每个页面都会插入该组件,用于同步全局设置,比如主题
+-->
 <template>
   <page-meta>
     <navigation-bar v-bind="originNavBarStyle" />
@@ -6,14 +13,16 @@
 </template>
 
 <script setup lang="ts">
+  import { onLaunch, onShow } from '@dcloudio/uni-app'
   import { useAppStore } from '@/stores/modules/appStore'
 
   defineOptions({ name: 'Sys' })
 
   const appStore = useAppStore()
-  const originNavBarStyle = computed(() => {
+
+  const setBarStyle = () => {
     if (appStore.isDark) {
-      return {
+      const styles: UniApp.SetNavigationbarColorOptions = {
         frontColor: '#ffffff',
         backgroundColor: '#1a1a1a',
         animation: {
@@ -21,8 +30,10 @@
           timingFunc: 'easeIn',
         },
       }
+      uni.setNavigationBarColor(styles)
+      return styles
     } else {
-      return {
+      const styles: UniApp.SetNavigationbarColorOptions = {
         frontColor: '#000000',
         backgroundColor: '#f8f8f8',
         animation: {
@@ -30,6 +41,17 @@
           timingFunc: 'easeIn',
         },
       }
+      uni.setNavigationBarColor(styles)
+      return styles
     }
+  }
+
+  const originNavBarStyle = computed(setBarStyle)
+
+  onLaunch(() => {
+    setBarStyle()
+  })
+  onShow(() => {
+    setBarStyle()
   })
 </script>