feat: 添加客户端主题切换并优化导出状态

This commit is contained in:
Nixevol
2026-07-05 04:14:17 +08:00
parent 09a68ad0df
commit e8e514f6dd
10 changed files with 273 additions and 6 deletions
+2
View File
@@ -149,6 +149,8 @@
- 追溯码管理入口与筛选修正(2026-07-05):全局 `/trace-codes` 从隐藏页恢复为左侧独立导航“追溯码管理”,仍保留艺术品详情页的数据管理入口;艺术品档案列表中点击“档案编号”改为进入作品编辑/详情页,右侧“数据管理”图标继续进入该档案追溯码管理。追溯码管理搜索框加宽,后端关键词搜索扩展到追溯码、完整编码、链接、档案编号、名称、艺术家、批次编号、分组名称和备注。分组管理接口不带参数时仍返回全部分组;生成追溯码弹窗会预加载作品下拉,避免初次点开显示无数据,并在选择作品后按该作品已有追溯码使用过的分组加载分组选项。 - 追溯码管理入口与筛选修正(2026-07-05):全局 `/trace-codes` 从隐藏页恢复为左侧独立导航“追溯码管理”,仍保留艺术品详情页的数据管理入口;艺术品档案列表中点击“档案编号”改为进入作品编辑/详情页,右侧“数据管理”图标继续进入该档案追溯码管理。追溯码管理搜索框加宽,后端关键词搜索扩展到追溯码、完整编码、链接、档案编号、名称、艺术家、批次编号、分组名称和备注。分组管理接口不带参数时仍返回全部分组;生成追溯码弹窗会预加载作品下拉,避免初次点开显示无数据,并在选择作品后按该作品已有追溯码使用过的分组加载分组选项。
- 追溯码搜索框宽度微调(2026-07-05):追溯码管理工具栏搜索框按扩展后的占位提示加宽,桌面端使用 `width: min(560px, 46vw)` 且最小 420px,小屏仍由媒体查询切换为 100% 宽,避免提示文案被过早截断。 - 追溯码搜索框宽度微调(2026-07-05):追溯码管理工具栏搜索框按扩展后的占位提示加宽,桌面端使用 `width: min(560px, 46vw)` 且最小 420px,小屏仍由媒体查询切换为 100% 宽,避免提示文案被过早截断。
- 追溯码导出按钮交互(2026-07-05):全局追溯码管理页和档案内追溯码管理页共用 `TraceCodePanel`,导出按钮由下拉菜单改为单击即导出;导出范围按“已勾选 > 当前筛选 > 全部”自动判断,按钮文案分别显示“导出(已选x项)”“导出(当前筛选)”或“导出”。固定档案页自身的 `artworkId` 不算用户筛选,全局页 URL/表头/关键词筛选会计入“当前筛选”。 - 追溯码导出按钮交互(2026-07-05):全局追溯码管理页和档案内追溯码管理页共用 `TraceCodePanel`,导出按钮由下拉菜单改为单击即导出;导出范围按“已勾选 > 当前筛选 > 全部”自动判断,按钮文案分别显示“导出(已选x项)”“导出(当前筛选)”或“导出”。固定档案页自身的 `artworkId` 不算用户筛选,全局页 URL/表头/关键词筛选会计入“当前筛选”。
- 客户端主题切换与导出防重复(2026-07-05):客户端新增轻量主题状态 `apps/client/src/composables/useTheme.ts` 和 `ThemeSwitch.vue`,首页与溯源详情页均显示主题切换按钮;默认主题为 `auto` 跟随系统,手动选择浅色/深色时写入 `localStorage: artveris_client_theme` 并通过 `html[data-theme]` 覆盖 CSS 变量。追溯码管理导出按钮新增 `exporting` loading/禁用状态,下载处理过程中会阻止重复点击。
- 溯源模板字段标识提示(2026-07-05):模板字段配置中“英文标识”输入框占位提示缩短为“英文唯一标识”(英文:`Unique English key`),避免窄输入框内示例文本过长导致显示不全。
## 当前代码基准与注意事项 ## 当前代码基准与注意事项
+9 -2
View File
@@ -17,7 +17,7 @@
<template #icon><n-icon :component="FolderOutline" /></template> <template #icon><n-icon :component="FolderOutline" /></template>
{{ t('pages.traceCode.manageGroups') }} {{ t('pages.traceCode.manageGroups') }}
</n-button> </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> <template #icon><n-icon :component="DownloadOutline" /></template>
{{ exportButtonText }} {{ exportButtonText }}
</n-button> </n-button>
@@ -277,6 +277,7 @@ const qrModal = ref(false);
const qrSrc = ref(''); const qrSrc = ref('');
const qrUrl = ref(''); const qrUrl = ref('');
let qrBlobUrl = ''; let qrBlobUrl = '';
const exporting = ref(false);
const groupModal = ref(false); const groupModal = ref(false);
const groupForm = reactive<{ name: string }>({ name: '' }); const groupForm = reactive<{ name: string }>({ name: '' });
@@ -577,6 +578,7 @@ const exportButtonText = computed(() => {
}); });
async function onExport() { async function onExport() {
if (exporting.value) return;
const params: Record<string, unknown> = {}; const params: Record<string, unknown> = {};
if (checkedKeys.value.length) { if (checkedKeys.value.length) {
params.ids = checkedKeys.value.map(String).join(','); params.ids = checkedKeys.value.map(String).join(',');
@@ -589,7 +591,12 @@ async function onExport() {
if (query.outboundStatus) params.outboundStatus = query.outboundStatus; if (query.outboundStatus) params.outboundStatus = query.outboundStatus;
if (query.keyword) params.keyword = query.keyword; 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) { async function batchAssignGroup(key: string) {
+1 -1
View File
@@ -204,7 +204,7 @@
"create": "New Template", "create": "New Template",
"edit": "Edit Template", "edit": "Edit Template",
"namePlaceholder": "Enter template name", "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", "sortHint": "Field order = display order on consumer page; use arrows to reorder",
"defaultFields": { "defaultFields": {
"craft": "Craft", "craft": "Craft",
+1 -1
View File
@@ -204,7 +204,7 @@
"create": "新建模板", "create": "新建模板",
"edit": "编辑模板", "edit": "编辑模板",
"namePlaceholder": "请输入模板名称", "namePlaceholder": "请输入模板名称",
"fieldKeyTip": "英文唯一标识,如 craft", "fieldKeyTip": "英文唯一标识",
"sortHint": "字段顺序即客户端展示顺序,可用上下箭头调整", "sortHint": "字段顺序即客户端展示顺序,可用上下箭头调整",
"defaultFields": { "defaultFields": {
"craft": "工艺", "craft": "工艺",
+150
View File
@@ -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>
+46
View File
@@ -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();
+1
View File
@@ -2,6 +2,7 @@ import { createApp } from 'vue';
import App from './App.vue'; import App from './App.vue';
import router from './router'; import router from './router';
import { i18n } from './locales'; import { i18n } from './locales';
import './composables/useTheme';
import './styles.css'; import './styles.css';
createApp(App).use(router).use(i18n).mount('#app'); createApp(App).use(router).use(i18n).mount('#app');
+24
View File
@@ -23,6 +23,30 @@
--shell-shadow: 0 0 24px rgba(0, 0, 0, 0.24); --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; box-sizing: border-box;
-webkit-tap-highlight-color: transparent; -webkit-tap-highlight-color: transparent;
+11 -2
View File
@@ -3,7 +3,10 @@
<img class="logo" :src="appIconUrl" alt="" /> <img class="logo" :src="appIconUrl" alt="" />
<h1>{{ t('home.title') }}</h1> <h1>{{ t('home.title') }}</h1>
<p class="muted">{{ t('home.hint') }}</p> <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"> <footer class="footer muted">
<span>{{ appName }}</span> <span>{{ appName }}</span>
<span v-if="filingInfo">{{ filingInfo }}</span> <span v-if="filingInfo">{{ filingInfo }}</span>
@@ -17,6 +20,7 @@ import { useI18n } from 'vue-i18n';
import { fetchAppInfo } from '@/api'; import { fetchAppInfo } from '@/api';
import { setLocale, SUPPORTED_LOCALES } from '@/locales'; import { setLocale, SUPPORTED_LOCALES } from '@/locales';
import { resolveAppIcon, setFavicon } from '@/utils/appIcon'; import { resolveAppIcon, setFavicon } from '@/utils/appIcon';
import ThemeSwitch from '@/components/ThemeSwitch.vue';
const { t, locale } = useI18n(); const { t, locale } = useI18n();
const appName = ref(''); const appName = ref('');
@@ -65,13 +69,18 @@ h1 {
margin: 8px 0 0; margin: 8px 0 0;
} }
.lang { .lang {
margin-top: 16px;
border: 1px solid var(--border); border: 1px solid var(--border);
background: var(--card-bg); background: var(--card-bg);
border-radius: 999px; border-radius: 999px;
padding: 6px 18px; padding: 6px 18px;
color: var(--brand); color: var(--brand);
} }
.home-actions {
display: inline-flex;
align-items: center;
gap: 10px;
margin-top: 16px;
}
.footer { .footer {
position: absolute; position: absolute;
bottom: 28px; bottom: 28px;
+28
View File
@@ -4,6 +4,7 @@
<header class="topbar"> <header class="topbar">
<img class="topbar-icon" :src="appIconUrl" alt="" /> <img class="topbar-icon" :src="appIconUrl" alt="" />
<span class="topbar-name text-ellipsis">{{ topbarTitle }}</span> <span class="topbar-name text-ellipsis">{{ topbarTitle }}</span>
<theme-switch />
<div class="lang-wrap"> <div class="lang-wrap">
<button class="lang" :aria-label="t('lang.switch')" :title="t('lang.switch')" @click.stop="langOpen = !langOpen"> <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"> <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 { setLocale, SUPPORTED_LOCALES } from '@/locales';
import { openMediaViewer } from '@/composables/openMediaViewer'; import { openMediaViewer } from '@/composables/openMediaViewer';
import { resolveAppIcon, setFavicon } from '@/utils/appIcon'; import { resolveAppIcon, setFavicon } from '@/utils/appIcon';
import ThemeSwitch from '@/components/ThemeSwitch.vue';
const route = useRoute(); const route = useRoute();
const { t, locale } = useI18n(); const { t, locale } = useI18n();
@@ -1437,4 +1439,30 @@ watch(
background: rgba(148, 163, 184, 0.14); 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> </style>