From e1cbf289eda84a429a878302392366168e6ebeec Mon Sep 17 00:00:00 2001 From: yin <3313488199@qq.com> Date: Wed, 18 Mar 2026 17:47:43 +0800 Subject: [PATCH] =?UTF-8?q?18=E5=8F=B7=E7=9A=84=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/LangSelect/index.vue | 4 +- src/layout/component/TaskView/index.vue | 12 +- src/stores/modules/shortcuts.ts | 16 +- src/views/admin/land/index.vue | 309 ++++++- src/views/auth/approve.vue | 828 +++++++++++++++++- src/views/dashboard/components/WelcomCard.vue | 2 +- .../dashboard/components/forms/joinStore.vue | 17 +- .../components/forms/joinWarehouse.vue | 3 +- .../storage/receiving/component/Details.vue | 2 - .../receiving/component/DetailsPanel.vue | 117 +-- .../storage/receiving/component/Product.vue | 573 ++++++++++++ src/views/storage/receiving/index.vue | 16 +- .../storage/receiving/receiving-config.ts | 81 ++ src/views/storage/receiving/window/basic.vue | 118 +++ src/views/storage/receiving/window/log.vue | 7 + .../storage/receiving/window/product.vue | 7 + .../system/setting/printTemplate/index.vue | 15 +- 17 files changed, 1987 insertions(+), 140 deletions(-) create mode 100644 src/views/storage/receiving/component/Product.vue create mode 100644 src/views/storage/receiving/window/basic.vue create mode 100644 src/views/storage/receiving/window/log.vue create mode 100644 src/views/storage/receiving/window/product.vue diff --git a/src/components/LangSelect/index.vue b/src/components/LangSelect/index.vue index 958d78ec..794fd114 100644 --- a/src/components/LangSelect/index.vue +++ b/src/components/LangSelect/index.vue @@ -23,7 +23,7 @@ import { useI18n } from 'vue-i18n' import { useAppStore } from '@/stores/modules/app' import { ElMessage } from 'element-plus' -const { locale } = useI18n() +const { locale, messages } = useI18n() const appStore = useAppStore() const language = computed(() => appStore.language) @@ -31,10 +31,12 @@ const language = computed(() => appStore.language) const handleSetLanguage = (lang: string) => { locale.value = lang appStore.setLanguage(lang) + console.log('当前语言包内容:', messages.value[lang]) ElMessage({ message: 'Switch Language Success', type: 'success' }) + location.reload() } diff --git a/src/layout/component/TaskView/index.vue b/src/layout/component/TaskView/index.vue index 6128750e..7ad9cdbc 100644 --- a/src/layout/component/TaskView/index.vue +++ b/src/layout/component/TaskView/index.vue @@ -11,9 +11,9 @@ v-bind="isExternal(shortcut.path) ? { href: shortcut.path, target: '_blank' } : { to: shortcut.path }" class="shortcut-item" > - + - {{ $t('menu.' + shortcut.title) }} + {{ generateTitle(shortcut.title) }} @@ -81,7 +81,7 @@ const scrollPane = ref() const visitedViews = computed(() => tagsViewStore.visitedViews) const routes = computed(() => permissionStore.routes) -const shortcuts = computed(() => shortcutsStore.shortcuts) +const shortcuts = computed(() => shortcutsStore.$state?.shortcuts ?? []) const shortcutExpanded = computed(() => settingsStore.shortcutExpanded) const toggleShortcut = () => { @@ -101,10 +101,10 @@ const isAffix = (tag: any) => { } const generateTitle = (title: any) => { - const hasKey = te('menu.' + title) + const titleKey = 'menu.' + title + const hasKey = te(titleKey) if (hasKey) { - const translatedTitle = t('menu.' + title) - return translatedTitle + return t(titleKey) } return title || 'no-name' } diff --git a/src/stores/modules/shortcuts.ts b/src/stores/modules/shortcuts.ts index aa7af649..73d446cb 100644 --- a/src/stores/modules/shortcuts.ts +++ b/src/stores/modules/shortcuts.ts @@ -47,14 +47,9 @@ export const useShortcutsStore = defineStore('shortcuts', () => { const is404 = resolved.matched.some(r => r.name === 'Page404' || r.path === '/:pathMatch(.*)*' || r.redirect === '/404') if (is404) return false - // Update title/icon from current route meta if available to keep it fresh - if (resolved.meta?.title) { - s.title = resolved.meta.title as string - } - if (resolved.meta?.icon) { - s.icon = resolved.meta.icon as string - } - + // Do not override title/icon if they already exist to avoid language-locked titles + // Only update if current meta title/icon is different from saved one + // Removed forced s.title update to prevent saving translated strings return true }) } else { @@ -129,6 +124,11 @@ export const useShortcutsStore = defineStore('shortcuts', () => { } }) + // Watch for shortcuts changes to save them, ensuring deep persistence + watch(shortcuts, () => { + saveShortcuts() + }, { deep: true }) + return { shortcuts, addShortcut, diff --git a/src/views/admin/land/index.vue b/src/views/admin/land/index.vue index 9b2f4c6b..99a8c87d 100644 --- a/src/views/admin/land/index.vue +++ b/src/views/admin/land/index.vue @@ -36,12 +36,12 @@ - +
- 重置模拟数据 + 重置数据
- +
- +
- + - - - - - - - - - - - - 立即新增语言数据 - - + + + +
+

新增语言信息

+
+ + + + + + + + + + + + 提交新增语言 + + +
+
+ + + +
+

翻译工具

+
+ + 获取字段 + 快速翻译 + 模板填充 + 重置模板 +
+
+ +
+
+

字段列表

+ + +
{{ f }}
+
+
+
尚未获取字段,点击“获取字段”以提取模板字段
+
+ +
+

目标语言翻译(可编辑)

+
+
+
{{ f }}
+ +
+
+
无可翻译字段
+
+
+
+
+
@@ -138,6 +184,7 @@ import { ElMessage } from 'element-plus' import localZh from '@/lang/zh-CN' import localEn from '@/lang/en-US' import _ from 'lodash' +import * as indexApi from '@/api/index' // 标签页选中项 const activeTab = ref('local') @@ -171,7 +218,7 @@ const mockServerData = { "Dashboard": "远程主页控制台" } }, - 'en-US': { + 'en': { "common": { "add": "Add (Server Overwrite)", "server_label": "Server-side specific key" @@ -182,14 +229,51 @@ const mockServerData = { } } +/** + * 递归深度合并对象 (同步 src/lang/index.ts 的逻辑) + */ +function deepMerge(target: any, source: any, parentKey: string = '') { + if (!source) return target + + Object.keys(source).forEach(key => { + const sourceValue = source[key] + const targetValue = target[key] + const fullKey = parentKey ? `${parentKey}.${key}` : key + + if (sourceValue && typeof sourceValue === 'object' && !Array.isArray(sourceValue)) { + if (!targetValue || typeof targetValue !== 'object') { + target[key] = {} + } + deepMerge(target[key], sourceValue, fullKey) + } else { + // 只有当源对象有值时才尝试合并 + if (sourceValue !== null && sourceValue !== undefined && sourceValue !== '') { + const sourceLower = typeof sourceValue === 'string' ? sourceValue.toLowerCase() : ''; + const fullKeyLower = fullKey.toLowerCase(); + const keyLower = key.toLowerCase(); + + // 占位符判断:如果值等于 key 或 fullKey,则视为未翻译 + const isPlaceholder = typeof sourceValue === 'string' && + (sourceLower === fullKeyLower || sourceLower === keyLower); + + if (!isPlaceholder || !targetValue) { + target[key] = sourceValue + } + } + } + }) + return target +} + /** * 项目合并后的翻译包 (深度合并:本地 + 服务器) */ const mergedZhString = computed(() => { try { const serverObj = serverZhString.value ? JSON.parse(serverZhString.value) : {} - // 服务器数据会覆盖本地同名冲突字段 - const merged = _.merge({}, localZh, serverObj) + // 克隆本地数据以避免直接修改 + const localCopy = JSON.parse(JSON.stringify(localZh)) + const merged = deepMerge(localCopy, serverObj) return JSON.stringify(merged, null, 2) } catch (e) { return '解析JSON失败:请确保服务器端输入的是有效的 JSON 字符串' @@ -199,7 +283,8 @@ const mergedZhString = computed(() => { const mergedEnString = computed(() => { try { const serverObj = serverEnString.value ? JSON.parse(serverEnString.value) : {} - const merged = _.merge({}, localEn, serverObj) + const localCopy = JSON.parse(JSON.stringify(localEn)) + const merged = deepMerge(localCopy, serverObj) return JSON.stringify(merged, null, 2) } catch (e) { return '解析JSON失败:请确保服务器端输入的是有效的 JSON 字符串' @@ -208,26 +293,75 @@ const mergedEnString = computed(() => { /** * 语言表单功能 + * 自动根据本地 zh-CN 语言包结构生成空值模板,用作新增语言的初始内容 */ +function makeTemplate(obj: any): any { + if (obj === null || typeof obj !== 'object') return '' + const out: any = Array.isArray(obj) ? [] : {} + for (const k in obj) { + const v = obj[k] + if (v && typeof v === 'object') { + out[k] = makeTemplate(v) + } else { + out[k] = '' + } + } + return out +} + +const defaultNewLangContent = JSON.stringify(makeTemplate(localZh), null, 2) + const newLangForm = ref({ name: '', code: '', - content: '{\n "common": {},\n "menu": {}\n}' + content: defaultNewLangContent }) onMounted(() => { - // 模拟从后端接口获取数据并初始化 - initMockServerData() + // 尝试从后端接口获取数据并初始化,失败时回退到模拟数据 + loadServerFromApi() }) +// 从后端加载服务器语言包并展示在“服务器语言包”区域,失败时使用 mock 数据 +const loadServerFromApi = async () => { + try { + const resZh = await indexApi.getI18nMessage({ language: 'zh-CN' }) + const resEn = await indexApi.getI18nMessage({ language: 'en' }) + + if (resZh && resZh.data) { + const payload = resZh.data.messages || resZh.data + serverZhString.value = JSON.stringify(payload, null, 2) + } + + if (resEn && resEn.data) { + const payload = resEn.data.messages || resEn.data + serverEnString.value = JSON.stringify(payload, null, 2) + } + + // 如果两者都没有数据,则使用本地模拟数据 + if ((!resZh || !resZh.data) && (!resEn || !resEn.data)) { + initMockServerData() + } + } catch (e) { + // 回退到模拟数据 + initMockServerData() + } +} + const initMockServerData = () => { serverZhString.value = JSON.stringify(mockServerData['zh-CN'], null, 2) - serverEnString.value = JSON.stringify(mockServerData['en-US'], null, 2) + serverEnString.value = JSON.stringify(mockServerData['en'], null, 2) } -const handleResetServerData = () => { - initMockServerData() - ElMessage.success('已清空手动修改内容并重置为初始模拟数据') +const handleResetServerData = async () => { + // 重置应优先从服务器拉取最新数据;失败时回退到模拟数据 + try { + await loadServerFromApi() + ElMessage.success('已从服务器重新加载语言包(若服务器不可用则回退到模拟数据)') + } catch (e) { + initMockServerData() + ElMessage.success('服务器加载失败,已回退到初始模拟数据') + } } // 模拟保存服务器端数据修改 @@ -255,6 +389,111 @@ const handleAddLanguage = () => { ElMessage.error('输入的数据内容不符合标准 JSON 语法') } } + +// ---------- 翻译工具(前端模拟) ---------- +const fieldsList = ref([]) +const translations = ref>({}) +const targetLang = ref('') + +// 从 newLangForm.content 中提取所有 leaf 字段路径 +function collectFields(obj: any, prefix = ''): string[] { + if (obj === null || typeof obj !== 'object') return [prefix].filter(Boolean) + let res: string[] = [] + for (const k in obj) { + const v = obj[k] + const path = prefix ? `${prefix}.${k}` : k + if (v && typeof v === 'object' && !Array.isArray(v)) { + res = res.concat(collectFields(v, path)) + } else { + res.push(path) + } + } + return res +} + +const getFields = () => { + try { + const obj = JSON.parse(newLangForm.value.content || '{}') + const keys = collectFields(obj) + fieldsList.value = keys + // 初始化 translations + const map: Record = {} + keys.forEach(k => { map[k] = '' }) + translations.value = map + ElMessage.success(`已提取 ${keys.length} 个字段`) + } catch (e) { + ElMessage.error('无法解析模板 JSON,请检查格式') + } +} + +// 模拟调用翻译接口,返回 map +function fakeTranslateRequest(items: string[], lang: string): Promise> { + return new Promise(resolve => { + setTimeout(() => { + const out: Record = {} + items.forEach(i => { + out[i] = `${lang || 'auto'} 翻译: ${i.split('.').slice(-1)[0]}` + }) + resolve(out) + }, 600) + }) +} + +const quickTranslate = async () => { + if (!fieldsList.value.length) { + ElMessage.warning('请先点击【获取字段】') + return + } + if (!targetLang.value) { + ElMessage.warning('请填写目标语言代码,例如:ja-JP') + return + } + const items = [...fieldsList.value] + const res = await fakeTranslateRequest(items, targetLang.value) + // 填充 translations + for (const k of Object.keys(res)) { + translations.value[k] = res[k] ?? '' + } + ElMessage.success('快速翻译已完成(模拟)') +} + +// 重置所有翻译输入框为空 +const resetTemplate = () => { + if (!fieldsList.value.length) { + ElMessage.info('没有可重置的字段') + return + } + for (const k of Object.keys(translations.value)) { + translations.value[k] = '' + } + ElMessage.success('已重置所有翻译输入框') +} + +// 将 translations 填充回 newLangForm.content(覆盖模板对应叶子节点) +const fillTemplate = () => { + try { + const obj = JSON.parse(newLangForm.value.content || '{}') + for (const path of Object.keys(translations.value)) { + const parts = path.split('.') + let cur: any = obj + for (let i = 0; i < parts.length - 1; i++) { + const key = parts[i] + if (!key) continue + if (cur[key] == null || typeof cur[key] !== 'object') { + cur[key] = {} + } + cur = cur[key] + } + const lastKey = parts[parts.length - 1] + if (!lastKey) continue + cur[lastKey] = translations.value[path] ?? '' + } + newLangForm.value.content = JSON.stringify(obj, null, 2) + ElMessage.success('已将翻译结果填充到模板') + } catch (e) { + ElMessage.error('模板填充失败:无法解析当前模板 JSON') + } +} \ No newline at end of file diff --git a/src/views/dashboard/components/WelcomCard.vue b/src/views/dashboard/components/WelcomCard.vue index 9fbfaf4e..94c2f43a 100644 --- a/src/views/dashboard/components/WelcomCard.vue +++ b/src/views/dashboard/components/WelcomCard.vue @@ -98,7 +98,7 @@ const moduleComponents: Record = { joinStore: defineAsyncComponent(() => import('./forms/joinStore.vue')), createWarehouse: defineAsyncComponent(() => import('./forms/createWarehouse.vue')), joinWarehouse: defineAsyncComponent(() => import('./forms/joinWarehouse.vue')) -} +} const formTitles: Record = { createStore: '创建货主', diff --git a/src/views/dashboard/components/forms/joinStore.vue b/src/views/dashboard/components/forms/joinStore.vue index 5ff25dfc..c9a515e5 100644 --- a/src/views/dashboard/components/forms/joinStore.vue +++ b/src/views/dashboard/components/forms/joinStore.vue @@ -123,11 +123,22 @@ const handleSubmit = async () => { if (valid) { loading.value = true try { - const res = await joinStore(form) - authLink.value = res.data // Assuming API returns the link in data - ElMessage.success('生成链接成功') + const res:any = await joinStore(form) + const baseURL = window.location.origin + if (res && res.code === 200) { + const joinToken = res.data && res.data.joinToken + if (joinToken) { + authLink.value = `${baseURL}/auth/approve?type=store&code=${joinToken}` + ElMessage.success('生成链接成功') + } else { + ElMessage.error('未返回有效的链接数据') + } + } else { + ElMessage.error(res?.message || '生成链接失败') + } } catch (error) { console.error(error) + ElMessage.error('生成链接失败') } finally { loading.value = false } diff --git a/src/views/dashboard/components/forms/joinWarehouse.vue b/src/views/dashboard/components/forms/joinWarehouse.vue index 6a9585e9..1018968e 100644 --- a/src/views/dashboard/components/forms/joinWarehouse.vue +++ b/src/views/dashboard/components/forms/joinWarehouse.vue @@ -125,11 +125,10 @@ const handleSubmit = async () => { try { const res: any = await joinWarehouse(form) const baseUrl = window.location.origin - // 与 vue2 保持一致:仅当后端返回 code === 200 时认为生成成功 if (res && res.code === 200) { const joinToken = res.data && res.data.joinToken if (joinToken) { - authLink.value = `${baseUrl}/#/auth/approve?type=store&code=${joinToken}` + authLink.value = `${baseUrl}/auth/approve?type=store&code=${joinToken}` ElMessage.success('生成链接成功') } else { ElMessage.error('未返回有效的 joinToken') diff --git a/src/views/storage/receiving/component/Details.vue b/src/views/storage/receiving/component/Details.vue index 77880a03..c6c4c489 100644 --- a/src/views/storage/receiving/component/Details.vue +++ b/src/views/storage/receiving/component/Details.vue @@ -1,5 +1,3 @@ - -