feat: 添加客户端主题切换并优化导出状态
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
<template #icon><n-icon :component="FolderOutline" /></template>
|
||||
{{ t('pages.traceCode.manageGroups') }}
|
||||
</n-button>
|
||||
<n-button v-if="auth.canWrite" @click="onExport">
|
||||
<n-button v-if="auth.canWrite" :loading="exporting" :disabled="exporting" @click="onExport">
|
||||
<template #icon><n-icon :component="DownloadOutline" /></template>
|
||||
{{ exportButtonText }}
|
||||
</n-button>
|
||||
@@ -277,6 +277,7 @@ const qrModal = ref(false);
|
||||
const qrSrc = ref('');
|
||||
const qrUrl = ref('');
|
||||
let qrBlobUrl = '';
|
||||
const exporting = ref(false);
|
||||
|
||||
const groupModal = ref(false);
|
||||
const groupForm = reactive<{ name: string }>({ name: '' });
|
||||
@@ -577,6 +578,7 @@ const exportButtonText = computed(() => {
|
||||
});
|
||||
|
||||
async function onExport() {
|
||||
if (exporting.value) return;
|
||||
const params: Record<string, unknown> = {};
|
||||
if (checkedKeys.value.length) {
|
||||
params.ids = checkedKeys.value.map(String).join(',');
|
||||
@@ -589,7 +591,12 @@ async function onExport() {
|
||||
if (query.outboundStatus) params.outboundStatus = query.outboundStatus;
|
||||
if (query.keyword) params.keyword = query.keyword;
|
||||
}
|
||||
await downloadFile('/trace-codes/export', 'trace-codes.zip', params);
|
||||
exporting.value = true;
|
||||
try {
|
||||
await downloadFile('/trace-codes/export', 'trace-codes.zip', params);
|
||||
} finally {
|
||||
exporting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function batchAssignGroup(key: string) {
|
||||
|
||||
@@ -204,7 +204,7 @@
|
||||
"create": "New Template",
|
||||
"edit": "Edit Template",
|
||||
"namePlaceholder": "Enter template name",
|
||||
"fieldKeyTip": "Unique key, e.g. craft",
|
||||
"fieldKeyTip": "Unique English key",
|
||||
"sortHint": "Field order = display order on consumer page; use arrows to reorder",
|
||||
"defaultFields": {
|
||||
"craft": "Craft",
|
||||
|
||||
@@ -204,7 +204,7 @@
|
||||
"create": "新建模板",
|
||||
"edit": "编辑模板",
|
||||
"namePlaceholder": "请输入模板名称",
|
||||
"fieldKeyTip": "英文唯一标识,如 craft",
|
||||
"fieldKeyTip": "英文唯一标识",
|
||||
"sortHint": "字段顺序即客户端展示顺序,可用上下箭头调整",
|
||||
"defaultFields": {
|
||||
"craft": "工艺",
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
<template>
|
||||
<div class="theme-wrap">
|
||||
<button class="theme-button" :aria-label="labels.title" :title="labels.title" @click.stop="open = !open">
|
||||
<svg v-if="mode === 'auto'" viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path d="M12 3a9 9 0 1 0 9 9" />
|
||||
<path d="M12 3a9 9 0 0 1 0 18" />
|
||||
</svg>
|
||||
<svg v-else-if="isDark" viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path d="M21 12.8A8.5 8.5 0 1 1 11.2 3a6.5 6.5 0 0 0 9.8 9.8Z" />
|
||||
</svg>
|
||||
<svg v-else viewBox="0 0 24 24" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="4" />
|
||||
<path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4" />
|
||||
</svg>
|
||||
</button>
|
||||
<transition name="theme-menu">
|
||||
<ul v-if="open" class="theme-menu" @click.stop>
|
||||
<li
|
||||
v-for="item in options"
|
||||
:key="item.value"
|
||||
class="theme-item"
|
||||
:class="{ active: item.value === mode }"
|
||||
@click="choose(item.value)"
|
||||
>
|
||||
<span>{{ item.label }}</span>
|
||||
<span v-if="item.value === mode" class="theme-check">✓</span>
|
||||
</li>
|
||||
</ul>
|
||||
</transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useTheme, type ThemeMode } from '@/composables/useTheme';
|
||||
|
||||
const { locale } = useI18n();
|
||||
const { mode, isDark, setThemeMode } = useTheme();
|
||||
const open = ref(false);
|
||||
|
||||
const isZh = computed(() => String(locale.value).startsWith('zh'));
|
||||
const labels = computed(() =>
|
||||
isZh.value
|
||||
? { title: '切换主题', light: '浅色', dark: '深色', auto: '跟随系统' }
|
||||
: { title: 'Switch theme', light: 'Light', dark: 'Dark', auto: 'System' },
|
||||
);
|
||||
const options = computed<Array<{ label: string; value: ThemeMode }>>(() => [
|
||||
{ label: labels.value.light, value: 'light' },
|
||||
{ label: labels.value.dark, value: 'dark' },
|
||||
{ label: labels.value.auto, value: 'auto' },
|
||||
]);
|
||||
|
||||
function choose(value: ThemeMode) {
|
||||
setThemeMode(value);
|
||||
open.value = false;
|
||||
}
|
||||
|
||||
function close() {
|
||||
open.value = false;
|
||||
}
|
||||
|
||||
onMounted(() => document.addEventListener('click', close));
|
||||
onBeforeUnmount(() => document.removeEventListener('click', close));
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.theme-wrap {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
}
|
||||
.theme-button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
background: transparent;
|
||||
color: var(--text);
|
||||
cursor: pointer;
|
||||
}
|
||||
.theme-button svg {
|
||||
width: 21px;
|
||||
height: 21px;
|
||||
fill: none;
|
||||
stroke: currentColor;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
stroke-width: 1.8;
|
||||
}
|
||||
.theme-button:active,
|
||||
.theme-button:hover {
|
||||
background: rgba(46, 84, 150, 0.08);
|
||||
}
|
||||
.theme-menu {
|
||||
position: absolute;
|
||||
top: calc(100% + 6px);
|
||||
right: 0;
|
||||
z-index: 20;
|
||||
min-width: 118px;
|
||||
margin: 0;
|
||||
padding: 6px;
|
||||
list-style: none;
|
||||
background: var(--card-bg);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
|
||||
}
|
||||
.theme-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 9px 12px;
|
||||
border-radius: 7px;
|
||||
font-size: 14px;
|
||||
color: var(--text);
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.theme-item:active,
|
||||
.theme-item:hover {
|
||||
background: var(--soft-bg);
|
||||
}
|
||||
.theme-item.active {
|
||||
color: var(--brand);
|
||||
font-weight: 600;
|
||||
}
|
||||
.theme-check {
|
||||
color: var(--brand);
|
||||
}
|
||||
.theme-menu-enter-active,
|
||||
.theme-menu-leave-active {
|
||||
transition:
|
||||
opacity 0.16s ease,
|
||||
transform 0.16s ease;
|
||||
transform-origin: top right;
|
||||
}
|
||||
.theme-menu-enter-from,
|
||||
.theme-menu-leave-to {
|
||||
opacity: 0;
|
||||
transform: scale(0.92) translateY(-4px);
|
||||
}
|
||||
:global(html[data-theme='dark']) .theme-button:active,
|
||||
:global(html[data-theme='dark']) .theme-button:hover {
|
||||
background: rgba(148, 163, 184, 0.14);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,46 @@
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
export type ThemeMode = 'light' | 'dark' | 'auto';
|
||||
|
||||
const KEY = 'artveris_client_theme';
|
||||
const modes: ThemeMode[] = ['light', 'dark', 'auto'];
|
||||
const media = window.matchMedia('(prefers-color-scheme: dark)');
|
||||
const systemDark = ref(media.matches);
|
||||
|
||||
media.addEventListener('change', (event) => {
|
||||
systemDark.value = event.matches;
|
||||
});
|
||||
|
||||
function getInitialMode(): ThemeMode {
|
||||
const saved = localStorage.getItem(KEY) as ThemeMode | null;
|
||||
return saved && modes.includes(saved) ? saved : 'auto';
|
||||
}
|
||||
|
||||
const mode = ref<ThemeMode>(getInitialMode());
|
||||
const isDark = computed(() => mode.value === 'dark' || (mode.value === 'auto' && systemDark.value));
|
||||
|
||||
function applyTheme() {
|
||||
const root = document.documentElement;
|
||||
if (mode.value === 'auto') {
|
||||
root.removeAttribute('data-theme');
|
||||
} else {
|
||||
root.setAttribute('data-theme', mode.value);
|
||||
}
|
||||
root.style.colorScheme = isDark.value ? 'dark' : 'light';
|
||||
}
|
||||
|
||||
export function setThemeMode(next: ThemeMode) {
|
||||
mode.value = next;
|
||||
localStorage.setItem(KEY, next);
|
||||
applyTheme();
|
||||
}
|
||||
|
||||
export function initTheme() {
|
||||
applyTheme();
|
||||
}
|
||||
|
||||
export function useTheme() {
|
||||
return { mode, isDark, setThemeMode };
|
||||
}
|
||||
|
||||
initTheme();
|
||||
@@ -2,6 +2,7 @@ import { createApp } from 'vue';
|
||||
import App from './App.vue';
|
||||
import router from './router';
|
||||
import { i18n } from './locales';
|
||||
import './composables/useTheme';
|
||||
import './styles.css';
|
||||
|
||||
createApp(App).use(router).use(i18n).mount('#app');
|
||||
|
||||
@@ -23,6 +23,30 @@
|
||||
--shell-shadow: 0 0 24px rgba(0, 0, 0, 0.24);
|
||||
}
|
||||
}
|
||||
:root[data-theme='light'] {
|
||||
color-scheme: light;
|
||||
--brand: #1f3864;
|
||||
--brand-2: #2e5496;
|
||||
--bg: #f3f5f9;
|
||||
--card-bg: #fff;
|
||||
--soft-bg: #f6f8fb;
|
||||
--border: #d0d7e2;
|
||||
--text: #1f2937;
|
||||
--muted: #6b7280;
|
||||
--shell-shadow: 0 0 24px rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
:root[data-theme='dark'] {
|
||||
color-scheme: dark;
|
||||
--brand: #7dd3fc;
|
||||
--brand-2: #5eead4;
|
||||
--bg: #0f172a;
|
||||
--card-bg: #111827;
|
||||
--soft-bg: #1f2937;
|
||||
--border: #334155;
|
||||
--text: #e5e7eb;
|
||||
--muted: #94a3b8;
|
||||
--shell-shadow: 0 0 24px rgba(0, 0, 0, 0.24);
|
||||
}
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
<img class="logo" :src="appIconUrl" alt="" />
|
||||
<h1>{{ t('home.title') }}</h1>
|
||||
<p class="muted">{{ t('home.hint') }}</p>
|
||||
<button class="lang" @click="toggleLang">{{ otherLangLabel }}</button>
|
||||
<div class="home-actions">
|
||||
<theme-switch />
|
||||
<button class="lang" @click="toggleLang">{{ otherLangLabel }}</button>
|
||||
</div>
|
||||
<footer class="footer muted">
|
||||
<span>{{ appName }}</span>
|
||||
<span v-if="filingInfo">{{ filingInfo }}</span>
|
||||
@@ -17,6 +20,7 @@ import { useI18n } from 'vue-i18n';
|
||||
import { fetchAppInfo } from '@/api';
|
||||
import { setLocale, SUPPORTED_LOCALES } from '@/locales';
|
||||
import { resolveAppIcon, setFavicon } from '@/utils/appIcon';
|
||||
import ThemeSwitch from '@/components/ThemeSwitch.vue';
|
||||
|
||||
const { t, locale } = useI18n();
|
||||
const appName = ref('');
|
||||
@@ -65,13 +69,18 @@ h1 {
|
||||
margin: 8px 0 0;
|
||||
}
|
||||
.lang {
|
||||
margin-top: 16px;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--card-bg);
|
||||
border-radius: 999px;
|
||||
padding: 6px 18px;
|
||||
color: var(--brand);
|
||||
}
|
||||
.home-actions {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-top: 16px;
|
||||
}
|
||||
.footer {
|
||||
position: absolute;
|
||||
bottom: 28px;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<header class="topbar">
|
||||
<img class="topbar-icon" :src="appIconUrl" alt="" />
|
||||
<span class="topbar-name text-ellipsis">{{ topbarTitle }}</span>
|
||||
<theme-switch />
|
||||
<div class="lang-wrap">
|
||||
<button class="lang" :aria-label="t('lang.switch')" :title="t('lang.switch')" @click.stop="langOpen = !langOpen">
|
||||
<svg viewBox="0 0 512 512" width="22" height="22" aria-hidden="true">
|
||||
@@ -376,6 +377,7 @@ import { fetchTrace, fetchAppInfo } from '@/api';
|
||||
import { setLocale, SUPPORTED_LOCALES } from '@/locales';
|
||||
import { openMediaViewer } from '@/composables/openMediaViewer';
|
||||
import { resolveAppIcon, setFavicon } from '@/utils/appIcon';
|
||||
import ThemeSwitch from '@/components/ThemeSwitch.vue';
|
||||
|
||||
const route = useRoute();
|
||||
const { t, locale } = useI18n();
|
||||
@@ -1437,4 +1439,30 @@ watch(
|
||||
background: rgba(148, 163, 184, 0.14);
|
||||
}
|
||||
}
|
||||
:global(html[data-theme='light']) .topbar {
|
||||
background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(239, 249, 252, 0.96));
|
||||
color: #17324d;
|
||||
border-bottom-color: rgba(46, 84, 150, 0.12);
|
||||
box-shadow: 0 6px 18px rgba(31, 56, 100, 0.06);
|
||||
}
|
||||
:global(html[data-theme='light']) .lang {
|
||||
color: #17324d;
|
||||
}
|
||||
:global(html[data-theme='light']) .lang:active,
|
||||
:global(html[data-theme='light']) .lang:hover {
|
||||
background: rgba(46, 84, 150, 0.08);
|
||||
}
|
||||
:global(html[data-theme='dark']) .topbar {
|
||||
background: linear-gradient(135deg, rgba(15, 23, 42, 0.96), rgba(17, 24, 39, 0.96));
|
||||
color: var(--text);
|
||||
border-bottom-color: rgba(148, 163, 184, 0.18);
|
||||
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
:global(html[data-theme='dark']) .lang {
|
||||
color: var(--text);
|
||||
}
|
||||
:global(html[data-theme='dark']) .lang:active,
|
||||
:global(html[data-theme='dark']) .lang:hover {
|
||||
background: rgba(148, 163, 184, 0.14);
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user