소스 검색

feat: 增加夜间模式

lvkun996 2 년 전
부모
커밋
b09f1fcc8c
6개의 변경된 파일92개의 추가작업 그리고 17개의 파일을 삭제
  1. 11 0
      public/index.html
  2. 9 8
      src/App.vue
  3. 18 0
      src/components/MicroComponents/index.tsx
  4. 36 9
      src/layout/navbar.vue
  5. 2 0
      src/store/index.ts
  6. 16 0
      src/store/modules/designStore/designStore.ts

+ 11 - 0
public/index.html

@@ -6,8 +6,18 @@
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <link rel="icon" href="logo.ico">
     <title>蛟龙云联</title>
+    <style type="text/css">
+      .icon {
+         width: 24px; height: 24px;
+         vertical-align: -0.15em;
+         /* fill: red; */
+         overflow: hidden;
+         /* background-color: azure; */
+      }
+  </style>
   </head>
   <body>
+
     <noscript>
       <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
     </noscript>
@@ -18,4 +28,5 @@
   <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/flv.js/1.6.2/flv.min.js"></script>\ -->
   <!-- <script src="https://cdn.bootcdn.net/ajax/libs/flv.js/1.6.2/flv.js"></script> -->
   <script src="https://cdn.bootcdn.net/ajax/libs/flv.js/1.6.2/flv.min.js"></script>
+  <script src="//at.alicdn.com/t/c/font_4137940_203u8vgindc.js"></script>
 </html>

+ 9 - 8
src/App.vue

@@ -1,5 +1,10 @@
 <template>
-    <a-config-provider :locale="zhCN">
+    <a-config-provider
+      :locale="zhCN"
+      :theme="{
+        algorithm: designStore.theme,
+      }"
+    >
       <router-view/>
     </a-config-provider>
 </template>
@@ -7,17 +12,13 @@
 import zhCN from 'ant-design-vue/es/locale/zh_CN'
 import dayjs from 'dayjs'
 import 'dayjs/locale/zh-cn'
+import { useDesignStore } from '@/store'
 
-import { ConfigProvider } from 'ant-design-vue'
 dayjs.locale('zh-cn')
 
-// ConfigProvider.config({
-//   theme: {
-//     primaryColor: '#fff'
-//   }
-// })
+const designStore = useDesignStore()
 
-console.log('process.env:', process.env)
+// theme.defaultAlgorithm
 
 </script>
 <style lang="less">

+ 18 - 0
src/components/MicroComponents/index.tsx

@@ -64,3 +64,21 @@ export const AlertTsx = defineComponent({
     )
   }
 })
+
+export const IconTsx = defineComponent({
+  props: {
+    name: {
+      type: String,
+      required: true
+    }
+  },
+  setup (props, ctx) {
+    console.log('IconTsx:', props.name)
+
+    return () => (
+      <svg class="icon" aria-hidden="true" style={{ fill: '#fff' }} >
+        <use style={{ fill: '#fff' }} xlinkHref={`#icon-${props.name}`}></use>
+      </svg>
+    )
+  }
+})

+ 36 - 9
src/layout/navbar.vue

@@ -1,16 +1,15 @@
 <template>
-  <a-layout-header class="header">
+  <a-layout-header class="header" :style="{backgroundColor: headerBgColor}">
       <a-row style="width: 100%;"  >
-        <a-col :span="3" >
+        <!-- <a-col :span="3" >
           <div class="logo" >
             <img :src="logoPng" alt="">
           </div>
-        </a-col>
-        <a-col :span="19" >
+        </a-col> -->
+        <a-col :span="18" >
         <a-menu
-          theme="dark"
           mode="horizontal"
-          :style="{ lineHeight: '64px' }"
+          :style="{ lineHeight: '64px', border: 'none' }"
           :selectedKeys="selectedKeys"
       >
           <a-menu-item
@@ -22,8 +21,15 @@
           </a-menu-item>
         </a-menu>
         </a-col>
-        <a-col :span="1" >
-          <user />
+        <a-col :span="4" >
+          <a-row :gutter="[8, 8]" justify="end" >
+            <a-col class="df-center" >
+              <a-button type="text" @click="changeTheme" > <IconTsx :name="iconName" /></a-button>
+            </a-col>
+            <a-col class="df-center" >
+              <user />
+            </a-col>
+          </a-row>
         </a-col>
       </a-row>
 
@@ -31,11 +37,13 @@
 </template>
 
 <script lang="ts" setup >
-import { onMounted, ref } from 'vue'
+import { computed, onMounted, ref } from 'vue'
 import { useAppRouter } from '@/store/router'
 import user from './user.vue'
 import { useRouter, useRoute } from 'vue-router'
 import { routes } from '@/router/index'
+import { IconTsx } from '@/components/MicroComponents/index'
+import { useDesignStore } from '@/store'
 
 const logoPng = require('@/assets/logo.jpg')
 
@@ -47,6 +55,18 @@ const appRouter = useAppRouter()
 
 const selectedKeys = ref<string[]>()
 
+const designStore = useDesignStore()
+
+console.log('designStore:', !!designStore.theme, designStore.theme)
+
+const iconName = computed(() => designStore.theme ? 'sun' : 'moon')
+
+const headerBgColor = computed(() => designStore.theme ? '#141414' : '#fff')
+
+const changeTheme = () => {
+  designStore.changeModeltheme()
+}
+
 const changeRouter = (route: ROUTER.RoutesProps) => {
   if (route.link) {
     window.open(route.path)
@@ -91,6 +111,7 @@ onMounted(() => {
 .header {
   position: relative;
   z-index: 2;
+  background-color: #fff;
 }
 
 .logo {
@@ -101,4 +122,10 @@ onMounted(() => {
     height: 100%;
   }
 }
+
+.df-center {
+  display: flex;
+  justify-content: center;
+  align-items: center;
+}
 </style>

+ 2 - 0
src/store/index.ts

@@ -1 +1,3 @@
 // import { createPinia } from 'pinia'
+
+export { useDesignStore } from './modules/designStore/designStore'

+ 16 - 0
src/store/modules/designStore/designStore.ts

@@ -0,0 +1,16 @@
+import { defineStore } from 'pinia'
+import { theme } from 'ant-design-vue'
+import { ref, computed } from 'vue'
+
+export const useDesignStore = defineStore('designStore', () => {
+  const modeltheme = ref<any>('')
+
+  const changeModeltheme = () => {
+    modeltheme.value = modeltheme.value ? '' : theme.darkAlgorithm
+  }
+
+  return {
+    theme: computed(() => modeltheme.value),
+    changeModeltheme
+  }
+})