gc_i18n 1.3.2 → 1.3.4

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
@@ -1,10 +1,3 @@
1
- import pro_zh_CN from "pro_iview_v3/lib/locales/zh-CN";
2
- import iview_zh_CN from "view-ui-plus/dist/locale/zh-CN";
3
- import pro_zh_TW from "pro_iview_v3/lib/locales/zh-TW";
4
- import iview_zh_TW from "view-ui-plus/dist/locale/zh-TW";
5
- import pro_en_US from "pro_iview_v3/lib/locales/en-US";
6
- import iview_en_US from "view-ui-plus/dist/locale/en-US";
7
-
8
1
  import gc_i18n from "../packages/index.js";
9
2
  export const languages = [
10
3
  {
@@ -23,20 +16,16 @@ export const languages = [
23
16
  export default {
24
17
  install(app, router) {
25
18
  console.log("i18n", import.meta.env);
26
- const { i18n } = new gc_i18n({
19
+ const i18n = new gc_i18n({
27
20
  appCode: "TEST",
28
21
  router,
29
22
  orgCode: import.meta.env.MODE === "unit" ? "DD" : "GREENCLOUD",
30
23
  // locale: localStorage.getItem("I18N_LANGUAGE"),
31
24
  // loginRouteName: "Login",
32
25
  dev: true,
33
- login: false,
34
- messages: {
35
- "zh-CN": { ...pro_zh_CN, ...iview_zh_CN },
36
- "zh-TW": { ...pro_zh_TW, ...iview_zh_TW },
37
- "en-US": { ...pro_en_US, ...iview_en_US }
38
- }
26
+ login: false
39
27
  });
40
- app.use(i18n);
28
+ // 调用实例的 install 方法来注册全局组件
29
+ i18n.install(app);
41
30
  }
42
31
  };
package/lang/index.json CHANGED
@@ -1,97 +1,82 @@
1
1
  {
2
2
  "qylb2": {
3
3
  "zh-cn": "首页",
4
- "zh-tw": "首頁",
5
- "en-us": "首页"
4
+ "zh-tw": "首頁"
6
5
  },
7
6
  "jcve2": {
8
7
  "zh-cn": "测试",
9
- "zh-tw": "測試",
10
- "en-us": "测试"
8
+ "zh-tw": "測試"
11
9
  },
12
10
  "juzboq4": {
13
11
  "zh-cn": "页面独有",
14
- "zh-tw": "頁面獨有",
15
- "en-us": "页面独有"
12
+ "zh-tw": "頁面獨有"
16
13
  },
17
14
  "haxjfz4": {
18
15
  "zh-cn": "蓝色灯光",
19
- "zh-tw": "藍色燈光",
20
- "en-us": "蓝色灯光"
16
+ "zh-tw": "藍色燈光"
21
17
  },
22
18
  "875i746": {
23
19
  "zh-cn": "十多个十多个",
24
- "zh-tw": "十多個十多個",
25
- "en-us": "十多个十多个"
20
+ "zh-tw": "十多個十多個"
26
21
  },
27
22
  "jaid2": {
28
23
  "zh-cn": "清楚",
29
- "zh-tw": "清楚",
30
- "en-us": "清楚"
24
+ "zh-tw": "清楚"
31
25
  },
32
26
  "jcm92": {
33
27
  "zh-cn": "清理",
34
- "zh-tw": "清理",
35
- "en-us": "清理"
28
+ "zh-tw": "清理"
36
29
  },
37
30
  "koca2": {
38
31
  "zh-cn": "登录",
39
- "zh-tw": "登錄",
40
- "en-us": "登录"
32
+ "zh-tw": "登錄"
41
33
  },
42
34
  "klpb2": {
43
35
  "zh-cn": "登出",
44
- "zh-tw": "登出",
45
- "en-us": "登出"
36
+ "zh-tw": "登出"
46
37
  },
47
38
  "sah0y05": {
48
39
  "zh-cn": "当前单位:",
49
- "zh-tw": "當前單位:",
50
- "en-us": "当前单位:"
40
+ "zh-tw": "當前單位:"
51
41
  },
52
42
  "ely02": {
53
43
  "zh-cn": "单位",
54
- "zh-tw": "單位",
55
- "en-us": "单位"
44
+ "zh-tw": "單位"
56
45
  },
57
46
  "imbi2": {
58
47
  "zh-cn": "模板",
59
- "zh-tw": "模板",
60
- "en-us": "模板"
48
+ "zh-tw": "模板"
61
49
  },
62
50
  "sf96jw5": {
63
51
  "zh-cn": "当前环境:",
64
- "zh-tw": "當前環境:",
65
- "en-us": "当前环境:"
52
+ "zh-tw": "當前環境:"
66
53
  },
67
54
  "wt0nrm7": {
68
55
  "zh-cn": "单位 : dd",
69
- "zh-tw": "單位 : dd",
70
- "en-us": "单位 : dd"
56
+ "zh-tw": "單位 : dd"
71
57
  },
72
58
  "tbqqg98": {
73
59
  "zh-cn": "单位级 : dd",
74
- "zh-tw": "單位級 : dd",
75
- "en-us": "单位级 : dd"
60
+ "zh-tw": "單位級 : dd"
76
61
  },
77
62
  "vo9pqm7": {
78
63
  "zh-cn": "当前环境 --",
79
- "zh-tw": "當前環境 --",
80
- "en-us": "当前环境 --"
64
+ "zh-tw": "當前環境 --"
81
65
  },
82
66
  "ledywde": {
83
67
  "zh-cn": "单位级 : 单位代码: dd",
84
- "zh-tw": "單位級 : 單位代碼: dd",
85
- "en-us": "单位级 : 单位代码: dd"
68
+ "zh-tw": "單位級 : 單位代碼: dd"
86
69
  },
87
70
  "g44k6lc": {
88
71
  "zh-cn": "单位级 单位代码: dd",
89
- "zh-tw": "單位級 單位代碼: dd",
90
- "en-us": "单位级 单位代码: dd"
72
+ "zh-tw": "單位級 單位代碼: dd"
91
73
  },
92
74
  "g1wx53": {
93
75
  "zh-cn": "模板级",
94
- "zh-tw": "模板級",
95
- "en-us": "模板级"
76
+ "zh-tw": "模板級"
77
+ },
78
+ "axba5d6": {
79
+ "zh-cn": "全局地球翻译",
80
+ "zh-tw": "全局地球翻譯"
96
81
  }
97
82
  }
package/lib/gc_i18n.css CHANGED
@@ -1 +1 @@
1
- .gc_i18n_spin[data-v-1f438196]{min-height:300px;display:flex;justify-content:center;padding-top:50px}.gc_i18n_tabs[data-v-1f438196]{padding-top:5px}.gc_i18n_tabs[data-v-1f438196] .ivu-tabs-tab{width:111px}.gc_i18n_tabs[data-v-1f438196] .ivu-tabs-content{width:100%}.gc_i18n_tabs[data-v-1f438196] .ivu-tabs-bar{margin-bottom:0!important}.gc_i18n_tabs .ivu-tabs-content[data-v-1f438196]{position:relative;top:-1px}.gc_i18n_tabs .extra[data-v-1f438196]{position:relative;top:-3px;display:flex;align-items:center}.gc_i18n_page[data-v-1f438196]{display:flex;justify-content:space-between;align-items:center;margin-top:10px}
1
+ .gc_i18n_spin[data-v-1f438196]{min-height:300px;display:flex;justify-content:center;padding-top:50px}.gc_i18n_tabs[data-v-1f438196]{padding-top:5px}.gc_i18n_tabs[data-v-1f438196] .ivu-tabs-tab{width:111px}.gc_i18n_tabs[data-v-1f438196] .ivu-tabs-content{width:100%}.gc_i18n_tabs[data-v-1f438196] .ivu-tabs-bar{margin-bottom:0!important}.gc_i18n_tabs .ivu-tabs-content[data-v-1f438196]{position:relative;top:-1px}.gc_i18n_tabs .extra[data-v-1f438196]{position:relative;top:-3px;display:flex;align-items:center}.gc_i18n_page[data-v-1f438196]{display:flex;justify-content:space-between;align-items:center;margin-top:10px}.earth{display:flex;justify-content:center;align-items:center}.earth .icon{cursor:pointer}.earth .input{margin-right:5px}
package/lib/gc_i18n.es.js CHANGED
@@ -1,25 +1,25 @@
1
1
  import './gc_i18n.css';
2
- import J from "keyboardjs";
3
- import K, { Message as w } from "view-ui-plus";
2
+ import F from "keyboardjs";
3
+ import R, { Message as T } from "view-ui-plus";
4
4
  import "view-ui-plus/dist/styles/viewuiplus.css";
5
- import { createVNode as y, resolveComponent as m, resolveDirective as F, createBlock as S, openBlock as f, withCtx as p, createElementBlock as O, createCommentVNode as U, createElementVNode as b, withDirectives as q, createTextVNode as L, Fragment as Q, renderList as X, toDisplayString as E, nextTick as Y, createApp as Z } from "vue";
6
- import { createI18n as $ } from "vue-i18n";
5
+ import { createVNode as y, resolveComponent as d, resolveDirective as q, createBlock as S, openBlock as f, withCtx as p, createElementBlock as I, createCommentVNode as K, createElementVNode as b, withDirectives as Q, createTextVNode as L, Fragment as X, renderList as Y, toDisplayString as U, nextTick as Z, createApp as $ } from "vue";
6
+ import { createI18n as ee } from "vue-i18n";
7
7
  import l from "lodash-es";
8
- import N from "axios";
8
+ import D from "axios";
9
9
  import _ from "store2";
10
- import { jws as ee } from "jsrsasign";
11
- const te = (t) => {
10
+ import { jws as te } from "jsrsasign";
11
+ const ae = (t) => {
12
12
  const e = {};
13
13
  for (const a of t)
14
14
  e[a.key] = a.value;
15
15
  return e;
16
- }, ae = (t, e, a) => (e.forEach((s) => {
16
+ }, se = (t, e, a) => (e.forEach((s) => {
17
17
  console.log("obj2.key ", s.key);
18
18
  const n = s.key.split(".");
19
19
  n[0] === "common" && l.find(t, { key: `${a}.${n[1]}` }) && l.remove(t, { key: `${a}.${n[1]}` });
20
20
  const o = l.find(t, { key: s.key });
21
21
  o ? l.merge(o, s) : t.push(s);
22
- }), t), A = async ({ baseUrl: t, token: e }) => N.get(t + "/i18n-web/sysoption/getsupportedlangs", {
22
+ }), t), A = async ({ baseUrl: t, token: e }) => D.get(t + "/i18n-web/sysoption/getsupportedlangs", {
23
23
  headers: {
24
24
  Authorization: e
25
25
  }
@@ -31,7 +31,7 @@ const te = (t) => {
31
31
  baseUrl: n,
32
32
  token: o
33
33
  }) => new Promise(async (r, h) => {
34
- const g = n + "/i18n-web/kv_translate/kv_translates", i = s ? g + "?lastPullDate=" + s : g, c = await N({
34
+ const g = n + "/i18n-web/kv_translate/kv_translates", i = s ? g + "?lastPullDate=" + s : g, c = await D({
35
35
  url: i,
36
36
  method: "GET",
37
37
  headers: {
@@ -42,21 +42,21 @@ const te = (t) => {
42
42
  }
43
43
  });
44
44
  c.data && c.data.result == 0 ? r(c.data.retVal) : r(c);
45
- }), se = async ({ data: t, token: e, baseUrl: a }) => N({
45
+ }), ne = async ({ data: t, token: e, baseUrl: a }) => D({
46
46
  url: a + "/i18n-web/kv_translate/userDicts",
47
47
  method: "POST",
48
48
  headers: {
49
49
  Authorization: e
50
50
  },
51
51
  data: t
52
- }), ne = async ({ data: t, token: e, baseUrl: a }) => N({
52
+ }), oe = async ({ data: t, token: e, baseUrl: a }) => D({
53
53
  url: a + "/i18n-web/kv_translate/batch",
54
54
  method: "POST",
55
55
  data: t,
56
56
  headers: {
57
57
  Authorization: e
58
58
  }
59
- }), oe = async ({
59
+ }), ie = async ({
60
60
  baseUrl: t,
61
61
  appCode: e,
62
62
  language: a = "zh-CN",
@@ -82,19 +82,19 @@ const te = (t) => {
82
82
  if (l.isEmpty(u.translatesDTOs))
83
83
  o(k);
84
84
  else {
85
- const v = ae(
85
+ const w = se(
86
86
  k,
87
87
  u.translatesDTOs,
88
88
  n
89
89
  ), C = {
90
90
  lastPullDate: u.lastPullDate,
91
- translatesDTOs: v
91
+ translatesDTOs: w
92
92
  };
93
- _.namespace(`I18N_${l.toUpper(e)}`).set(a, C, ":"), o(v);
93
+ _.namespace(`I18N_${l.toUpper(e)}`).set(a, C, ":"), o(w);
94
94
  }
95
95
  }
96
96
  }
97
- }), ie = {
97
+ }), le = {
98
98
  data() {
99
99
  return {
100
100
  LanguageSettingVisible: !1,
@@ -157,7 +157,7 @@ const te = (t) => {
157
157
  const r = n[a], {
158
158
  localhost: h
159
159
  } = n;
160
- return h ? null : y(m("Input"), {
160
+ return h ? null : y(d("Input"), {
161
161
  modelValue: r,
162
162
  onOnChange: (g) => {
163
163
  const i = g.target.value, {
@@ -236,12 +236,12 @@ const te = (t) => {
236
236
  });
237
237
  });
238
238
  }), l.isEmpty(a)) {
239
- w.error({
239
+ T.error({
240
240
  content: "没有需要保存的数据"
241
241
  });
242
242
  return;
243
243
  }
244
- const s = await ne({
244
+ const s = await oe({
245
245
  baseUrl: this.baseUrl,
246
246
  data: {
247
247
  appCode: this.appCode,
@@ -250,9 +250,9 @@ const te = (t) => {
250
250
  },
251
251
  token: this.token
252
252
  });
253
- s && s.data.result === 0 ? (w.success({
253
+ s && s.data.result === 0 ? (T.success({
254
254
  content: t || s.data.msg
255
- }), this.setLanguage(), this.initialData = l.cloneDeep(this.data.datas), this.mySaveData = [], this.router.go(0)) : w.error({
255
+ }), this.setLanguage(), this.initialData = l.cloneDeep(this.data.datas), this.mySaveData = [], this.router.go(0)) : T.error({
256
256
  content: s.data.msg || "保存失败"
257
257
  });
258
258
  },
@@ -283,7 +283,7 @@ const te = (t) => {
283
283
  },
284
284
  async search(t, e) {
285
285
  this.loading = !0;
286
- const a = await se({
286
+ const a = await ne({
287
287
  baseUrl: this.baseUrl,
288
288
  data: {
289
289
  appCode: this.appCode,
@@ -321,20 +321,20 @@ const te = (t) => {
321
321
  l.includes(t, s.code) && (s.checked = !0);
322
322
  }), this.languages = a, this.getPageData();
323
323
  } else
324
- w.error("获取语言失败,出错了");
324
+ T.error("获取语言失败,出错了");
325
325
  }
326
326
  }
327
- }, le = (t, e) => {
327
+ }, G = (t, e) => {
328
328
  const a = t.__vccOpts || t;
329
329
  for (const [s, n] of e)
330
330
  a[s] = n;
331
331
  return a;
332
332
  }, re = { key: 0 }, ce = { class: "extra" }, ue = { class: "gc_i18n_page" }, ge = { style: { display: "flex" } };
333
333
  function he(t, e, a, s, n, o) {
334
- const r = m("Spin"), h = m("Table"), g = m("TabPane"), i = m("Icon"), c = m("Checkbox"), u = m("DropdownItem"), k = m("DropdownMenu"), v = m("Dropdown"), C = m("Input"), I = m("Tabs"), B = m("Page"), R = m("Button"), j = m("Modal"), W = F("click-away");
335
- return f(), S(j, {
334
+ const r = d("Spin"), h = d("Table"), g = d("TabPane"), i = d("Icon"), c = d("Checkbox"), u = d("DropdownItem"), k = d("DropdownMenu"), w = d("Dropdown"), C = d("Input"), E = d("Tabs"), j = d("Page"), O = d("Button"), W = d("Modal"), H = q("click-away");
335
+ return f(), S(W, {
336
336
  modelValue: n.isModalVisible,
337
- "onUpdate:modelValue": e[4] || (e[4] = (d) => n.isModalVisible = d),
337
+ "onUpdate:modelValue": e[4] || (e[4] = (m) => n.isModalVisible = m),
338
338
  "mask-closable": !1,
339
339
  width: 70,
340
340
  title: "多语言管理中心",
@@ -342,17 +342,17 @@ function he(t, e, a, s, n, o) {
342
342
  onOnCancel: o.closeModal
343
343
  }, {
344
344
  default: p(() => [
345
- n.isModalVisible ? (f(), O("div", re, [
346
- y(I, {
345
+ n.isModalVisible ? (f(), I("div", re, [
346
+ y(E, {
347
347
  modelValue: n.type,
348
- "onUpdate:modelValue": e[2] || (e[2] = (d) => n.type = d),
348
+ "onUpdate:modelValue": e[2] || (e[2] = (m) => n.type = m),
349
349
  type: "card",
350
350
  class: "gc_i18n_tabs",
351
351
  onOnClick: o.changeTab
352
352
  }, {
353
353
  extra: p(() => [
354
354
  b("div", ce, [
355
- q((f(), S(v, {
355
+ Q((f(), S(w, {
356
356
  style: { width: "80px" },
357
357
  transfer: "",
358
358
  trigger: "custom",
@@ -362,17 +362,17 @@ function he(t, e, a, s, n, o) {
362
362
  list: p(() => [
363
363
  y(k, null, {
364
364
  default: p(() => [
365
- (f(!0), O(Q, null, X(n.languages, (d) => (f(), S(u, {
366
- key: d.code
365
+ (f(!0), I(X, null, Y(n.languages, (m) => (f(), S(u, {
366
+ key: m.code
367
367
  }, {
368
368
  default: p(() => [
369
369
  y(c, {
370
- modelValue: d.checked,
371
- "onUpdate:modelValue": (H) => d.checked = H,
370
+ modelValue: m.checked,
371
+ "onUpdate:modelValue": (J) => m.checked = J,
372
372
  onOnChange: o.saveLanguageSetting
373
373
  }, {
374
374
  default: p(() => [
375
- b("span", null, E(d.name), 1)
375
+ b("span", null, U(m.name), 1)
376
376
  ]),
377
377
  _: 2
378
378
  }, 1032, ["modelValue", "onUpdate:modelValue", "onOnChange"])
@@ -386,7 +386,7 @@ function he(t, e, a, s, n, o) {
386
386
  default: p(() => [
387
387
  b("a", {
388
388
  href: "javascript:void(0)",
389
- onClick: e[0] || (e[0] = (...d) => o.handleLanguageSettingOpen && o.handleLanguageSettingOpen(...d))
389
+ onClick: e[0] || (e[0] = (...m) => o.handleLanguageSettingOpen && o.handleLanguageSettingOpen(...m))
390
390
  }, [
391
391
  e[5] || (e[5] = L(" 语言 ", -1)),
392
392
  y(i, { type: "ios-arrow-down" })
@@ -394,14 +394,14 @@ function he(t, e, a, s, n, o) {
394
394
  ]),
395
395
  _: 1
396
396
  }, 8, ["visible"])), [
397
- [W, o.onClickOutside]
397
+ [H, o.onClickOutside]
398
398
  ]),
399
399
  y(C, {
400
400
  class: "gc_i18n_search",
401
401
  prefix: "ios-search",
402
402
  placeholder: "请输入搜索内容",
403
403
  modelValue: n.searchText,
404
- "onUpdate:modelValue": e[1] || (e[1] = (d) => n.searchText = d),
404
+ "onUpdate:modelValue": e[1] || (e[1] = (m) => n.searchText = m),
405
405
  clearable: "",
406
406
  onOnEnter: o.inputSearch,
407
407
  onOnClear: o.inputSearch
@@ -463,15 +463,15 @@ function he(t, e, a, s, n, o) {
463
463
  }, null, 8, ["columns", "data"]))
464
464
  ]),
465
465
  _: 1
466
- })) : U("", !0)
466
+ })) : K("", !0)
467
467
  ]),
468
468
  _: 1
469
469
  }, 8, ["modelValue", "onOnClick"]),
470
470
  b("div", ue, [
471
471
  b("div", ge, [
472
- y(B, {
472
+ y(j, {
473
473
  modelValue: o.firstResult,
474
- "onUpdate:modelValue": e[3] || (e[3] = (d) => o.firstResult = d),
474
+ "onUpdate:modelValue": e[3] || (e[3] = (m) => o.firstResult = m),
475
475
  total: n.page.totalRows,
476
476
  "page-size": 10,
477
477
  simple: "",
@@ -479,11 +479,11 @@ function he(t, e, a, s, n, o) {
479
479
  onOnChange: o.changePage
480
480
  }, null, 8, ["modelValue", "total", "onOnChange"]),
481
481
  b("div", null, [
482
- b("span", null, " 共 " + E(n.page.totalRows) + " 项当前页数据 ", 1)
482
+ b("span", null, " 共 " + U(n.page.totalRows) + " 项当前页数据 ", 1)
483
483
  ])
484
484
  ]),
485
485
  b("div", null, [
486
- y(R, {
486
+ y(O, {
487
487
  style: { "margin-right": "10px" },
488
488
  onClick: o.closeModal
489
489
  }, {
@@ -492,7 +492,7 @@ function he(t, e, a, s, n, o) {
492
492
  ])]),
493
493
  _: 1
494
494
  }, 8, ["onClick"]),
495
- y(R, {
495
+ y(O, {
496
496
  type: "primary",
497
497
  onClick: o.saveData
498
498
  }, {
@@ -503,12 +503,24 @@ function he(t, e, a, s, n, o) {
503
503
  }, 8, ["onClick"])
504
504
  ])
505
505
  ])
506
- ])) : U("", !0)
506
+ ])) : K("", !0)
507
507
  ]),
508
508
  _: 1
509
509
  }, 8, ["modelValue", "onOnCancel"]);
510
510
  }
511
- const de = /* @__PURE__ */ le(ie, [["render", he], ["__scopeId", "data-v-1f438196"]]);
511
+ const de = /* @__PURE__ */ G(le, [["render", he], ["__scopeId", "data-v-1f438196"]]), me = {}, pe = { class: "earth" };
512
+ function fe(t, e) {
513
+ const a = d("Input"), s = d("Icon");
514
+ return f(), I("div", pe, [
515
+ y(a, { class: "input" }),
516
+ y(s, {
517
+ class: "icon",
518
+ type: "ios-globe",
519
+ size: "20"
520
+ })
521
+ ]);
522
+ }
523
+ const ye = /* @__PURE__ */ G(me, [["render", fe]]);
512
524
  function V(t) {
513
525
  const e = [], a = /(?:\$t|_ctx\.\$t)\s*\(\s*(['"])([^'"]+?)\1/gs;
514
526
  if (t.template) {
@@ -542,7 +554,7 @@ function V(t) {
542
554
  }
543
555
  return [...new Set(e)];
544
556
  }
545
- function me(t) {
557
+ function _e(t) {
546
558
  return { all: t = t || /* @__PURE__ */ new Map(), on: function(e, a) {
547
559
  var s = t.get(e);
548
560
  s ? s.push(a) : t.set(e, [a]);
@@ -558,29 +570,29 @@ function me(t) {
558
570
  });
559
571
  } };
560
572
  }
561
- const G = function() {
573
+ const P = function() {
562
574
  return document.ontouchstart !== null ? "click" : "touchstart";
563
- }, T = "__vue_click_away__", P = function(t, e, a) {
564
- z(t);
575
+ }, N = "__vue_click_away__", z = function(t, e, a) {
576
+ B(t);
565
577
  let s = a.context, n = e.value, o = !1;
566
578
  setTimeout(function() {
567
579
  o = !0;
568
- }, 0), t[T] = function(r) {
580
+ }, 0), t[N] = function(r) {
569
581
  if ((!t || !t.contains(r.target)) && n && o && typeof n == "function")
570
582
  return n.call(s, r);
571
- }, document.addEventListener(G(), t[T], !1);
572
- }, z = function(t) {
573
- document.removeEventListener(G(), t[T], !1), delete t[T];
574
- }, pe = function(t, e, a) {
575
- e.value !== e.oldValue && P(t, e, a);
576
- }, fe = {
583
+ }, document.addEventListener(P(), t[N], !1);
584
+ }, B = function(t) {
585
+ document.removeEventListener(P(), t[N], !1), delete t[N];
586
+ }, Se = function(t, e, a) {
587
+ e.value !== e.oldValue && z(t, e, a);
588
+ }, ke = {
577
589
  install: function(t) {
578
- t.directive("click-away", ye);
590
+ t.directive("click-away", be);
579
591
  }
580
- }, ye = {
581
- mounted: P,
582
- updated: pe,
583
- unmounted: z
592
+ }, be = {
593
+ mounted: z,
594
+ updated: Se,
595
+ unmounted: B
584
596
  };
585
597
  function M(t) {
586
598
  const e = {
@@ -589,9 +601,9 @@ function M(t) {
589
601
  }, a = {
590
602
  orgCode: t
591
603
  }, s = JSON.stringify(e), n = JSON.stringify(a);
592
- return ee.JWS.sign("HS512", s, n, "");
604
+ return te.JWS.sign("HS512", s, n, "");
593
605
  }
594
- class D {
606
+ class v {
595
607
  constructor(e = {}) {
596
608
  const {
597
609
  router: a,
@@ -604,7 +616,7 @@ class D {
604
616
  keyboard: i,
605
617
  locale: c
606
618
  } = e;
607
- this.token = o || M(r) || _.get("I18N_TOKEN"), this.loadI18n = !0, this.appCode = s, this.router = a, this.locale = c || _.get("I18N_LANGUAGE") || navigator.language || "zh-CN", this.name = "", this.messages = n || {}, this.translationKeys = [], this.translationKeySet = /* @__PURE__ */ new Set(), this.loginRouteName = h || "login", this.login = g, this.loginTranslationKeys = [], this.keyboard = i || "shift>t", this.baseUrl = e.dev ? "https://test.ihotel.cn" : "https://trans.ihotel.cn", this.initRouterGuards(), this.initI18n(e), J.bind(this.keyboard, (u) => {
619
+ this.token = o || M(r) || _.get("I18N_TOKEN"), this.loadI18n = !0, this.appCode = s, this.router = a, this.locale = c || _.get("I18N_LANGUAGE") || navigator.language || "zh-CN", this.name = "", this.messages = n || {}, this.translationKeys = [], this.translationKeySet = /* @__PURE__ */ new Set(), this.loginRouteName = h || "login", this.login = g, this.loginTranslationKeys = [], this.keyboard = i || "shift>t", this.baseUrl = e.dev ? "https://test.ihotel.cn" : "https://trans.ihotel.cn", this.initRouterGuards(), this.initI18n(e), F.bind(this.keyboard, (u) => {
608
620
  !this.configInstance && this.name != this.loginRouteName && (this.translationKeys = Array.from(this.translationKeySet), this.configInstance = this.createModal(this.name), this.configInstance.openModal({ name: this.name }));
609
621
  }), this.setupLanguageChangeListener();
610
622
  }
@@ -617,7 +629,7 @@ class D {
617
629
  }
618
630
  // 初始化路由守卫
619
631
  initRouterGuards() {
620
- D._routerGuardRegistered || (D._routerGuardRegistered = !0, this.router.beforeEach(async (e, a, s) => {
632
+ v._routerGuardRegistered || (v._routerGuardRegistered = !0, this.router.beforeEach(async (e, a, s) => {
621
633
  var h, g;
622
634
  const { language: n, token: o } = e.query;
623
635
  this.configInstance && this.configInstance.closeModal(), this.name = e.name, this.translationKeySet = /* @__PURE__ */ new Set(), o && this.setToken(o), this.loadI18n && await this.setLanguage(n || this.locale), this.loadI18n = !1;
@@ -650,9 +662,9 @@ class D {
650
662
  return;
651
663
  }
652
664
  s();
653
- }), D._afterEachGuardRegistered || (D._afterEachGuardRegistered = !0, this.router.afterEach(async () => {
665
+ }), v._afterEachGuardRegistered || (v._afterEachGuardRegistered = !0, this.router.afterEach(async () => {
654
666
  var n, o, r;
655
- await Y();
667
+ await Z();
656
668
  const e = Array.from(this.translationKeySet), a = Array.from(
657
669
  /* @__PURE__ */ new Set([...this.translationKeys || [], ...e])
658
670
  );
@@ -661,7 +673,7 @@ class D {
661
673
  }
662
674
  // 初始化 i18n 实例
663
675
  initI18n(e) {
664
- this.i18n = $({
676
+ this.i18n = ee({
665
677
  locale: this.locale,
666
678
  allowComposition: !0,
667
679
  globalInjection: !0,
@@ -718,31 +730,43 @@ class D {
718
730
  }
719
731
  }
720
732
  }
721
- async setLanguage(e) {
722
- return new Promise(async (a, s) => {
723
- const n = await oe({
733
+ async setLanguage(e = "zh-CN") {
734
+ const a = "I18N_MESSAGES_COMMON_" + e;
735
+ let s = _.get(a);
736
+ if (console.log("commonMessages", s), l.isEmpty(s)) {
737
+ const n = await D.get(
738
+ `https://cdn.ihotel.cn/i18n_messages/${e}.json`
739
+ );
740
+ if (console.log("lang", n), n) {
741
+ const { data: o } = n;
742
+ s = o, _.set(a, o);
743
+ }
744
+ }
745
+ return new Promise(async (n, o) => {
746
+ const r = await ie({
724
747
  baseUrl: this.baseUrl,
725
748
  appCode: this.appCode,
726
749
  language: e || this.locale,
727
750
  token: this.token,
728
751
  routerName: this.name
729
752
  });
730
- if (n) {
731
- const o = te(n), r = l.assign(
753
+ if (r) {
754
+ const h = ae(r), g = l.assign(
732
755
  {},
756
+ s,
733
757
  l.get(this.messages, e),
734
- o
758
+ h
735
759
  );
736
- this.i18n.global.setLocaleMessage(e, r);
760
+ this.i18n.global.setLocaleMessage(e, g);
737
761
  }
738
- this.locale = e, this.i18n.global.locale.value = e, _.set("I18N_LANGUAGE", e), a(!0);
762
+ this.locale = e, this.i18n.global.locale.value = e, _.set("I18N_LANGUAGE", e), n(!0);
739
763
  });
740
764
  }
741
765
  createModal(e) {
742
- const a = me();
766
+ const a = _e();
743
767
  return a.on("closeModal", (s) => {
744
768
  this.configInstance = null;
745
- }), Z(de, {
769
+ }), $(de, {
746
770
  appCode: this.appCode,
747
771
  router: this.router,
748
772
  token: this.token,
@@ -757,15 +781,15 @@ class D {
757
781
  // 基础URL
758
782
  emitter: a
759
783
  // 将事件总线作为 prop 传递
760
- }).use(K).use(fe).mount(document.createElement("div"));
784
+ }).use(R).use(ke).mount(document.createElement("div"));
761
785
  }
762
786
  install(e, a = {}) {
763
- e.use(K, {
787
+ e.use(R, {
764
788
  i18n: this.i18n
765
- }), e.use(this.i18n);
789
+ }), e.use(this.i18n), e.component("i18n-earth", ye);
766
790
  }
767
791
  }
768
792
  export {
769
- D as I18n,
770
- D as default
793
+ v as I18n,
794
+ v as default
771
795
  };
@@ -1 +1 @@
1
- (function(p,C){typeof exports=="object"&&typeof module<"u"?C(exports,require("keyboardjs"),require("view-ui-plus"),require("view-ui-plus/dist/styles/viewuiplus.css"),require("vue"),require("vue-i18n"),require("lodash-es"),require("axios"),require("store2"),require("jsrsasign")):typeof define=="function"&&define.amd?define(["exports","keyboardjs","view-ui-plus","view-ui-plus/dist/styles/viewuiplus.css","vue","vue-i18n","lodash-es","axios","store2","jsrsasign"],C):(p=typeof globalThis<"u"?globalThis:p||self,C(p.gc_i18n={},p.keyboardJS,p.iview,null,p.Vue,p.vueI18n,p._,p.Axios,p.store2,p.jsrsasign))})(this,(function(p,C,S,ne,a,K,r,w,f,U){"use strict";const M=t=>{const e={};for(const n of t)e[n.key]=n.value;return e},B=(t,e,n)=>(e.forEach(s=>{console.log("obj2.key ",s.key);const o=s.key.split(".");o[0]==="common"&&r.find(t,{key:`${n}.${o[1]}`})&&r.remove(t,{key:`${n}.${o[1]}`});const i=r.find(t,{key:s.key});i?r.merge(i,s):t.push(s)}),t),V=async({baseUrl:t,token:e})=>w.get(t+"/i18n-web/sysoption/getsupportedlangs",{headers:{Authorization:e}}),_=async({appCode:t,language:e="zh-CN",page:n,lastPullDate:s,baseUrl:o,token:i})=>new Promise(async(c,u)=>{const g=o+"/i18n-web/kv_translate/kv_translates",l=s?g+"?lastPullDate="+s:g,h=await w({url:l,method:"GET",headers:{appCode:t,page:n,language:e,Authorization:i}});h.data&&h.data.result==0?c(h.data.retVal):c(h)}),A=async({data:t,token:e,baseUrl:n})=>w({url:n+"/i18n-web/kv_translate/userDicts",method:"POST",headers:{Authorization:e},data:t}),P=async({data:t,token:e,baseUrl:n})=>w({url:n+"/i18n-web/kv_translate/batch",method:"POST",data:t,headers:{Authorization:e}}),G=async({baseUrl:t,appCode:e,language:n="zh-CN",token:s,routerName:o})=>new Promise(async(i,c)=>{const u=f.namespace(`I18N_${r.toUpper(e)}`),g={baseUrl:t,appCode:e,language:n,token:s},l=u.get(n);if(!l||!l.lastPullDate){const h=await _(g);h&&(u.set(n,h),i(h.translatesDTOs))}else{const{lastPullDate:h}=l,d=await _({...g,lastPullDate:h});if(d){const y=r.get(l,"translatesDTOs");if(r.isEmpty(d.translatesDTOs))i(y);else{const N=B(y,d.translatesDTOs,o),T={lastPullDate:d.lastPullDate,translatesDTOs:N};f.namespace(`I18N_${r.toUpper(e)}`).set(n,T,":"),i(N)}}}}),z={data(){return{LanguageSettingVisible:!1,isModalVisible:!1,loading:!1,searchText:"",name:"",type:"pageData",languages:[],mySaveData:[],pageData:[],pageDataShow:[],page:{pageSize:10,firstResult:0},data:[]}},computed:{firstResult(){return this.page.firstResult/this.page.pageSize+1},columns(){let t=[{title:"关键词",fixed:"left",width:110,key:"dictKey"}];return r.map(this.languages,e=>{const n=e.code;if(e.checked)return t.push({title:e.name,key:n,render:(s,{row:o,index:i})=>{const c=o[n],{localhost:u}=o;return u?null:a.createVNode(a.resolveComponent("Input"),{modelValue:c,onOnChange:g=>{const l=g.target.value,{dictKey:h}=o,d=r.findIndex(this.mySaveData,{dictKey:h});d>-1?this.mySaveData[d][n]=l:this.mySaveData.push({...o,[n]:l,page:this.type==="loginData"?this.loginRouteName:this.type==="pageData"?this.name:"common"})}},null)}})}),t}},props:{appCode:String,router:Object,setLanguage:Function,token:String,baseUrl:String,translationKeys:Array,loginRouteName:String,loginTranslationKeys:Array,login:{type:Boolean,default:!0},emitter:Object},methods:{saveLanguageSetting(t){const e=r.map(r.filter(this.languages,n=>n.checked),"code");f.set("I18N_LANGUAGE_SETTING",e)},handleLanguageSettingOpen(){this.LanguageSettingVisible=!this.LanguageSettingVisible},onClickOutside(){this.LanguageSettingVisible=!1},inputSearch(){this.type==="pageData"?this.getPageData():this.search()},closeModal(){this.searchText="",this.type="pageData",this.isModalVisible=!1,this.emitter.emit("closeModal")},openModal({name:t}){this.isModalVisible||(this.isModalVisible=!0,this.name=t,this.init())},findShallowStringDiff(t){return r.find(t,["_isEdit",!0])},async saveData({msg:t="保存成功"},e=!0){const n=[];if(r.map(this.mySaveData,o=>{r.map(this.languages,i=>{n.push({key:o.dictKey,page:o.page,lang:i.code,value:o[i.code]})})}),r.isEmpty(n)){S.Message.error({content:"没有需要保存的数据"});return}const s=await P({baseUrl:this.baseUrl,data:{appCode:this.appCode,isLocal:"F",data:n},token:this.token});s&&s.data.result===0?(S.Message.success({content:t||s.data.msg}),this.setLanguage(),this.initialData=r.cloneDeep(this.data.datas),this.mySaveData=[],this.router.go(0)):S.Message.error({content:s.data.msg||"保存失败"})},async saveNoEqual(){r.isEmpty(this.mySaveData)||this.saveData({msg:"已为您自动保存"},!1)},changePage(t){this.saveNoEqual(),this.type==="pageData"?this.getPageData({firstResult:(t-1)*this.page.pageSize}):this.search({firstResult:(t-1)*this.page.pageSize})},async getPageData(t){this.search({...t,commaSeparatedKeys:this.translationKeys.toString()},"pageData")},async getLoginData(t){this.search({...t,page:this.loginRouteName,commaSeparatedKeys:this.loginTranslationKeys.toString()},"pageData")},async search(t,e){this.loading=!0;const n=await A({baseUrl:this.baseUrl,data:{appCode:this.appCode,searchBlur:this.searchText,commaSeparatedLangs:r.map(this.languages,"code").toString(),page:e==="loginData"?this.loginRouteName:e==="pageData"?this.name:"common",pageSize:10,...t},token:this.token});if(n){this.initialData=r.cloneDeep(n.data.retVal.datas);let s=n.data.retVal.datas;this.data=r.cloneDeep(s),this.page={firstResult:n.data.retVal.firstResult,pageSize:n.data.retVal.pageSize,totalRows:n.data.retVal.totalRows}}this.loading=!1},changeTab(t){this.type=t,this.mySaveData=[],t==="data"?this.search():t==="pageData"?this.getPageData():t==="loginData"&&this.getLoginData()},async init(){let t=f.get("I18N_LANGUAGE_SETTING");const e=await V({token:this.token,baseUrl:this.baseUrl});if(e&&e.data.result==0){let n=e.data.retVal;r.isEmpty(t)&&(t=["zh-CN","en-US","zh-TW"]),r.map(n,s=>{r.includes(t,s.code)&&(s.checked=!0)}),this.languages=n,this.getPageData()}else S.Message.error("获取语言失败,出错了")}}},j=(t,e)=>{const n=t.__vccOpts||t;for(const[s,o]of e)n[s]=o;return n},q={key:0},W={class:"extra"},H={class:"gc_i18n_page"},J={style:{display:"flex"}};function F(t,e,n,s,o,i){const c=a.resolveComponent("Spin"),u=a.resolveComponent("Table"),g=a.resolveComponent("TabPane"),l=a.resolveComponent("Icon"),h=a.resolveComponent("Checkbox"),d=a.resolveComponent("DropdownItem"),y=a.resolveComponent("DropdownMenu"),N=a.resolveComponent("Dropdown"),T=a.resolveComponent("Input"),R=a.resolveComponent("Tabs"),$=a.resolveComponent("Page"),O=a.resolveComponent("Button"),ee=a.resolveComponent("Modal"),te=a.resolveDirective("click-away");return a.openBlock(),a.createBlock(ee,{modelValue:o.isModalVisible,"onUpdate:modelValue":e[4]||(e[4]=m=>o.isModalVisible=m),"mask-closable":!1,width:70,title:"多语言管理中心","footer-hide":"",onOnCancel:i.closeModal},{default:a.withCtx(()=>[o.isModalVisible?(a.openBlock(),a.createElementBlock("div",q,[a.createVNode(R,{modelValue:o.type,"onUpdate:modelValue":e[2]||(e[2]=m=>o.type=m),type:"card",class:"gc_i18n_tabs",onOnClick:i.changeTab},{extra:a.withCtx(()=>[a.createElementVNode("div",W,[a.withDirectives((a.openBlock(),a.createBlock(N,{style:{width:"80px"},transfer:"",trigger:"custom",placement:"bottom-start",visible:o.LanguageSettingVisible},{list:a.withCtx(()=>[a.createVNode(y,null,{default:a.withCtx(()=>[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(o.languages,m=>(a.openBlock(),a.createBlock(d,{key:m.code},{default:a.withCtx(()=>[a.createVNode(h,{modelValue:m.checked,"onUpdate:modelValue":ae=>m.checked=ae,onOnChange:i.saveLanguageSetting},{default:a.withCtx(()=>[a.createElementVNode("span",null,a.toDisplayString(m.name),1)]),_:2},1032,["modelValue","onUpdate:modelValue","onOnChange"])]),_:2},1024))),128))]),_:1})]),default:a.withCtx(()=>[a.createElementVNode("a",{href:"javascript:void(0)",onClick:e[0]||(e[0]=(...m)=>i.handleLanguageSettingOpen&&i.handleLanguageSettingOpen(...m))},[e[5]||(e[5]=a.createTextVNode(" 语言 ",-1)),a.createVNode(l,{type:"ios-arrow-down"})])]),_:1},8,["visible"])),[[te,i.onClickOutside]]),a.createVNode(T,{class:"gc_i18n_search",prefix:"ios-search",placeholder:"请输入搜索内容",modelValue:o.searchText,"onUpdate:modelValue":e[1]||(e[1]=m=>o.searchText=m),clearable:"",onOnEnter:i.inputSearch,onOnClear:i.inputSearch},null,8,["modelValue","onOnEnter","onOnClear"])])]),default:a.withCtx(()=>[a.createVNode(g,{name:"pageData",label:"当前页面"},{default:a.withCtx(()=>[o.loading?(a.openBlock(),a.createBlock(c,{key:0,class:"gc_i18n_spin"})):(a.openBlock(),a.createBlock(u,{key:1,border:"",height:380,columns:i.columns,data:o.data},null,8,["columns","data"]))]),_:1}),a.createVNode(g,{name:"data",label:"当前应用"},{default:a.withCtx(()=>[o.loading?(a.openBlock(),a.createBlock(c,{key:0,class:"gc_i18n_spin"})):(a.openBlock(),a.createBlock(u,{key:1,border:"",height:380,columns:i.columns,data:o.data},null,8,["columns","data"]))]),_:1}),n.login?(a.openBlock(),a.createBlock(g,{key:0,name:"loginData",label:"登录页面"},{default:a.withCtx(()=>[o.loading?(a.openBlock(),a.createBlock(c,{key:0,class:"gc_i18n_spin"})):(a.openBlock(),a.createBlock(u,{key:1,border:"",height:380,columns:i.columns,data:o.data},null,8,["columns","data"]))]),_:1})):a.createCommentVNode("",!0)]),_:1},8,["modelValue","onOnClick"]),a.createElementVNode("div",H,[a.createElementVNode("div",J,[a.createVNode($,{modelValue:i.firstResult,"onUpdate:modelValue":e[3]||(e[3]=m=>i.firstResult=m),total:o.page.totalRows,"page-size":10,simple:"","show-total":"",onOnChange:i.changePage},null,8,["modelValue","total","onOnChange"]),a.createElementVNode("div",null,[a.createElementVNode("span",null," 共 "+a.toDisplayString(o.page.totalRows)+" 项当前页数据 ",1)])]),a.createElementVNode("div",null,[a.createVNode(O,{style:{"margin-right":"10px"},onClick:i.closeModal},{default:a.withCtx(()=>[...e[6]||(e[6]=[a.createTextVNode("关闭",-1)])]),_:1},8,["onClick"]),a.createVNode(O,{type:"primary",onClick:i.saveData},{default:a.withCtx(()=>[...e[7]||(e[7]=[a.createTextVNode("保存",-1)])]),_:1},8,["onClick"])])])])):a.createCommentVNode("",!0)]),_:1},8,["modelValue","onOnCancel"])}const v=j(z,[["render",F],["__scopeId","data-v-1f438196"]]);function D(t){const e=[],n=/(?:\$t|_ctx\.\$t)\s*\(\s*(['"])([^'"]+?)\1/gs;if(t.template){let s;for(;(s=n.exec(t.template))!==null;)e.push(s[2])}if(t.render){const s=t.render.toString();let o;for(;(o=n.exec(s))!==null;)e.push(o[2])}if(t.setup){const s=t.setup.toString();let o;for(;(o=n.exec(s))!==null;)e.push(o[2])}if(t.methods)for(const s in t.methods){const o=t.methods[s].toString();let i;for(;(i=n.exec(o))!==null;)e.push(i[2])}if(t.components)for(const s in t.components){const o=t.components[s];e.push(...D(o))}return[...new Set(e)]}function Q(t){return{all:t=t||new Map,on:function(e,n){var s=t.get(e);s?s.push(n):t.set(e,[n])},off:function(e,n){var s=t.get(e);s&&(n?s.splice(s.indexOf(n)>>>0,1):t.set(e,[]))},emit:function(e,n){var s=t.get(e);s&&s.slice().map(function(o){o(n)}),(s=t.get("*"))&&s.slice().map(function(o){o(e,n)})}}}const L=function(){return document.ontouchstart!==null?"click":"touchstart"},b="__vue_click_away__",x=function(t,e,n){E(t);let s=n.context,o=e.value,i=!1;setTimeout(function(){i=!0},0),t[b]=function(c){if((!t||!t.contains(c.target))&&o&&i&&typeof o=="function")return o.call(s,c)},document.addEventListener(L(),t[b],!1)},E=function(t){document.removeEventListener(L(),t[b],!1),delete t[b]},X=function(t,e,n){e.value!==e.oldValue&&x(t,e,n)},Y={install:function(t){t.directive("click-away",Z)}},Z={mounted:x,updated:X,unmounted:E};function I(t){const e={alg:"HS512"},n={orgCode:t},s=JSON.stringify(e),o=JSON.stringify(n);return U.jws.JWS.sign("HS512",s,o,"")}class k{constructor(e={}){const{router:n,appCode:s,messages:o,token:i,orgCode:c,loginRouteName:u,login:g,keyboard:l,locale:h}=e;this.token=i||I(c)||f.get("I18N_TOKEN"),this.loadI18n=!0,this.appCode=s,this.router=n,this.locale=h||f.get("I18N_LANGUAGE")||navigator.language||"zh-CN",this.name="",this.messages=o||{},this.translationKeys=[],this.translationKeySet=new Set,this.loginRouteName=u||"login",this.login=g,this.loginTranslationKeys=[],this.keyboard=l||"shift>t",this.baseUrl=e.dev?"https://test.ihotel.cn":"https://trans.ihotel.cn",this.initRouterGuards(),this.initI18n(e),C.bind(this.keyboard,d=>{!this.configInstance&&this.name!=this.loginRouteName&&(this.translationKeys=Array.from(this.translationKeySet),this.configInstance=this.createModal(this.name),this.configInstance.openModal({name:this.name}))}),this.setupLanguageChangeListener()}setupLanguageChangeListener(){"onlanguagechange"in window&&window.addEventListener("languagechange",()=>{const e=navigator.language;e!==this.locale&&this.setLanguage(e)})}initRouterGuards(){k._routerGuardRegistered||(k._routerGuardRegistered=!0,this.router.beforeEach(async(e,n,s)=>{var u,g;const{language:o,token:i}=e.query;this.configInstance&&this.configInstance.closeModal(),this.name=e.name,this.translationKeySet=new Set,i&&this.setToken(i),this.loadI18n&&await this.setLanguage(o||this.locale),this.loadI18n=!1;const c=this.router.getRoutes().find(l=>l.name===this.loginRouteName||l.path===`/${this.loginRouteName}`);if(c&&c.components){let l=(u=c.components)==null?void 0:u.default;if(typeof l=="function"&&l.toString().includes("import("))try{l=await l(),l=l.default}catch(d){console.error("加载异步组件时出错:",d),s();return}const h=D(l);this.loginTranslationKeys=h}if(e.matched.length>0)try{const l=[];for(const h of e.matched){let d=(g=h.components)==null?void 0:g.default;if(typeof d=="function"&&d.toString().includes("import(")&&(d=await d(),d=d.default),d){const y=D(d);l.push(...y)}}this.translationKeys=l}catch(l){console.error("加载异步组件时出错:",l),s();return}s()}),k._afterEachGuardRegistered||(k._afterEachGuardRegistered=!0,this.router.afterEach(async()=>{var o,i,c;await a.nextTick();const e=Array.from(this.translationKeySet),n=Array.from(new Set([...this.translationKeys||[],...e]));this.translationKeys=n,((c=(i=(o=this.router)==null?void 0:o.currentRoute)==null?void 0:i.value)==null?void 0:c.name)===this.loginRouteName&&(this.loginTranslationKeys=n)})))}initI18n(e){this.i18n=K.createI18n({locale:this.locale,allowComposition:!0,globalInjection:!0,legacy:!1,silentTranslationWarn:!0,silentFallbackWarn:!0,missingWarn:!1,fallbackWarn:!1,...e});const n=this.i18n.global.t;globalThis.$t=this.i18n.global.t=(s,o)=>{var c,u,g;typeof s=="string"&&this.translationKeySet.add(s);const i=(g=(u=(c=this.router)==null?void 0:c.currentRoute)==null?void 0:u.value)==null?void 0:g.name;if(i){const l=`${i}.${s}`,h=n(l);if(h!==l&&!r.isEmpty(h))return h;{const d=`common.${s}`,y=n(d);return y!==d?y:n(s,o)}}else return n(s,o)},globalThis.$i18nLogin=async s=>{this.setToken(I(s)),this.clearI18n(),await this.setLanguage(this.locale),location.reload()},globalThis.$i18nLogout=s=>{this.clearI18n(),location.reload()},globalThis.$deepScan=function(s){return s},globalThis.$clearI18n=this.clearI18n=()=>{f.namespace(`I18N_${r.toUpper(this.appCode)}`).clearAll()},globalThis.$changeLocale=this.changeLocale=this.i18n.global.changeLocale=async s=>{await this.setLanguage(s||this.locale)}}setToken(e){this.token=e,f.set("I18N_TOKEN",e)}async getLanguages(e=!1){const n=f.get("I18N_LANGUAGES");if(n&&!e)return n;{const s=await V({baseUrl:this.baseUrl,appCode:this.appCode,token:this.token});if(s.data){const o=r.get(s.data,"retVal");return f.set("I18N_LANGUAGES",o),o}}}async setLanguage(e){return new Promise(async(n,s)=>{const o=await G({baseUrl:this.baseUrl,appCode:this.appCode,language:e||this.locale,token:this.token,routerName:this.name});if(o){const i=M(o),c=r.assign({},r.get(this.messages,e),i);this.i18n.global.setLocaleMessage(e,c)}this.locale=e,this.i18n.global.locale.value=e,f.set("I18N_LANGUAGE",e),n(!0)})}createModal(e){const n=Q();return n.on("closeModal",s=>{this.configInstance=null}),a.createApp(v,{appCode:this.appCode,router:this.router,token:this.token,setLanguage:this.setLanguage.bind(this,this.locale),name:e||this.name,translationKeys:this.translationKeys,loginRouteName:this.loginRouteName,loginTranslationKeys:this.loginTranslationKeys,login:this.login,baseUrl:this.baseUrl,emitter:n}).use(S).use(Y).mount(document.createElement("div"))}install(e,n={}){e.use(S,{i18n:this.i18n}),e.use(this.i18n)}}p.I18n=k,p.default=k,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
1
+ (function(p,C){typeof exports=="object"&&typeof module<"u"?C(exports,require("keyboardjs"),require("view-ui-plus"),require("view-ui-plus/dist/styles/viewuiplus.css"),require("vue"),require("vue-i18n"),require("lodash-es"),require("axios"),require("store2"),require("jsrsasign")):typeof define=="function"&&define.amd?define(["exports","keyboardjs","view-ui-plus","view-ui-plus/dist/styles/viewuiplus.css","vue","vue-i18n","lodash-es","axios","store2","jsrsasign"],C):(p=typeof globalThis<"u"?globalThis:p||self,C(p.gc_i18n={},p.keyboardJS,p.iview,null,p.Vue,p.vueI18n,p._,p.Axios,p.store2,p.jsrsasign))})(this,(function(p,C,S,le,t,K,r,N,f,U){"use strict";const B=a=>{const e={};for(const n of a)e[n.key]=n.value;return e},A=(a,e,n)=>(e.forEach(s=>{console.log("obj2.key ",s.key);const o=s.key.split(".");o[0]==="common"&&r.find(a,{key:`${n}.${o[1]}`})&&r.remove(a,{key:`${n}.${o[1]}`});const i=r.find(a,{key:s.key});i?r.merge(i,s):a.push(s)}),a),D=async({baseUrl:a,token:e})=>N.get(a+"/i18n-web/sysoption/getsupportedlangs",{headers:{Authorization:e}}),T=async({appCode:a,language:e="zh-CN",page:n,lastPullDate:s,baseUrl:o,token:i})=>new Promise(async(c,u)=>{const g=o+"/i18n-web/kv_translate/kv_translates",l=s?g+"?lastPullDate="+s:g,h=await N({url:l,method:"GET",headers:{appCode:a,page:n,language:e,Authorization:i}});h.data&&h.data.result==0?c(h.data.retVal):c(h)}),G=async({data:a,token:e,baseUrl:n})=>N({url:n+"/i18n-web/kv_translate/userDicts",method:"POST",headers:{Authorization:e},data:a}),P=async({data:a,token:e,baseUrl:n})=>N({url:n+"/i18n-web/kv_translate/batch",method:"POST",data:a,headers:{Authorization:e}}),z=async({baseUrl:a,appCode:e,language:n="zh-CN",token:s,routerName:o})=>new Promise(async(i,c)=>{const u=f.namespace(`I18N_${r.toUpper(e)}`),g={baseUrl:a,appCode:e,language:n,token:s},l=u.get(n);if(!l||!l.lastPullDate){const h=await T(g);h&&(u.set(n,h),i(h.translatesDTOs))}else{const{lastPullDate:h}=l,d=await T({...g,lastPullDate:h});if(d){const y=r.get(l,"translatesDTOs");if(r.isEmpty(d.translatesDTOs))i(y);else{const _=A(y,d.translatesDTOs,o),V={lastPullDate:d.lastPullDate,translatesDTOs:_};f.namespace(`I18N_${r.toUpper(e)}`).set(n,V,":"),i(_)}}}}),j={data(){return{LanguageSettingVisible:!1,isModalVisible:!1,loading:!1,searchText:"",name:"",type:"pageData",languages:[],mySaveData:[],pageData:[],pageDataShow:[],page:{pageSize:10,firstResult:0},data:[]}},computed:{firstResult(){return this.page.firstResult/this.page.pageSize+1},columns(){let a=[{title:"关键词",fixed:"left",width:110,key:"dictKey"}];return r.map(this.languages,e=>{const n=e.code;if(e.checked)return a.push({title:e.name,key:n,render:(s,{row:o,index:i})=>{const c=o[n],{localhost:u}=o;return u?null:t.createVNode(t.resolveComponent("Input"),{modelValue:c,onOnChange:g=>{const l=g.target.value,{dictKey:h}=o,d=r.findIndex(this.mySaveData,{dictKey:h});d>-1?this.mySaveData[d][n]=l:this.mySaveData.push({...o,[n]:l,page:this.type==="loginData"?this.loginRouteName:this.type==="pageData"?this.name:"common"})}},null)}})}),a}},props:{appCode:String,router:Object,setLanguage:Function,token:String,baseUrl:String,translationKeys:Array,loginRouteName:String,loginTranslationKeys:Array,login:{type:Boolean,default:!0},emitter:Object},methods:{saveLanguageSetting(a){const e=r.map(r.filter(this.languages,n=>n.checked),"code");f.set("I18N_LANGUAGE_SETTING",e)},handleLanguageSettingOpen(){this.LanguageSettingVisible=!this.LanguageSettingVisible},onClickOutside(){this.LanguageSettingVisible=!1},inputSearch(){this.type==="pageData"?this.getPageData():this.search()},closeModal(){this.searchText="",this.type="pageData",this.isModalVisible=!1,this.emitter.emit("closeModal")},openModal({name:a}){this.isModalVisible||(this.isModalVisible=!0,this.name=a,this.init())},findShallowStringDiff(a){return r.find(a,["_isEdit",!0])},async saveData({msg:a="保存成功"},e=!0){const n=[];if(r.map(this.mySaveData,o=>{r.map(this.languages,i=>{n.push({key:o.dictKey,page:o.page,lang:i.code,value:o[i.code]})})}),r.isEmpty(n)){S.Message.error({content:"没有需要保存的数据"});return}const s=await P({baseUrl:this.baseUrl,data:{appCode:this.appCode,isLocal:"F",data:n},token:this.token});s&&s.data.result===0?(S.Message.success({content:a||s.data.msg}),this.setLanguage(),this.initialData=r.cloneDeep(this.data.datas),this.mySaveData=[],this.router.go(0)):S.Message.error({content:s.data.msg||"保存失败"})},async saveNoEqual(){r.isEmpty(this.mySaveData)||this.saveData({msg:"已为您自动保存"},!1)},changePage(a){this.saveNoEqual(),this.type==="pageData"?this.getPageData({firstResult:(a-1)*this.page.pageSize}):this.search({firstResult:(a-1)*this.page.pageSize})},async getPageData(a){this.search({...a,commaSeparatedKeys:this.translationKeys.toString()},"pageData")},async getLoginData(a){this.search({...a,page:this.loginRouteName,commaSeparatedKeys:this.loginTranslationKeys.toString()},"pageData")},async search(a,e){this.loading=!0;const n=await G({baseUrl:this.baseUrl,data:{appCode:this.appCode,searchBlur:this.searchText,commaSeparatedLangs:r.map(this.languages,"code").toString(),page:e==="loginData"?this.loginRouteName:e==="pageData"?this.name:"common",pageSize:10,...a},token:this.token});if(n){this.initialData=r.cloneDeep(n.data.retVal.datas);let s=n.data.retVal.datas;this.data=r.cloneDeep(s),this.page={firstResult:n.data.retVal.firstResult,pageSize:n.data.retVal.pageSize,totalRows:n.data.retVal.totalRows}}this.loading=!1},changeTab(a){this.type=a,this.mySaveData=[],a==="data"?this.search():a==="pageData"?this.getPageData():a==="loginData"&&this.getLoginData()},async init(){let a=f.get("I18N_LANGUAGE_SETTING");const e=await D({token:this.token,baseUrl:this.baseUrl});if(e&&e.data.result==0){let n=e.data.retVal;r.isEmpty(a)&&(a=["zh-CN","en-US","zh-TW"]),r.map(n,s=>{r.includes(a,s.code)&&(s.checked=!0)}),this.languages=n,this.getPageData()}else S.Message.error("获取语言失败,出错了")}}},I=(a,e)=>{const n=a.__vccOpts||a;for(const[s,o]of e)n[s]=o;return n},q={key:0},W={class:"extra"},H={class:"gc_i18n_page"},J={style:{display:"flex"}};function F(a,e,n,s,o,i){const c=t.resolveComponent("Spin"),u=t.resolveComponent("Table"),g=t.resolveComponent("TabPane"),l=t.resolveComponent("Icon"),h=t.resolveComponent("Checkbox"),d=t.resolveComponent("DropdownItem"),y=t.resolveComponent("DropdownMenu"),_=t.resolveComponent("Dropdown"),V=t.resolveComponent("Input"),M=t.resolveComponent("Tabs"),ne=t.resolveComponent("Page"),R=t.resolveComponent("Button"),se=t.resolveComponent("Modal"),oe=t.resolveDirective("click-away");return t.openBlock(),t.createBlock(se,{modelValue:o.isModalVisible,"onUpdate:modelValue":e[4]||(e[4]=m=>o.isModalVisible=m),"mask-closable":!1,width:70,title:"多语言管理中心","footer-hide":"",onOnCancel:i.closeModal},{default:t.withCtx(()=>[o.isModalVisible?(t.openBlock(),t.createElementBlock("div",q,[t.createVNode(M,{modelValue:o.type,"onUpdate:modelValue":e[2]||(e[2]=m=>o.type=m),type:"card",class:"gc_i18n_tabs",onOnClick:i.changeTab},{extra:t.withCtx(()=>[t.createElementVNode("div",W,[t.withDirectives((t.openBlock(),t.createBlock(_,{style:{width:"80px"},transfer:"",trigger:"custom",placement:"bottom-start",visible:o.LanguageSettingVisible},{list:t.withCtx(()=>[t.createVNode(y,null,{default:t.withCtx(()=>[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(o.languages,m=>(t.openBlock(),t.createBlock(d,{key:m.code},{default:t.withCtx(()=>[t.createVNode(h,{modelValue:m.checked,"onUpdate:modelValue":ie=>m.checked=ie,onOnChange:i.saveLanguageSetting},{default:t.withCtx(()=>[t.createElementVNode("span",null,t.toDisplayString(m.name),1)]),_:2},1032,["modelValue","onUpdate:modelValue","onOnChange"])]),_:2},1024))),128))]),_:1})]),default:t.withCtx(()=>[t.createElementVNode("a",{href:"javascript:void(0)",onClick:e[0]||(e[0]=(...m)=>i.handleLanguageSettingOpen&&i.handleLanguageSettingOpen(...m))},[e[5]||(e[5]=t.createTextVNode(" 语言 ",-1)),t.createVNode(l,{type:"ios-arrow-down"})])]),_:1},8,["visible"])),[[oe,i.onClickOutside]]),t.createVNode(V,{class:"gc_i18n_search",prefix:"ios-search",placeholder:"请输入搜索内容",modelValue:o.searchText,"onUpdate:modelValue":e[1]||(e[1]=m=>o.searchText=m),clearable:"",onOnEnter:i.inputSearch,onOnClear:i.inputSearch},null,8,["modelValue","onOnEnter","onOnClear"])])]),default:t.withCtx(()=>[t.createVNode(g,{name:"pageData",label:"当前页面"},{default:t.withCtx(()=>[o.loading?(t.openBlock(),t.createBlock(c,{key:0,class:"gc_i18n_spin"})):(t.openBlock(),t.createBlock(u,{key:1,border:"",height:380,columns:i.columns,data:o.data},null,8,["columns","data"]))]),_:1}),t.createVNode(g,{name:"data",label:"当前应用"},{default:t.withCtx(()=>[o.loading?(t.openBlock(),t.createBlock(c,{key:0,class:"gc_i18n_spin"})):(t.openBlock(),t.createBlock(u,{key:1,border:"",height:380,columns:i.columns,data:o.data},null,8,["columns","data"]))]),_:1}),n.login?(t.openBlock(),t.createBlock(g,{key:0,name:"loginData",label:"登录页面"},{default:t.withCtx(()=>[o.loading?(t.openBlock(),t.createBlock(c,{key:0,class:"gc_i18n_spin"})):(t.openBlock(),t.createBlock(u,{key:1,border:"",height:380,columns:i.columns,data:o.data},null,8,["columns","data"]))]),_:1})):t.createCommentVNode("",!0)]),_:1},8,["modelValue","onOnClick"]),t.createElementVNode("div",H,[t.createElementVNode("div",J,[t.createVNode(ne,{modelValue:i.firstResult,"onUpdate:modelValue":e[3]||(e[3]=m=>i.firstResult=m),total:o.page.totalRows,"page-size":10,simple:"","show-total":"",onOnChange:i.changePage},null,8,["modelValue","total","onOnChange"]),t.createElementVNode("div",null,[t.createElementVNode("span",null," 共 "+t.toDisplayString(o.page.totalRows)+" 项当前页数据 ",1)])]),t.createElementVNode("div",null,[t.createVNode(R,{style:{"margin-right":"10px"},onClick:i.closeModal},{default:t.withCtx(()=>[...e[6]||(e[6]=[t.createTextVNode("关闭",-1)])]),_:1},8,["onClick"]),t.createVNode(R,{type:"primary",onClick:i.saveData},{default:t.withCtx(()=>[...e[7]||(e[7]=[t.createTextVNode("保存",-1)])]),_:1},8,["onClick"])])])])):t.createCommentVNode("",!0)]),_:1},8,["modelValue","onOnCancel"])}const Q=I(j,[["render",F],["__scopeId","data-v-1f438196"]]),v={},X={class:"earth"};function Y(a,e){const n=t.resolveComponent("Input"),s=t.resolveComponent("Icon");return t.openBlock(),t.createElementBlock("div",X,[t.createVNode(n,{class:"input"}),t.createVNode(s,{class:"icon",type:"ios-globe",size:"20"})])}const Z=I(v,[["render",Y]]);function b(a){const e=[],n=/(?:\$t|_ctx\.\$t)\s*\(\s*(['"])([^'"]+?)\1/gs;if(a.template){let s;for(;(s=n.exec(a.template))!==null;)e.push(s[2])}if(a.render){const s=a.render.toString();let o;for(;(o=n.exec(s))!==null;)e.push(o[2])}if(a.setup){const s=a.setup.toString();let o;for(;(o=n.exec(s))!==null;)e.push(o[2])}if(a.methods)for(const s in a.methods){const o=a.methods[s].toString();let i;for(;(i=n.exec(o))!==null;)e.push(i[2])}if(a.components)for(const s in a.components){const o=a.components[s];e.push(...b(o))}return[...new Set(e)]}function $(a){return{all:a=a||new Map,on:function(e,n){var s=a.get(e);s?s.push(n):a.set(e,[n])},off:function(e,n){var s=a.get(e);s&&(n?s.splice(s.indexOf(n)>>>0,1):a.set(e,[]))},emit:function(e,n){var s=a.get(e);s&&s.slice().map(function(o){o(n)}),(s=a.get("*"))&&s.slice().map(function(o){o(e,n)})}}}const L=function(){return document.ontouchstart!==null?"click":"touchstart"},w="__vue_click_away__",E=function(a,e,n){x(a);let s=n.context,o=e.value,i=!1;setTimeout(function(){i=!0},0),a[w]=function(c){if((!a||!a.contains(c.target))&&o&&i&&typeof o=="function")return o.call(s,c)},document.addEventListener(L(),a[w],!1)},x=function(a){document.removeEventListener(L(),a[w],!1),delete a[w]},ee=function(a,e,n){e.value!==e.oldValue&&E(a,e,n)},te={install:function(a){a.directive("click-away",ae)}},ae={mounted:E,updated:ee,unmounted:x};function O(a){const e={alg:"HS512"},n={orgCode:a},s=JSON.stringify(e),o=JSON.stringify(n);return U.jws.JWS.sign("HS512",s,o,"")}class k{constructor(e={}){const{router:n,appCode:s,messages:o,token:i,orgCode:c,loginRouteName:u,login:g,keyboard:l,locale:h}=e;this.token=i||O(c)||f.get("I18N_TOKEN"),this.loadI18n=!0,this.appCode=s,this.router=n,this.locale=h||f.get("I18N_LANGUAGE")||navigator.language||"zh-CN",this.name="",this.messages=o||{},this.translationKeys=[],this.translationKeySet=new Set,this.loginRouteName=u||"login",this.login=g,this.loginTranslationKeys=[],this.keyboard=l||"shift>t",this.baseUrl=e.dev?"https://test.ihotel.cn":"https://trans.ihotel.cn",this.initRouterGuards(),this.initI18n(e),C.bind(this.keyboard,d=>{!this.configInstance&&this.name!=this.loginRouteName&&(this.translationKeys=Array.from(this.translationKeySet),this.configInstance=this.createModal(this.name),this.configInstance.openModal({name:this.name}))}),this.setupLanguageChangeListener()}setupLanguageChangeListener(){"onlanguagechange"in window&&window.addEventListener("languagechange",()=>{const e=navigator.language;e!==this.locale&&this.setLanguage(e)})}initRouterGuards(){k._routerGuardRegistered||(k._routerGuardRegistered=!0,this.router.beforeEach(async(e,n,s)=>{var u,g;const{language:o,token:i}=e.query;this.configInstance&&this.configInstance.closeModal(),this.name=e.name,this.translationKeySet=new Set,i&&this.setToken(i),this.loadI18n&&await this.setLanguage(o||this.locale),this.loadI18n=!1;const c=this.router.getRoutes().find(l=>l.name===this.loginRouteName||l.path===`/${this.loginRouteName}`);if(c&&c.components){let l=(u=c.components)==null?void 0:u.default;if(typeof l=="function"&&l.toString().includes("import("))try{l=await l(),l=l.default}catch(d){console.error("加载异步组件时出错:",d),s();return}const h=b(l);this.loginTranslationKeys=h}if(e.matched.length>0)try{const l=[];for(const h of e.matched){let d=(g=h.components)==null?void 0:g.default;if(typeof d=="function"&&d.toString().includes("import(")&&(d=await d(),d=d.default),d){const y=b(d);l.push(...y)}}this.translationKeys=l}catch(l){console.error("加载异步组件时出错:",l),s();return}s()}),k._afterEachGuardRegistered||(k._afterEachGuardRegistered=!0,this.router.afterEach(async()=>{var o,i,c;await t.nextTick();const e=Array.from(this.translationKeySet),n=Array.from(new Set([...this.translationKeys||[],...e]));this.translationKeys=n,((c=(i=(o=this.router)==null?void 0:o.currentRoute)==null?void 0:i.value)==null?void 0:c.name)===this.loginRouteName&&(this.loginTranslationKeys=n)})))}initI18n(e){this.i18n=K.createI18n({locale:this.locale,allowComposition:!0,globalInjection:!0,legacy:!1,silentTranslationWarn:!0,silentFallbackWarn:!0,missingWarn:!1,fallbackWarn:!1,...e});const n=this.i18n.global.t;globalThis.$t=this.i18n.global.t=(s,o)=>{var c,u,g;typeof s=="string"&&this.translationKeySet.add(s);const i=(g=(u=(c=this.router)==null?void 0:c.currentRoute)==null?void 0:u.value)==null?void 0:g.name;if(i){const l=`${i}.${s}`,h=n(l);if(h!==l&&!r.isEmpty(h))return h;{const d=`common.${s}`,y=n(d);return y!==d?y:n(s,o)}}else return n(s,o)},globalThis.$i18nLogin=async s=>{this.setToken(O(s)),this.clearI18n(),await this.setLanguage(this.locale),location.reload()},globalThis.$i18nLogout=s=>{this.clearI18n(),location.reload()},globalThis.$deepScan=function(s){return s},globalThis.$clearI18n=this.clearI18n=()=>{f.namespace(`I18N_${r.toUpper(this.appCode)}`).clearAll()},globalThis.$changeLocale=this.changeLocale=this.i18n.global.changeLocale=async s=>{await this.setLanguage(s||this.locale)}}setToken(e){this.token=e,f.set("I18N_TOKEN",e)}async getLanguages(e=!1){const n=f.get("I18N_LANGUAGES");if(n&&!e)return n;{const s=await D({baseUrl:this.baseUrl,appCode:this.appCode,token:this.token});if(s.data){const o=r.get(s.data,"retVal");return f.set("I18N_LANGUAGES",o),o}}}async setLanguage(e="zh-CN"){const n="I18N_MESSAGES_COMMON_"+e;let s=f.get(n);if(console.log("commonMessages",s),r.isEmpty(s)){const o=await N.get(`https://cdn.ihotel.cn/i18n_messages/${e}.json`);if(console.log("lang",o),o){const{data:i}=o;s=i,f.set(n,i)}}return new Promise(async(o,i)=>{const c=await z({baseUrl:this.baseUrl,appCode:this.appCode,language:e||this.locale,token:this.token,routerName:this.name});if(c){const u=B(c),g=r.assign({},s,r.get(this.messages,e),u);this.i18n.global.setLocaleMessage(e,g)}this.locale=e,this.i18n.global.locale.value=e,f.set("I18N_LANGUAGE",e),o(!0)})}createModal(e){const n=$();return n.on("closeModal",s=>{this.configInstance=null}),t.createApp(Q,{appCode:this.appCode,router:this.router,token:this.token,setLanguage:this.setLanguage.bind(this,this.locale),name:e||this.name,translationKeys:this.translationKeys,loginRouteName:this.loginRouteName,loginTranslationKeys:this.loginTranslationKeys,login:this.login,baseUrl:this.baseUrl,emitter:n}).use(S).use(te).mount(document.createElement("div"))}install(e,n={}){e.use(S,{i18n:this.i18n}),e.use(this.i18n),e.component("i18n-earth",Z)}}p.I18n=k,p.default=k,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gc_i18n",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "type": "module",
5
5
  "main": "./lib/gc_i18n.umd.js",
6
6
  "module": "./lib/gc_i18n.es.js",
@@ -0,0 +1,24 @@
1
+ <template>
2
+ <div class="earth">
3
+ <Input class="input"></Input>
4
+ <Icon
5
+ class="icon"
6
+ type="ios-globe"
7
+ size="20"
8
+ />
9
+ </div>
10
+ </template>
11
+ <script setup></script>
12
+ <style lang="less">
13
+ .earth {
14
+ display: flex;
15
+ justify-content: center;
16
+ align-items: center;
17
+ .icon {
18
+ cursor: pointer;
19
+ }
20
+ .input {
21
+ margin-right: 5px;
22
+ }
23
+ }
24
+ </style>
package/packages/index.js CHANGED
@@ -4,6 +4,7 @@ import "view-ui-plus/dist/styles/viewuiplus.css";
4
4
  import { createApp, nextTick } from "vue";
5
5
  import { createI18n } from "vue-i18n";
6
6
  import configVue from "./components/config.vue";
7
+ import earthVue from "./components/earth.vue";
7
8
  import { getLanguages, getTranslate } from "./libs/service";
8
9
  import { convertArrayToObject } from "./libs/utils";
9
10
  import { extractTranslationKeys } from "./libs/i18nUtils";
@@ -12,6 +13,7 @@ import store2 from "store2";
12
13
  import mitt from "mitt";
13
14
  import { jws } from "jsrsasign";
14
15
  import VueClickAway from "vue3-click-away";
16
+ import axios from "axios";
15
17
 
16
18
  // 生成 JWT 的函数
17
19
  function generateJWT(orgCode) {
@@ -267,7 +269,22 @@ class I18n {
267
269
  }
268
270
  }
269
271
  }
270
- async setLanguage(language) {
272
+ async setLanguage(language = "zh-CN") {
273
+ const commonMessagesKey = "I18N_MESSAGES_COMMON_" + language;
274
+ let commonMessages = store2.get(commonMessagesKey);
275
+ console.log("commonMessages", commonMessages);
276
+ if (_.isEmpty(commonMessages)) {
277
+ const lang = await axios.get(
278
+ `https://cdn.ihotel.cn/i18n_messages/${language}.json`
279
+ );
280
+ console.log("lang", lang);
281
+ if (lang) {
282
+ const { data } = lang;
283
+ commonMessages = data;
284
+ store2.set(commonMessagesKey, data);
285
+ }
286
+ }
287
+
271
288
  return new Promise(async (resolve, reject) => {
272
289
  const res = await getTranslate({
273
290
  baseUrl: this.baseUrl,
@@ -280,6 +297,7 @@ class I18n {
280
297
  const remoteMessages = convertArrayToObject(res);
281
298
  const messages = _.assign(
282
299
  {},
300
+ commonMessages,
283
301
  _.get(this.messages, language),
284
302
  remoteMessages
285
303
  );
@@ -325,6 +343,8 @@ class I18n {
325
343
  i18n: this.i18n
326
344
  });
327
345
  app.use(this.i18n);
346
+ // 自动注册全局组件
347
+ app.component("i18n-earth", earthVue);
328
348
  }
329
349
  }
330
350
 
package/src/view/Home.vue CHANGED
@@ -20,12 +20,15 @@ const type = import.meta.env.MODE === "unit" ? "单位级 单位代码: dd" : "
20
20
 
21
21
  <div>首页</div>
22
22
  <RouterLink to="/test">测试</RouterLink>
23
+ 全局地球翻译<i18n-earth></i18n-earth>
23
24
  <h1>{{ $t("dsgljksdg") }}</h1>
24
25
  <button @click="change('en-US')">en</button>
25
26
  <button @click="change('zh-CN')">zh</button>
27
+ <button @click="change('zh-TW')">tw</button>
26
28
  <div>
27
29
  <button @click="clear">清理</button>
28
30
  <button @click="login">登录</button>
29
31
  <button @click="logout">登出</button>
32
+ <Table></Table>
30
33
  </div>
31
34
  </template>