gc_i18n 1.2.13 → 1.3.1

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/lang/index.js CHANGED
@@ -22,15 +22,15 @@ export const languages = [
22
22
  ];
23
23
  export default {
24
24
  install(app, router) {
25
+ console.log("i18n", import.meta.env);
25
26
  const { i18n } = new gc_i18n({
26
27
  appCode: "TEST",
27
28
  router,
28
- token: localStorage.getItem("token"),
29
- local: localStorage.getItem("I18N_LANGUAGE"),
29
+ orgCode: import.meta.env.MODE === "unit" ? "DD" : "GREENCLOUD",
30
+ // locale: localStorage.getItem("I18N_LANGUAGE"),
30
31
  // loginRouteName: "Login",
31
32
  dev: true,
32
33
  login: false,
33
- orgCode: "GREENCLOUD",
34
34
  messages: {
35
35
  "zh-CN": { ...pro_zh_CN, ...iview_zh_CN },
36
36
  "zh-TW": { ...pro_zh_TW, ...iview_zh_TW },
package/lang/index.json CHANGED
@@ -33,5 +33,65 @@
33
33
  "zh-cn": "清理",
34
34
  "zh-tw": "清理",
35
35
  "en-us": "清理"
36
+ },
37
+ "koca2": {
38
+ "zh-cn": "登录",
39
+ "zh-tw": "登錄",
40
+ "en-us": "登录"
41
+ },
42
+ "klpb2": {
43
+ "zh-cn": "登出",
44
+ "zh-tw": "登出",
45
+ "en-us": "登出"
46
+ },
47
+ "sah0y05": {
48
+ "zh-cn": "当前单位:",
49
+ "zh-tw": "當前單位:",
50
+ "en-us": "当前单位:"
51
+ },
52
+ "ely02": {
53
+ "zh-cn": "单位",
54
+ "zh-tw": "單位",
55
+ "en-us": "单位"
56
+ },
57
+ "imbi2": {
58
+ "zh-cn": "模板",
59
+ "zh-tw": "模板",
60
+ "en-us": "模板"
61
+ },
62
+ "sf96jw5": {
63
+ "zh-cn": "当前环境:",
64
+ "zh-tw": "當前環境:",
65
+ "en-us": "当前环境:"
66
+ },
67
+ "wt0nrm7": {
68
+ "zh-cn": "单位 : dd",
69
+ "zh-tw": "單位 : dd",
70
+ "en-us": "单位 : dd"
71
+ },
72
+ "tbqqg98": {
73
+ "zh-cn": "单位级 : dd",
74
+ "zh-tw": "單位級 : dd",
75
+ "en-us": "单位级 : dd"
76
+ },
77
+ "vo9pqm7": {
78
+ "zh-cn": "当前环境 --",
79
+ "zh-tw": "當前環境 --",
80
+ "en-us": "当前环境 --"
81
+ },
82
+ "ledywde": {
83
+ "zh-cn": "单位级 : 单位代码: dd",
84
+ "zh-tw": "單位級 : 單位代碼: dd",
85
+ "en-us": "单位级 : 单位代码: dd"
86
+ },
87
+ "g44k6lc": {
88
+ "zh-cn": "单位级 单位代码: dd",
89
+ "zh-tw": "單位級 單位代碼: dd",
90
+ "en-us": "单位级 单位代码: dd"
91
+ },
92
+ "g1wx53": {
93
+ "zh-cn": "模板级",
94
+ "zh-tw": "模板級",
95
+ "en-us": "模板级"
36
96
  }
37
97
  }
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "gc_i18n",
3
- "version": "1.2.13",
3
+ "version": "1.3.1",
4
4
  "type": "module",
5
5
  "main": "./lib/gc_i18n.umd.cjs",
6
6
  "module": "./lib/gc_i18n.js",
7
7
  "scripts": {
8
8
  "dev": "vite",
9
+ "dev:unit": "vite --mode unit --port 8080",
10
+ "dev:template": "vite --mode template --port 8081",
9
11
  "build": "vite build",
10
12
  "preview": "vite preview",
11
13
  "cnpm": "cnpm sync gc_i18n"
12
14
  },
13
15
  "dependencies": {
14
16
  "axios": "^1.7.9",
15
- "jose": "^6.0.11",
16
17
  "jsrsasign": "^11.1.0",
17
18
  "keyboardjs": "^2.7.0",
18
19
  "lodash-es": "^4.17.21",
@@ -33,5 +34,6 @@
33
34
  "vite": "^6.1.0",
34
35
  "vite-gc-i18n-plugin": "^1.0.4",
35
36
  "vite-plugin-libcss": "^1.1.1"
36
- }
37
+ },
38
+ "packageManager": "pnpm@10.15.1+sha512.34e538c329b5553014ca8e8f4535997f96180a1d0f614339357449935350d924e22f8614682191264ec33d1462ac21561aff97f6bb18065351c162c7e8f6de67"
37
39
  }
@@ -98,6 +98,7 @@ export default {
98
98
  },
99
99
  props: {
100
100
  appCode: String,
101
+ router: Object,
101
102
  setLanguage: Function,
102
103
  token: String,
103
104
  baseUrl: String, // 基础URL
@@ -185,15 +186,8 @@ export default {
185
186
  this.initialData = _.cloneDeep(this.data.datas);
186
187
 
187
188
  this.mySaveData = [];
188
- Modal.confirm({
189
- title: "是否刷新页面",
190
- onOk: () => {
191
- window.location.reload();
192
- },
193
- onCancel: () => {
194
- close && this.closeModal();
195
- }
196
- });
189
+ // window.location.reload();
190
+ this.router.go(0);
197
191
  } else {
198
192
  Message.error({ content: res.data.msg || "保存失败" });
199
193
  }
@@ -263,6 +257,7 @@ export default {
263
257
  },
264
258
  changeTab(name) {
265
259
  this.type = name;
260
+ this.mySaveData = [];
266
261
  if (name === "data") {
267
262
  this.search();
268
263
  } else if (name === "pageData") {
@@ -455,6 +450,9 @@ export default {
455
450
  }
456
451
  .gc_i18n_tabs {
457
452
  padding-top: 5px;
453
+ :deep(.ivu-tabs-tab) {
454
+ width: 111px;
455
+ }
458
456
  :deep(.ivu-tabs-content) {
459
457
  width: 100%;
460
458
  }
package/packages/index.js CHANGED
@@ -37,13 +37,15 @@ export default class I18n {
37
37
  orgCode,
38
38
  loginRouteName,
39
39
  login,
40
- keyboard
40
+ keyboard,
41
+ locale
41
42
  } = options;
42
- this.token = token || generateJWT(orgCode);
43
+ this.token = token || generateJWT(orgCode) || store2.get("I18N_TOKEN");
43
44
  this.loadI18n = true;
44
45
  this.appCode = appCode;
45
46
  this.router = router;
46
- this.locale = store2.get("I18N_LANGUAGE") || navigator.language || "zh-CN";
47
+ this.locale =
48
+ locale || store2.get("I18N_LANGUAGE") || navigator.language || "zh-CN";
47
49
  this.name = "";
48
50
  this.messages = messages || {};
49
51
  this.translationKeys = [];
@@ -74,7 +76,6 @@ export default class I18n {
74
76
  // 监听浏览器语言变化
75
77
  this.setupLanguageChangeListener();
76
78
  }
77
-
78
79
  // 监听浏览器语言变化
79
80
  setupLanguageChangeListener() {
80
81
  if ("onlanguagechange" in window) {
@@ -111,8 +112,8 @@ export default class I18n {
111
112
  );
112
113
  });
113
114
 
114
- if (loginRoute) {
115
- let loginComponent = loginRoute.components.default;
115
+ if (loginRoute && loginRoute.components) {
116
+ let loginComponent = loginRoute.components?.default;
116
117
  if (
117
118
  typeof loginComponent === "function" &&
118
119
  loginComponent.toString().includes("import(")
@@ -132,29 +133,29 @@ export default class I18n {
132
133
  this.loginTranslationKeys = loginRouteKeys;
133
134
  }
134
135
  if (to.matched.length > 0) {
135
- // 兼容保留:静态扫描路由组件,获取初步 keys(可能不包含自动注册的子组件)
136
- const allTranslationKeys = [];
137
- for (const match of to.matched) {
138
- let component = match.components.default;
139
- if (
140
- typeof component === "function" &&
141
- component.toString().includes("import(")
142
- ) {
143
- try {
136
+ try {
137
+ // 兼容保留:静态扫描路由组件,获取初步 keys(可能不包含自动注册的子组件)
138
+ const allTranslationKeys = [];
139
+ for (const match of to.matched) {
140
+ let component = match.components?.default;
141
+ if (
142
+ typeof component === "function" &&
143
+ component.toString().includes("import(")
144
+ ) {
144
145
  component = await component();
145
146
  component = component.default;
146
- } catch (error) {
147
- console.error("加载异步组件时出错:", error);
148
- next();
149
- return;
147
+ }
148
+ if (component) {
149
+ const keys = extractTranslationKeys(component);
150
+ allTranslationKeys.push(...keys);
150
151
  }
151
152
  }
152
- if (component) {
153
- const keys = extractTranslationKeys(component);
154
- allTranslationKeys.push(...keys);
155
- }
153
+ this.translationKeys = allTranslationKeys;
154
+ } catch (error) {
155
+ console.error("加载异步组件时出错:", error);
156
+ next();
157
+ return;
156
158
  }
157
- this.translationKeys = allTranslationKeys;
158
159
  }
159
160
  next();
160
161
  });
@@ -219,11 +220,21 @@ export default class I18n {
219
220
  return originalT(key, comment);
220
221
  }
221
222
  };
223
+ globalThis.$i18nLogin = async (orgCode) => {
224
+ this.setToken(generateJWT(orgCode));
225
+ this.clearI18n();
226
+ await this.setLanguage(this.locale);
227
+ location.reload();
228
+ };
229
+ globalThis.$i18nLogout = (orgCode) => {
230
+ this.clearI18n();
231
+ location.reload();
232
+ };
222
233
 
223
234
  globalThis.$deepScan = function (val) {
224
235
  return val;
225
236
  };
226
- globalThis.$clearI18n = () => {
237
+ globalThis.$clearI18n = this.clearI18n = () => {
227
238
  const languageStore = store2.namespace(`I18N_${_.toUpper(this.appCode)}`);
228
239
  languageStore.clearAll();
229
240
  };
@@ -236,6 +247,7 @@ export default class I18n {
236
247
  }
237
248
  setToken(token) {
238
249
  this.token = token;
250
+ store2.set("I18N_TOKEN", token);
239
251
  }
240
252
  async getLanguages(isRemote = false) {
241
253
  const langs = store2.get("I18N_LANGUAGES");
@@ -260,7 +272,8 @@ export default class I18n {
260
272
  baseUrl: this.baseUrl,
261
273
  appCode: this.appCode,
262
274
  language: language ? language : this.locale,
263
- token: this.token
275
+ token: this.token,
276
+ routerName: this.name
264
277
  });
265
278
  if (res) {
266
279
  const remoteMessages = convertArrayToObject(res);
@@ -291,6 +304,7 @@ export default class I18n {
291
304
  // 创建 config 组件的实例
292
305
  return createApp(configVue, {
293
306
  appCode: this.appCode,
307
+ router: this.router,
294
308
  token: this.token,
295
309
  setLanguage: this.setLanguage.bind(this, this.locale),
296
310
  name: name || this.name,
@@ -77,7 +77,8 @@ export const getTranslate = async ({
77
77
  baseUrl,
78
78
  appCode,
79
79
  language = "zh-CN",
80
- token
80
+ token,
81
+ routerName
81
82
  }) => {
82
83
  return new Promise(async (resolve, reject) => {
83
84
  // const appCodeStore = i18nStore.get(appCode);
@@ -107,7 +108,11 @@ export const getTranslate = async ({
107
108
  // 合并增量数据
108
109
  const langData = _.get(lastData, "translatesDTOs");
109
110
  if (!_.isEmpty(res.translatesDTOs)) {
110
- const data = mergeArraysByKey(langData, res.translatesDTOs);
111
+ const data = mergeArraysByKey(
112
+ langData,
113
+ res.translatesDTOs,
114
+ routerName
115
+ );
111
116
  const saveData = {
112
117
  lastPullDate: res.lastPullDate,
113
118
  translatesDTOs: data
@@ -7,8 +7,17 @@ export const convertArrayToObject = (arr) => {
7
7
  return result;
8
8
  };
9
9
 
10
- export const mergeArraysByKey = (arr1, arr2) => {
10
+ export const mergeArraysByKey = (arr1, arr2, routerName) => {
11
11
  arr2.forEach((obj2) => {
12
+ console.log("obj2.key ", obj2.key);
13
+ const type = obj2.key.split(".");
14
+ if (type[0] === "common") {
15
+ const findHome = _.find(arr1, { key: `${routerName}.${type[1]}` });
16
+ // 如果找到 删除
17
+ if (findHome) {
18
+ _.remove(arr1, { key: `${routerName}.${type[1]}` });
19
+ }
20
+ }
12
21
  const foundObj = _.find(arr1, { key: obj2.key });
13
22
  if (foundObj) {
14
23
  _.merge(foundObj, obj2);
package/src/view/Home.vue CHANGED
@@ -6,15 +6,26 @@ const change = async (lang) => {
6
6
  const clear = () => {
7
7
  $clearI18n();
8
8
  };
9
+ const login = () => {
10
+ $i18nLogin("abc");
11
+ };
12
+ const logout = () => {
13
+ $i18nLogout();
14
+ };
15
+ const type = import.meta.env.MODE === "unit" ? "单位级 单位代码: dd" : "模板级";
9
16
  </script>
10
17
 
11
18
  <template>
12
- <h1>首页</h1>
19
+ <h1>当前环境 -- {{ type }}</h1>
20
+
21
+ <div>首页</div>
13
22
  <RouterLink to="/test">测试</RouterLink>
14
23
  <h1>{{ $t("dsgljksdg") }}</h1>
15
24
  <button @click="change('en-US')">en</button>
16
25
  <button @click="change('zh-CN')">zh</button>
17
26
  <div>
18
27
  <button @click="clear">清理</button>
28
+ <button @click="login">登录</button>
29
+ <button @click="logout">登出</button>
19
30
  </div>
20
31
  </template>
package/vite.config.js CHANGED
@@ -26,7 +26,10 @@ export default defineConfig({
26
26
  "view-ui-plus",
27
27
  "store2",
28
28
  "jsrsasign",
29
+ "pro_iview_v3",
29
30
  "keyboardjs",
31
+ "vue-i18n",
32
+ "vue-router",
30
33
  "view-ui-plus/dist/styles/viewuiplus.css"
31
34
  ],
32
35
  output: {
package/lib/gc_i18n.css DELETED
@@ -1 +0,0 @@
1
- .gc_i18n_spin[data-v-ef963ad8]{min-height:300px;display:flex;justify-content:center;padding-top:50px}.gc_i18n_tabs[data-v-ef963ad8]{padding-top:5px}.gc_i18n_tabs[data-v-ef963ad8] .ivu-tabs-content{width:100%}.gc_i18n_tabs[data-v-ef963ad8] .ivu-tabs-bar{margin-bottom:0!important}.gc_i18n_tabs .ivu-tabs-content[data-v-ef963ad8]{position:relative;top:-1px}.gc_i18n_tabs .extra[data-v-ef963ad8]{position:relative;top:-3px;display:flex;align-items:center}.gc_i18n_page[data-v-ef963ad8]{display:flex;justify-content:space-between;align-items:center;margin-top:10px}