@gct-paas/core 0.1.6-dev.23 → 0.1.6-dev.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.min.js +2 -2
- package/dist/{redirect-index-C5MqjUMk.js → redirect-index-B6QaafAd.js} +1 -1
- package/es/_virtual/_rolldown/runtime.mjs +13 -0
- package/es/locale/auto-register.d.ts +2 -0
- package/es/locale/auto-register.mjs +13 -0
- package/es/locale/index.d.ts +26 -0
- package/es/locale/index.mjs +65 -1
- package/es/locale/sys/model.mjs +9 -0
- package/es/locale/sys.mjs +9 -0
- package/es/setup-app.mjs +2 -0
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! @gct-paas/core v0.1.6-dev.
|
|
1
|
+
/*! @gct-paas/core v0.1.6-dev.24 */
|
|
2
2
|
import{createElementBlock as e,defineComponent as r,openBlock as t,unref as a}from"vue";import{useRouter as p}from"vue-router";var o=/* @__PURE__ */r({__name:"redirect-index",setup(r){const{currentRoute:o,replace:i}=p(),{params:s,query:u}=a(o),{path:m,_redirect_type:n="path"}=s;Reflect.deleteProperty(s,"_redirect_type"),Reflect.deleteProperty(s,"path");const c=Array.isArray(m)?m.join("/"):m;return i("name"===n?{name:c,query:u,params:JSON.parse(s._origin_params??"{}")}:{path:c.startsWith("/")?c:"/"+c,query:u}),(r,a)=>(t(),e("div"))}});export{o as default};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __exportAll };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { model_exports } from "./sys/model.mjs";
|
|
2
|
+
import { sys_exports } from "./sys.mjs";
|
|
3
|
+
//#region src/locale/auto-register.ts
|
|
4
|
+
var localeModules = /* @__PURE__ */ Object.assign({
|
|
5
|
+
"./sys/model.ts": model_exports,
|
|
6
|
+
"./sys.ts": sys_exports
|
|
7
|
+
});
|
|
8
|
+
/** 注册 core 包的 locale 多语言资源 */
|
|
9
|
+
function registerCoreLocale() {
|
|
10
|
+
_gct.i18nUtil.autoRegisterLocale(localeModules);
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { registerCoreLocale };
|
package/es/locale/index.d.ts
CHANGED
|
@@ -42,6 +42,32 @@ export declare class LocaleUtil {
|
|
|
42
42
|
env: EnvironmentType;
|
|
43
43
|
branch?: string;
|
|
44
44
|
}): string;
|
|
45
|
+
/**
|
|
46
|
+
* 自动注册 import.meta.glob 扫描到的 locale 模块。
|
|
47
|
+
* 根据文件路径生成 key(去除 locale 目录和 .ts 后缀,/ 替换为 .),
|
|
48
|
+
* 构建嵌套对象后合并到 i18n 实例。
|
|
49
|
+
*
|
|
50
|
+
* @param globResult - import.meta.glob 返回的模块映射
|
|
51
|
+
* @param locale - 目标语言标识,默认 'zh-CN'
|
|
52
|
+
*/
|
|
53
|
+
autoRegisterLocale(globResult: Record<string, {
|
|
54
|
+
default: Record<string, unknown>;
|
|
55
|
+
}>, locale?: string): void;
|
|
56
|
+
/** 路径转 key: './sys/pageDesigner.ts' → 'sys.pageDesigner',排除 index */
|
|
57
|
+
private pathToLocaleKey;
|
|
58
|
+
/** 将点号路径构建为嵌套对象: 'sys.pageDesigner' + value → { sys: { pageDesigner: value } } */
|
|
59
|
+
private buildNestedObject;
|
|
60
|
+
/**
|
|
61
|
+
* 将扁平 key 的 messages 对象转为多层嵌套对象
|
|
62
|
+
*
|
|
63
|
+
* @param messages 扁平 key 的 messages,如 { "common.button.submit": "提交" }
|
|
64
|
+
* @returns 嵌套对象,如 { common: { button: { submit: "提交" } } }
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* flattenToNested({ "a.b.c": "v1", "a.b.d": "v2", "a.e": "v3" })
|
|
68
|
+
* // => { a: { b: { c: "v1", d: "v2" }, e: "v3" } }
|
|
69
|
+
*/
|
|
70
|
+
flattenToNested(messages: Record<string, string>): Record<string, unknown>;
|
|
45
71
|
/**
|
|
46
72
|
* 设置 HTML 根元素的 lang 属性,供浏览器、辅助技术识别当前语言
|
|
47
73
|
*
|
package/es/locale/index.mjs
CHANGED
|
@@ -106,7 +106,8 @@ var LocaleUtil = class {
|
|
|
106
106
|
acc[key] = value.join(":");
|
|
107
107
|
return acc;
|
|
108
108
|
}, {});
|
|
109
|
-
this.
|
|
109
|
+
const nestedMessages = this.flattenToNested(messages);
|
|
110
|
+
this.i18n.global.mergeLocaleMessage(locale, nestedMessages);
|
|
110
111
|
}
|
|
111
112
|
getMessageUrl(payload) {
|
|
112
113
|
if ("app" in payload) {
|
|
@@ -116,6 +117,69 @@ var LocaleUtil = class {
|
|
|
116
117
|
return `/minio/locale-js/${payload.locale}__platform__.json`;
|
|
117
118
|
}
|
|
118
119
|
/**
|
|
120
|
+
* 自动注册 import.meta.glob 扫描到的 locale 模块。
|
|
121
|
+
* 根据文件路径生成 key(去除 locale 目录和 .ts 后缀,/ 替换为 .),
|
|
122
|
+
* 构建嵌套对象后合并到 i18n 实例。
|
|
123
|
+
*
|
|
124
|
+
* @param globResult - import.meta.glob 返回的模块映射
|
|
125
|
+
* @param locale - 目标语言标识,默认 'zh-CN'
|
|
126
|
+
*/
|
|
127
|
+
autoRegisterLocale(globResult, locale = "zh-CN") {
|
|
128
|
+
for (const path in globResult) {
|
|
129
|
+
const mod = globResult[path];
|
|
130
|
+
if (!mod?.default) continue;
|
|
131
|
+
const key = this.pathToLocaleKey(path);
|
|
132
|
+
if (!key) continue;
|
|
133
|
+
const messages = this.buildNestedObject(key, mod.default);
|
|
134
|
+
this.i18n.global.mergeLocaleMessage(locale, messages);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** 路径转 key: './sys/pageDesigner.ts' → 'sys.pageDesigner',排除 index */
|
|
138
|
+
pathToLocaleKey(path) {
|
|
139
|
+
const cleaned = path.replace(/^\.\//, "").replace(/\.ts$/, "");
|
|
140
|
+
if (cleaned === "index" || cleaned.endsWith("/index")) return null;
|
|
141
|
+
return cleaned.replace(/\//g, ".");
|
|
142
|
+
}
|
|
143
|
+
/** 将点号路径构建为嵌套对象: 'sys.pageDesigner' + value → { sys: { pageDesigner: value } } */
|
|
144
|
+
buildNestedObject(dotPath, value) {
|
|
145
|
+
const parts = dotPath.split(".");
|
|
146
|
+
const result = {};
|
|
147
|
+
let current = result;
|
|
148
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
149
|
+
current[parts[i]] = {};
|
|
150
|
+
current = current[parts[i]];
|
|
151
|
+
}
|
|
152
|
+
current[parts[parts.length - 1]] = value;
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* 将扁平 key 的 messages 对象转为多层嵌套对象
|
|
157
|
+
*
|
|
158
|
+
* @param messages 扁平 key 的 messages,如 { "common.button.submit": "提交" }
|
|
159
|
+
* @returns 嵌套对象,如 { common: { button: { submit: "提交" } } }
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* flattenToNested({ "a.b.c": "v1", "a.b.d": "v2", "a.e": "v3" })
|
|
163
|
+
* // => { a: { b: { c: "v1", d: "v2" }, e: "v3" } }
|
|
164
|
+
*/
|
|
165
|
+
flattenToNested(messages) {
|
|
166
|
+
const result = {};
|
|
167
|
+
for (const key in messages) {
|
|
168
|
+
if (/\p{Unified_Ideograph}/u.test(key)) {
|
|
169
|
+
result[key] = messages[key];
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const parts = key.split(".");
|
|
173
|
+
let current = result;
|
|
174
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
175
|
+
if (!(parts[i] in current) || typeof current[parts[i]] !== "object") current[parts[i]] = {};
|
|
176
|
+
current = current[parts[i]];
|
|
177
|
+
}
|
|
178
|
+
current[parts[parts.length - 1]] = messages[key];
|
|
179
|
+
}
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
119
183
|
* 设置 HTML 根元素的 lang 属性,供浏览器、辅助技术识别当前语言
|
|
120
184
|
*
|
|
121
185
|
* @param locale 语言标识,如 zh-CN、en
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
//#region src/locale/sys/model.ts
|
|
3
|
+
var model_exports = /* @__PURE__ */ __exportAll({ default: () => model_default });
|
|
4
|
+
var model_default = {
|
|
5
|
+
modelNameError: "不能包含表情符号及以下特殊字符:?*:,[]#",
|
|
6
|
+
notModelNameError: "不能包含表情符号及以下特殊字符:\\/?*:,[]#"
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { model_exports };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
//#region src/locale/sys.ts
|
|
3
|
+
var sys_exports = /* @__PURE__ */ __exportAll({ default: () => sys_default });
|
|
4
|
+
var sys_default = {
|
|
5
|
+
notNull: "该值不能为空",
|
|
6
|
+
regError: "校验格式不正确"
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { sys_exports };
|
package/es/setup-app.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { usePlatformConfigStore } from "./modules/platform-config/store.mjs";
|
|
|
5
5
|
import "./modules/platform-config/index.mjs";
|
|
6
6
|
import { useUserStore } from "./modules/user-stores/store/user.store.mjs";
|
|
7
7
|
import "./modules/user-stores/index.mjs";
|
|
8
|
+
import { registerCoreLocale } from "./locale/auto-register.mjs";
|
|
8
9
|
import { HttpUtil } from "@gct-paas/api";
|
|
9
10
|
//#region src/setup-app.ts
|
|
10
11
|
/**
|
|
@@ -16,6 +17,7 @@ import { HttpUtil } from "@gct-paas/api";
|
|
|
16
17
|
async function setupApp(_app) {
|
|
17
18
|
HttpUtil.use(interceptors);
|
|
18
19
|
await _gct.init();
|
|
20
|
+
registerCoreLocale();
|
|
19
21
|
await usePlatformConfigStore().init();
|
|
20
22
|
const token = getToken();
|
|
21
23
|
if (token) try {
|