112 lines
3.9 KiB
Vue
112 lines
3.9 KiB
Vue
<script setup lang="ts">
|
|
import { computed, watch } from "vue";
|
|
import { createLocale, darkTheme, dateZhCN, NConfigProvider, NDialogProvider, NMessageProvider, zhCN } from "naive-ui";
|
|
import type { GlobalThemeOverrides } from "naive-ui";
|
|
import { isDark } from "./shared/theme";
|
|
|
|
const locale = createLocale({
|
|
Input: { placeholder: "" },
|
|
InputNumber: { placeholder: "" },
|
|
Select: { placeholder: "" },
|
|
DatePicker: {
|
|
datePlaceholder: "",
|
|
datetimePlaceholder: "",
|
|
selectDate: "",
|
|
},
|
|
}, zhCN);
|
|
|
|
const palette = computed(() => isDark.value
|
|
? { bg: "#0D1117", panel: "#161A22", ink: "#E6EDF3", muted: "#9AA4AE", line: "#262C36", accent: "#79C0FF", sidebar: "#0D1117", danger: "#F85149" }
|
|
: { bg: "#F6F8FA", panel: "#FFFFFF", ink: "#0D1117", muted: "#57606A", line: "#D0D7DE", accent: "#0969DA", sidebar: "#FFFFFF", danger: "#CF222E" });
|
|
|
|
watch(palette, (value) => {
|
|
const root = document.documentElement;
|
|
const dark = isDark.value;
|
|
root.style.setProperty("--bg", value.bg);
|
|
root.style.setProperty("--panel", value.panel);
|
|
root.style.setProperty("--ink", value.ink);
|
|
root.style.setProperty("--muted", value.muted);
|
|
root.style.setProperty("--line", value.line);
|
|
root.style.setProperty("--accent", value.accent);
|
|
root.style.setProperty("--sidebar", value.sidebar);
|
|
root.style.setProperty("--danger", value.danger);
|
|
root.style.setProperty("--ok", dark ? "#3FB950" : "#1A7F37");
|
|
root.style.setProperty("--panel-2", dark ? "#1C2129" : "#F3F5F7");
|
|
root.style.setProperty("--hover", dark ? "rgba(230, 237, 243, 0.04)" : "rgba(13, 17, 23, 0.03)");
|
|
root.style.setProperty("--shadow", dark ? "none" : "0 1px 2px rgba(13, 17, 23, 0.04)");
|
|
root.style.setProperty("--accent-soft", dark ? "rgba(121, 192, 255, 0.16)" : "rgba(9, 105, 218, 0.12)");
|
|
root.dataset.theme = dark ? "dark" : "light";
|
|
}, { immediate: true });
|
|
|
|
const overrides = computed<GlobalThemeOverrides>(() => {
|
|
const line = isDark.value ? "#6E7681" : "#D0D7DE";
|
|
const lineHover = isDark.value ? "#C9D1D9" : "#57606A";
|
|
return {
|
|
common: {
|
|
primaryColor: "#1F6FEB",
|
|
primaryColorHover: "#388BFD",
|
|
primaryColorPressed: "#1158C7",
|
|
primaryColorSuppl: "#1F6FEB",
|
|
bodyColor: palette.value.bg,
|
|
cardColor: palette.value.panel,
|
|
modalColor: palette.value.panel,
|
|
popoverColor: palette.value.panel,
|
|
textColor2: palette.value.ink,
|
|
textColor3: isDark.value ? "#C9D1D9" : "#57606A",
|
|
placeholderColor: isDark.value ? "#C9D1D9" : "#57606A",
|
|
borderColor: line,
|
|
fontFamily: '"Segoe UI", "Microsoft YaHei", sans-serif',
|
|
borderRadius: "4px",
|
|
heightMedium: "34px",
|
|
heightSmall: "28px",
|
|
},
|
|
Button: {
|
|
heightMedium: "34px",
|
|
heightSmall: "28px",
|
|
paddingMedium: "0 14px",
|
|
paddingSmall: "0 10px",
|
|
fontWeightStrong: "600",
|
|
borderRadiusMedium: "4px",
|
|
},
|
|
Input: {
|
|
heightMedium: "34px",
|
|
placeholderColor: isDark.value ? "#C9D1D9" : "#57606A",
|
|
border: `1px solid ${line}`,
|
|
borderHover: `1px solid ${lineHover}`,
|
|
borderFocus: "1px solid #1F6FEB",
|
|
},
|
|
InternalSelection: {
|
|
heightMedium: "34px",
|
|
border: `1px solid ${line}`,
|
|
borderHover: `1px solid ${lineHover}`,
|
|
borderActive: "1px solid #1F6FEB",
|
|
borderFocus: "1px solid #1F6FEB",
|
|
},
|
|
Dialog: {
|
|
borderRadius: "8px",
|
|
titleFontSize: "16px",
|
|
titleFontWeight: "650",
|
|
padding: "20px 24px 16px",
|
|
},
|
|
Card: {
|
|
borderRadius: "8px",
|
|
paddingMedium: "20px 24px",
|
|
titleFontSizeMedium: "16px",
|
|
titleFontWeight: "650",
|
|
},
|
|
};
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<n-config-provider class="app-root" :locale="locale" :date-locale="dateZhCN" :theme="isDark ? darkTheme : null" :theme-overrides="overrides">
|
|
<n-message-provider>
|
|
<n-dialog-provider>
|
|
<div class="app-root">
|
|
<router-view />
|
|
</div>
|
|
</n-dialog-provider>
|
|
</n-message-provider>
|
|
</n-config-provider>
|
|
</template>
|