From 0a78b72fdf00e6333634fafffa6868d69c2553a2 Mon Sep 17 00:00:00 2001 From: harrywan Date: Wed, 4 Sep 2024 15:27:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20plugin-layout=E7=9A=84=E9=A1=B5?= =?UTF-8?q?=E7=AD=BE=E4=BF=A1=E6=81=AF=E6=94=AF=E6=8C=81=E5=9B=BD=E9=99=85?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 3 + packages/fes-plugin-layout/src/index.js | 7 +++ .../src/runtime/helpers/fillMenu.js | 8 +-- .../src/runtime/helpers/pluginLocale.js | 9 +-- .../src/runtime/helpers/svg.js | 8 +-- .../src/runtime/helpers/utils.js | 5 +- .../src/runtime/locales/layout/en-US.js | 6 ++ .../src/runtime/locales/layout/zh-CN.js | 6 ++ .../src/runtime/views/MultiTabProvider.vue | 59 +++++++++++++------ packages/fes-plugin-locale/src/index.js | 23 ++++++-- .../fes-plugin-locale/src/runtime/runtime.js | 4 +- .../src/runtime/views/SelectLang.vue | 10 ++-- packages/fes-plugin-locale/src/utils/index.js | 44 +++++++------- 13 files changed, 127 insertions(+), 65 deletions(-) create mode 100644 packages/fes-plugin-layout/src/runtime/locales/layout/en-US.js create mode 100644 packages/fes-plugin-layout/src/runtime/locales/layout/zh-CN.js diff --git a/.vscode/settings.json b/.vscode/settings.json index 1d237d44..fb221bd7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -31,5 +31,8 @@ "source": "./fixtures/output/**/*.*", "target": "./fixtures/input/" } + ], + "cSpell.words": [ + "unref" ] } diff --git a/packages/fes-plugin-layout/src/index.js b/packages/fes-plugin-layout/src/index.js index 5ff334de..5fe82f90 100644 --- a/packages/fes-plugin-layout/src/index.js +++ b/packages/fes-plugin-layout/src/index.js @@ -30,6 +30,13 @@ export default (api) => { const absRuntimeFilePath = join(namespace, 'runtime.js'); + api.register({ + key: 'addExtraLocales', + fn: () => [ + join(api.paths.absTmpPath, namespace, 'locales'), + ], + }); + api.onGenerateFiles(async () => { // .fes配置 const userConfig = { diff --git a/packages/fes-plugin-layout/src/runtime/helpers/fillMenu.js b/packages/fes-plugin-layout/src/runtime/helpers/fillMenu.js index 366dfa4f..b6345a0a 100644 --- a/packages/fes-plugin-layout/src/runtime/helpers/fillMenu.js +++ b/packages/fes-plugin-layout/src/runtime/helpers/fillMenu.js @@ -1,4 +1,4 @@ -const getMetaByName = (config, name) => { +function getMetaByName(config, name) { let res = {}; if (Array.isArray(config)) { for (let i = 0; i < config.length; i++) { @@ -17,9 +17,9 @@ const getMetaByName = (config, name) => { } } return res; -}; +} -const fillMenuByRoute = (menuConfig, routeConfig, dep = 0) => { +function fillMenuByRoute(menuConfig, routeConfig, dep = 0) { dep += 1; if (dep > 3) { console.warn('[plugin-layout]: 菜单层级最好不要超出三层!'); @@ -44,6 +44,6 @@ const fillMenuByRoute = (menuConfig, routeConfig, dep = 0) => { }); } return arr; -}; +} export default fillMenuByRoute; diff --git a/packages/fes-plugin-layout/src/runtime/helpers/pluginLocale.js b/packages/fes-plugin-layout/src/runtime/helpers/pluginLocale.js index 0691f188..f6ab7a9c 100644 --- a/packages/fes-plugin-layout/src/runtime/helpers/pluginLocale.js +++ b/packages/fes-plugin-layout/src/runtime/helpers/pluginLocale.js @@ -1,6 +1,6 @@ import { plugin } from '@@/core/coreExports'; -export const transTitle = (name) => { +export function transTitle(name) { if (!/^\$\S+$/.test(name)) { return name; } @@ -10,10 +10,10 @@ export const transTitle = (name) => { return t(name.slice(1)); } return name; -}; +} -export const transform = (menus) => - menus.map((menu) => { +export function transform(menus) { + return menus.map((menu) => { const copy = { ...menu, label: transTitle(menu.label), @@ -23,3 +23,4 @@ export const transform = (menus) => } return copy; }); +} diff --git a/packages/fes-plugin-layout/src/runtime/helpers/svg.js b/packages/fes-plugin-layout/src/runtime/helpers/svg.js index f42d5cb5..54ea0491 100644 --- a/packages/fes-plugin-layout/src/runtime/helpers/svg.js +++ b/packages/fes-plugin-layout/src/runtime/helpers/svg.js @@ -2,7 +2,7 @@ const isStr = function (str) { return typeof str === 'string'; }; -export const isValid = (elm) => { +export function isValid(elm) { if (elm.nodeType === 1) { if (elm.nodeName.toLowerCase() === 'script') { return false; @@ -22,9 +22,9 @@ export const isValid = (elm) => { } } return true; -}; +} -export const validateContent = (svgContent) => { +export function validateContent(svgContent) { const div = document.createElement('div'); div.innerHTML = svgContent; @@ -46,4 +46,4 @@ export const validateContent = (svgContent) => { } } return ''; -}; +} diff --git a/packages/fes-plugin-layout/src/runtime/helpers/utils.js b/packages/fes-plugin-layout/src/runtime/helpers/utils.js index 29750c4d..c104bc76 100644 --- a/packages/fes-plugin-layout/src/runtime/helpers/utils.js +++ b/packages/fes-plugin-layout/src/runtime/helpers/utils.js @@ -1,8 +1,9 @@ -export const flatNodes = (nodes = []) => - nodes.reduce((res, node) => { +export function flatNodes(nodes = []) { + return nodes.reduce((res, node) => { res.push(node); if (node.children) { res = res.concat(flatNodes(node.children)); } return res; }, []); +} diff --git a/packages/fes-plugin-layout/src/runtime/locales/layout/en-US.js b/packages/fes-plugin-layout/src/runtime/locales/layout/en-US.js new file mode 100644 index 00000000..04cea5c9 --- /dev/null +++ b/packages/fes-plugin-layout/src/runtime/locales/layout/en-US.js @@ -0,0 +1,6 @@ +export default { + pluginLayout: { + closeOtherPage: 'Close Other Page', + reloadPage: 'Reload Page', + }, +}; diff --git a/packages/fes-plugin-layout/src/runtime/locales/layout/zh-CN.js b/packages/fes-plugin-layout/src/runtime/locales/layout/zh-CN.js new file mode 100644 index 00000000..d21ae72e --- /dev/null +++ b/packages/fes-plugin-layout/src/runtime/locales/layout/zh-CN.js @@ -0,0 +1,6 @@ +export default { + pluginLayout: { + closeOtherPage: '关闭其他页签', + reloadPage: '刷新当前页签', + }, +}; diff --git a/packages/fes-plugin-layout/src/runtime/views/MultiTabProvider.vue b/packages/fes-plugin-layout/src/runtime/views/MultiTabProvider.vue index 96b9e683..cd78be98 100644 --- a/packages/fes-plugin-layout/src/runtime/views/MultiTabProvider.vue +++ b/packages/fes-plugin-layout/src/runtime/views/MultiTabProvider.vue @@ -7,7 +7,7 @@ type="card" class="layout-content-tabs" @close="handleCloseTab" - @update:modelValue="switchPage" + @update:model-value="switchPage" >