add dark support
This commit is contained in:
69
src/App.vue
69
src/App.vue
@@ -1,13 +1,40 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch } from "vue";
|
import { ref, watch, onMounted } from "vue";
|
||||||
import { open } from "@tauri-apps/plugin-dialog";
|
import { open } from "@tauri-apps/plugin-dialog";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import { ElMessage } from 'element-plus';
|
import { ElMessage } from 'element-plus';
|
||||||
import { Document, VideoPlay, CircleCheck } from '@element-plus/icons-vue';
|
import { Document, VideoPlay, CircleCheck, Moon, Sunny } from '@element-plus/icons-vue';
|
||||||
|
|
||||||
// Navigation
|
// Navigation
|
||||||
const activeMenu = ref("preparation");
|
const activeMenu = ref("preparation");
|
||||||
|
|
||||||
|
// Theme
|
||||||
|
const isDark = ref(false);
|
||||||
|
|
||||||
|
const toggleTheme = (val: string | number | boolean) => {
|
||||||
|
// val comes from el-switch change event which is boolean | string | number
|
||||||
|
const isDarkMode = val === true;
|
||||||
|
isDark.value = isDarkMode;
|
||||||
|
if (isDarkMode) {
|
||||||
|
document.documentElement.classList.add('dark');
|
||||||
|
localStorage.setItem('theme', 'dark');
|
||||||
|
} else {
|
||||||
|
document.documentElement.classList.remove('dark');
|
||||||
|
localStorage.setItem('theme', 'light');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
const savedTheme = localStorage.getItem('theme');
|
||||||
|
if (savedTheme === 'dark' || (!savedTheme && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
|
||||||
|
isDark.value = true;
|
||||||
|
document.documentElement.classList.add('dark');
|
||||||
|
} else {
|
||||||
|
isDark.value = false;
|
||||||
|
document.documentElement.classList.remove('dark');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Preparation Data
|
// Preparation Data
|
||||||
const workingDir = ref("");
|
const workingDir = ref("");
|
||||||
const templateDir = ref("");
|
const templateDir = ref("");
|
||||||
@@ -91,7 +118,7 @@ watch(currentDir, (newPath) => {
|
|||||||
const mm = match[1];
|
const mm = match[1];
|
||||||
const dd = match[2];
|
const dd = match[2];
|
||||||
const year = new Date().getFullYear();
|
const year = new Date().getFullYear();
|
||||||
// Format: AI-yyyyddmm-
|
// Format: AI-yyyymmdd-
|
||||||
videoNamePrefix.value = `AI-${year}${mm}${dd}-`;
|
videoNamePrefix.value = `AI-${year}${mm}${dd}-`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -100,12 +127,12 @@ watch(currentDir, (newPath) => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<el-container class="layout-container" style="height: 100vh">
|
<el-container class="layout-container" style="height: 100vh">
|
||||||
<el-aside width="200px" style="background-color: #fff; border-right: 1px solid #dcdfe6;">
|
<el-aside width="200px" class="main-aside">
|
||||||
<el-menu
|
<el-menu
|
||||||
:default-active="activeMenu"
|
:default-active="activeMenu"
|
||||||
class="el-menu-vertical-demo"
|
class="el-menu-vertical-demo"
|
||||||
@select="(index: string) => activeMenu = index"
|
@select="(index: string) => activeMenu = index"
|
||||||
style="border-right: none;"
|
style="border-right: none; flex: 1;"
|
||||||
>
|
>
|
||||||
<el-menu-item index="preparation">
|
<el-menu-item index="preparation">
|
||||||
<el-icon><Document /></el-icon>
|
<el-icon><Document /></el-icon>
|
||||||
@@ -120,6 +147,16 @@ watch(currentDir, (newPath) => {
|
|||||||
<span>检查</span>
|
<span>检查</span>
|
||||||
</el-menu-item>
|
</el-menu-item>
|
||||||
</el-menu>
|
</el-menu>
|
||||||
|
|
||||||
|
<div class="aside-footer">
|
||||||
|
<el-switch
|
||||||
|
v-model="isDark"
|
||||||
|
inline-prompt
|
||||||
|
:active-icon="Moon"
|
||||||
|
:inactive-icon="Sunny"
|
||||||
|
@change="toggleTheme"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</el-aside>
|
</el-aside>
|
||||||
|
|
||||||
<el-main>
|
<el-main>
|
||||||
@@ -185,7 +222,7 @@ watch(currentDir, (newPath) => {
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item label="文件前缀">
|
<el-form-item label="文件前缀">
|
||||||
<el-input v-model="videoNamePrefix" placeholder="AI-yyyyddmm-" />
|
<el-input v-model="videoNamePrefix" placeholder="AI-yyyymmdd-" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
</el-card>
|
</el-card>
|
||||||
@@ -209,13 +246,29 @@ watch(currentDir, (newPath) => {
|
|||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
|
font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
|
||||||
background-color: #f0f2f5;
|
background-color: var(--el-bg-color-page);
|
||||||
|
color: var(--el-text-color-primary);
|
||||||
|
transition: background-color 0.3s, color 0.3s;
|
||||||
}
|
}
|
||||||
.layout-container {
|
.layout-container {
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
}
|
}
|
||||||
|
.main-aside {
|
||||||
|
background-color: var(--el-bg-color);
|
||||||
|
border-right: 1px solid var(--el-border-color);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
transition: background-color 0.3s, border-color 0.3s;
|
||||||
|
}
|
||||||
|
.aside-footer {
|
||||||
|
padding: 16px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
border-top: 1px solid var(--el-border-color);
|
||||||
|
}
|
||||||
.box-card {
|
.box-card {
|
||||||
max-width: 800px;
|
max-width: 800px;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { createApp } from "vue";
|
import { createApp } from "vue";
|
||||||
import ElementPlus from 'element-plus'
|
import ElementPlus from 'element-plus'
|
||||||
import 'element-plus/dist/index.css'
|
import 'element-plus/dist/index.css'
|
||||||
|
import 'element-plus/theme-chalk/dark/css-vars.css'
|
||||||
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
|
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
|
||||||
import App from "./App.vue";
|
import App from "./App.vue";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user