gc_i18n 1.3.1 → 1.3.3

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/README.md CHANGED
@@ -1,5 +1,63 @@
1
- # Vue 3 + Vite
1
+ # gc_i18n
2
2
 
3
- This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
3
+ 一个基于 Vue 3 Vite 的国际化解决方案库。
4
4
 
5
- Learn more about IDE Support for Vue in the [Vue Docs Scaling up Guide](https://vuejs.org/guide/scaling-up/tooling.html#ide-support).
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install gc_i18n
9
+ ```
10
+
11
+ ## 使用
12
+
13
+ ```javascript
14
+ import lang from 'gc_i18n';
15
+
16
+ const app = createApp(App);
17
+ app.use(lang, router);
18
+ app.mount('#app');
19
+ ```
20
+
21
+ ## Node.js 版本兼容性说明
22
+
23
+ 本库支持 Node.js 16.0.0 及以上版本。在低版本 Node.js 环境中使用时,请注意以下几点:
24
+
25
+ 1. 本库同时提供 ESM 和 UMD 两种模块格式的构建产物
26
+ 2. 在 package.json 中明确指定了 `exports` 字段以提高模块解析兼容性
27
+ 3. 如果在 Node.js 16.0.0 环境中遇到模块解析错误,请尝试以下解决方案:
28
+
29
+ ### 解决方案 1:升级 Node.js 版本(推荐)
30
+ 建议将 Node.js 升级到 18.x 或更高版本以获得更好的 ES 模块支持。
31
+
32
+ ### 解决方案 2:使用 require 方式导入
33
+ 如果必须使用 Node.js 16.0.0,可以尝试使用 CommonJS 方式导入:
34
+
35
+ ```javascript
36
+ const lang = require('gc_i18n');
37
+ ```
38
+
39
+ ### 解决方案 3:检查 Vite 配置
40
+ 确保你的 Vite 配置正确处理了模块解析:
41
+
42
+ ```javascript
43
+ // vite.config.js
44
+ export default defineConfig({
45
+ resolve: {
46
+ alias: {
47
+ 'gc_i18n': 'gc_i18n/lib/gc_i18n.umd.cjs'
48
+ }
49
+ }
50
+ });
51
+ ```
52
+
53
+ ## 构建
54
+
55
+ ```bash
56
+ npm run build
57
+ ```
58
+
59
+ ## 开发
60
+
61
+ ```bash
62
+ npm run dev
63
+ ```
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
  }
@@ -0,0 +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}.earth{display:flex;justify-content:center;align-items:center}.earth .icon{cursor:pointer}.earth .input{margin-right:5px}
@@ -0,0 +1,791 @@
1
+ import './gc_i18n.css';
2
+ import F from "keyboardjs";
3
+ import R, { Message as T } from "view-ui-plus";
4
+ import "view-ui-plus/dist/styles/viewuiplus.css";
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
+ import l from "lodash-es";
8
+ import D from "axios";
9
+ import _ from "store2";
10
+ import { jws as te } from "jsrsasign";
11
+ const ae = (t) => {
12
+ const e = {};
13
+ for (const a of t)
14
+ e[a.key] = a.value;
15
+ return e;
16
+ }, se = (t, e, a) => (e.forEach((s) => {
17
+ console.log("obj2.key ", s.key);
18
+ const n = s.key.split(".");
19
+ n[0] === "common" && l.find(t, { key: `${a}.${n[1]}` }) && l.remove(t, { key: `${a}.${n[1]}` });
20
+ const o = l.find(t, { key: s.key });
21
+ o ? l.merge(o, s) : t.push(s);
22
+ }), t), A = async ({ baseUrl: t, token: e }) => D.get(t + "/i18n-web/sysoption/getsupportedlangs", {
23
+ headers: {
24
+ Authorization: e
25
+ }
26
+ }), x = async ({
27
+ appCode: t,
28
+ language: e = "zh-CN",
29
+ page: a,
30
+ lastPullDate: s,
31
+ baseUrl: n,
32
+ token: o
33
+ }) => new Promise(async (r, h) => {
34
+ const g = n + "/i18n-web/kv_translate/kv_translates", i = s ? g + "?lastPullDate=" + s : g, c = await D({
35
+ url: i,
36
+ method: "GET",
37
+ headers: {
38
+ appCode: t,
39
+ page: a,
40
+ language: e,
41
+ Authorization: o
42
+ }
43
+ });
44
+ c.data && c.data.result == 0 ? r(c.data.retVal) : r(c);
45
+ }), ne = async ({ data: t, token: e, baseUrl: a }) => D({
46
+ url: a + "/i18n-web/kv_translate/userDicts",
47
+ method: "POST",
48
+ headers: {
49
+ Authorization: e
50
+ },
51
+ data: t
52
+ }), oe = async ({ data: t, token: e, baseUrl: a }) => D({
53
+ url: a + "/i18n-web/kv_translate/batch",
54
+ method: "POST",
55
+ data: t,
56
+ headers: {
57
+ Authorization: e
58
+ }
59
+ }), ie = async ({
60
+ baseUrl: t,
61
+ appCode: e,
62
+ language: a = "zh-CN",
63
+ token: s,
64
+ routerName: n
65
+ }) => new Promise(async (o, r) => {
66
+ const h = _.namespace(`I18N_${l.toUpper(e)}`), g = {
67
+ baseUrl: t,
68
+ appCode: e,
69
+ language: a,
70
+ token: s
71
+ }, i = h.get(a);
72
+ if (!i || !i.lastPullDate) {
73
+ const c = await x(g);
74
+ c && (h.set(a, c), o(c.translatesDTOs));
75
+ } else {
76
+ const { lastPullDate: c } = i, u = await x({
77
+ ...g,
78
+ lastPullDate: c
79
+ });
80
+ if (u) {
81
+ const k = l.get(i, "translatesDTOs");
82
+ if (l.isEmpty(u.translatesDTOs))
83
+ o(k);
84
+ else {
85
+ const w = se(
86
+ k,
87
+ u.translatesDTOs,
88
+ n
89
+ ), C = {
90
+ lastPullDate: u.lastPullDate,
91
+ translatesDTOs: w
92
+ };
93
+ _.namespace(`I18N_${l.toUpper(e)}`).set(a, C, ":"), o(w);
94
+ }
95
+ }
96
+ }
97
+ }), le = {
98
+ data() {
99
+ return {
100
+ LanguageSettingVisible: !1,
101
+ isModalVisible: !1,
102
+ loading: !1,
103
+ searchText: "",
104
+ name: "",
105
+ type: "pageData",
106
+ languages: [],
107
+ mySaveData: [],
108
+ pageData: [],
109
+ pageDataShow: [],
110
+ page: {
111
+ pageSize: 10,
112
+ firstResult: 0
113
+ },
114
+ data: []
115
+ };
116
+ },
117
+ computed: {
118
+ firstResult() {
119
+ return this.page.firstResult / this.page.pageSize + 1;
120
+ },
121
+ columns() {
122
+ let t = [
123
+ // {
124
+ // title: "状态",
125
+ // fixed: "left",
126
+ // width: 90,
127
+ // key: "page",
128
+ // render: (h, { row }) => {
129
+ // return h(
130
+ // "span",
131
+ // {},
132
+ // row.page === "common"
133
+ // ? "全局"
134
+ // : row.page === this.name
135
+ // ? "当前页"
136
+ // : "登录页"
137
+ // );
138
+ // }
139
+ // },
140
+ {
141
+ title: "关键词",
142
+ fixed: "left",
143
+ width: 110,
144
+ key: "dictKey"
145
+ }
146
+ ];
147
+ return l.map(this.languages, (e) => {
148
+ const a = e.code;
149
+ if (e.checked)
150
+ return t.push({
151
+ title: e.name,
152
+ key: a,
153
+ render: (s, {
154
+ row: n,
155
+ index: o
156
+ }) => {
157
+ const r = n[a], {
158
+ localhost: h
159
+ } = n;
160
+ return h ? null : y(d("Input"), {
161
+ modelValue: r,
162
+ onOnChange: (g) => {
163
+ const i = g.target.value, {
164
+ dictKey: c
165
+ } = n, u = l.findIndex(this.mySaveData, {
166
+ dictKey: c
167
+ });
168
+ u > -1 ? this.mySaveData[u][a] = i : this.mySaveData.push({
169
+ ...n,
170
+ [a]: i,
171
+ page: this.type === "loginData" ? this.loginRouteName : this.type === "pageData" ? this.name : "common"
172
+ });
173
+ }
174
+ }, null);
175
+ }
176
+ });
177
+ }), t;
178
+ }
179
+ },
180
+ props: {
181
+ appCode: String,
182
+ router: Object,
183
+ setLanguage: Function,
184
+ token: String,
185
+ baseUrl: String,
186
+ // 基础URL
187
+ translationKeys: Array,
188
+ loginRouteName: String,
189
+ // 登录页路由名称
190
+ loginTranslationKeys: Array,
191
+ // 登录页翻译键
192
+ login: {
193
+ type: Boolean,
194
+ default: !0
195
+ // 是否显示登录页翻译
196
+ },
197
+ emitter: Object
198
+ // 接收事件总线
199
+ },
200
+ methods: {
201
+ saveLanguageSetting(t) {
202
+ const e = l.map(l.filter(this.languages, (a) => a.checked), "code");
203
+ _.set("I18N_LANGUAGE_SETTING", e);
204
+ },
205
+ handleLanguageSettingOpen() {
206
+ this.LanguageSettingVisible = !this.LanguageSettingVisible;
207
+ },
208
+ onClickOutside() {
209
+ this.LanguageSettingVisible = !1;
210
+ },
211
+ inputSearch() {
212
+ this.type === "pageData" ? this.getPageData() : this.search();
213
+ },
214
+ closeModal() {
215
+ this.searchText = "", this.type = "pageData", this.isModalVisible = !1, this.emitter.emit("closeModal");
216
+ },
217
+ openModal({
218
+ name: t
219
+ }) {
220
+ this.isModalVisible || (this.isModalVisible = !0, this.name = t, this.init());
221
+ },
222
+ findShallowStringDiff(t) {
223
+ return l.find(t, ["_isEdit", !0]);
224
+ },
225
+ async saveData({
226
+ msg: t = "保存成功"
227
+ }, e = !0) {
228
+ const a = [];
229
+ if (l.map(this.mySaveData, (n) => {
230
+ l.map(this.languages, (o) => {
231
+ a.push({
232
+ key: n.dictKey,
233
+ page: n.page,
234
+ lang: o.code,
235
+ value: n[o.code]
236
+ });
237
+ });
238
+ }), l.isEmpty(a)) {
239
+ T.error({
240
+ content: "没有需要保存的数据"
241
+ });
242
+ return;
243
+ }
244
+ const s = await oe({
245
+ baseUrl: this.baseUrl,
246
+ data: {
247
+ appCode: this.appCode,
248
+ isLocal: "F",
249
+ data: a
250
+ },
251
+ token: this.token
252
+ });
253
+ s && s.data.result === 0 ? (T.success({
254
+ content: t || s.data.msg
255
+ }), this.setLanguage(), this.initialData = l.cloneDeep(this.data.datas), this.mySaveData = [], this.router.go(0)) : T.error({
256
+ content: s.data.msg || "保存失败"
257
+ });
258
+ },
259
+ async saveNoEqual() {
260
+ l.isEmpty(this.mySaveData) || this.saveData({
261
+ msg: "已为您自动保存"
262
+ }, !1);
263
+ },
264
+ changePage(t) {
265
+ this.saveNoEqual(), this.type === "pageData" ? this.getPageData({
266
+ firstResult: (t - 1) * this.page.pageSize
267
+ }) : this.search({
268
+ firstResult: (t - 1) * this.page.pageSize
269
+ });
270
+ },
271
+ async getPageData(t) {
272
+ this.search({
273
+ ...t,
274
+ commaSeparatedKeys: this.translationKeys.toString()
275
+ }, "pageData");
276
+ },
277
+ async getLoginData(t) {
278
+ this.search({
279
+ ...t,
280
+ page: this.loginRouteName,
281
+ commaSeparatedKeys: this.loginTranslationKeys.toString()
282
+ }, "pageData");
283
+ },
284
+ async search(t, e) {
285
+ this.loading = !0;
286
+ const a = await ne({
287
+ baseUrl: this.baseUrl,
288
+ data: {
289
+ appCode: this.appCode,
290
+ searchBlur: this.searchText,
291
+ commaSeparatedLangs: l.map(this.languages, "code").toString(),
292
+ page: e === "loginData" ? this.loginRouteName : e === "pageData" ? this.name : "common",
293
+ pageSize: 10,
294
+ ...t
295
+ },
296
+ token: this.token
297
+ });
298
+ if (a) {
299
+ this.initialData = l.cloneDeep(a.data.retVal.datas);
300
+ let s = a.data.retVal.datas;
301
+ this.data = l.cloneDeep(s), this.page = {
302
+ firstResult: a.data.retVal.firstResult,
303
+ pageSize: a.data.retVal.pageSize,
304
+ totalRows: a.data.retVal.totalRows
305
+ };
306
+ }
307
+ this.loading = !1;
308
+ },
309
+ changeTab(t) {
310
+ this.type = t, this.mySaveData = [], t === "data" ? this.search() : t === "pageData" ? this.getPageData() : t === "loginData" && this.getLoginData();
311
+ },
312
+ async init() {
313
+ let t = _.get("I18N_LANGUAGE_SETTING");
314
+ const e = await A({
315
+ token: this.token,
316
+ baseUrl: this.baseUrl
317
+ });
318
+ if (e && e.data.result == 0) {
319
+ let a = e.data.retVal;
320
+ l.isEmpty(t) && (t = ["zh-CN", "en-US", "zh-TW"]), l.map(a, (s) => {
321
+ l.includes(t, s.code) && (s.checked = !0);
322
+ }), this.languages = a, this.getPageData();
323
+ } else
324
+ T.error("获取语言失败,出错了");
325
+ }
326
+ }
327
+ }, G = (t, e) => {
328
+ const a = t.__vccOpts || t;
329
+ for (const [s, n] of e)
330
+ a[s] = n;
331
+ return a;
332
+ }, re = { key: 0 }, ce = { class: "extra" }, ue = { class: "gc_i18n_page" }, he = { style: { display: "flex" } };
333
+ function ge(t, e, a, s, n, o) {
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"), O = d("Tabs"), j = d("Page"), E = d("Button"), W = d("Modal"), H = q("click-away");
335
+ return f(), S(W, {
336
+ modelValue: n.isModalVisible,
337
+ "onUpdate:modelValue": e[4] || (e[4] = (m) => n.isModalVisible = m),
338
+ "mask-closable": !1,
339
+ width: 70,
340
+ title: "多语言管理中心",
341
+ "footer-hide": "",
342
+ onOnCancel: o.closeModal
343
+ }, {
344
+ default: p(() => [
345
+ n.isModalVisible ? (f(), I("div", re, [
346
+ y(O, {
347
+ modelValue: n.type,
348
+ "onUpdate:modelValue": e[2] || (e[2] = (m) => n.type = m),
349
+ type: "card",
350
+ class: "gc_i18n_tabs",
351
+ onOnClick: o.changeTab
352
+ }, {
353
+ extra: p(() => [
354
+ b("div", ce, [
355
+ Q((f(), S(w, {
356
+ style: { width: "80px" },
357
+ transfer: "",
358
+ trigger: "custom",
359
+ placement: "bottom-start",
360
+ visible: n.LanguageSettingVisible
361
+ }, {
362
+ list: p(() => [
363
+ y(k, null, {
364
+ default: p(() => [
365
+ (f(!0), I(X, null, Y(n.languages, (m) => (f(), S(u, {
366
+ key: m.code
367
+ }, {
368
+ default: p(() => [
369
+ y(c, {
370
+ modelValue: m.checked,
371
+ "onUpdate:modelValue": (J) => m.checked = J,
372
+ onOnChange: o.saveLanguageSetting
373
+ }, {
374
+ default: p(() => [
375
+ b("span", null, U(m.name), 1)
376
+ ]),
377
+ _: 2
378
+ }, 1032, ["modelValue", "onUpdate:modelValue", "onOnChange"])
379
+ ]),
380
+ _: 2
381
+ }, 1024))), 128))
382
+ ]),
383
+ _: 1
384
+ })
385
+ ]),
386
+ default: p(() => [
387
+ b("a", {
388
+ href: "javascript:void(0)",
389
+ onClick: e[0] || (e[0] = (...m) => o.handleLanguageSettingOpen && o.handleLanguageSettingOpen(...m))
390
+ }, [
391
+ e[5] || (e[5] = L(" 语言 ", -1)),
392
+ y(i, { type: "ios-arrow-down" })
393
+ ])
394
+ ]),
395
+ _: 1
396
+ }, 8, ["visible"])), [
397
+ [H, o.onClickOutside]
398
+ ]),
399
+ y(C, {
400
+ class: "gc_i18n_search",
401
+ prefix: "ios-search",
402
+ placeholder: "请输入搜索内容",
403
+ modelValue: n.searchText,
404
+ "onUpdate:modelValue": e[1] || (e[1] = (m) => n.searchText = m),
405
+ clearable: "",
406
+ onOnEnter: o.inputSearch,
407
+ onOnClear: o.inputSearch
408
+ }, null, 8, ["modelValue", "onOnEnter", "onOnClear"])
409
+ ])
410
+ ]),
411
+ default: p(() => [
412
+ y(g, {
413
+ name: "pageData",
414
+ label: "当前页面"
415
+ }, {
416
+ default: p(() => [
417
+ n.loading ? (f(), S(r, {
418
+ key: 0,
419
+ class: "gc_i18n_spin"
420
+ })) : (f(), S(h, {
421
+ key: 1,
422
+ border: "",
423
+ height: 380,
424
+ columns: o.columns,
425
+ data: n.data
426
+ }, null, 8, ["columns", "data"]))
427
+ ]),
428
+ _: 1
429
+ }),
430
+ y(g, {
431
+ name: "data",
432
+ label: "当前应用"
433
+ }, {
434
+ default: p(() => [
435
+ n.loading ? (f(), S(r, {
436
+ key: 0,
437
+ class: "gc_i18n_spin"
438
+ })) : (f(), S(h, {
439
+ key: 1,
440
+ border: "",
441
+ height: 380,
442
+ columns: o.columns,
443
+ data: n.data
444
+ }, null, 8, ["columns", "data"]))
445
+ ]),
446
+ _: 1
447
+ }),
448
+ a.login ? (f(), S(g, {
449
+ key: 0,
450
+ name: "loginData",
451
+ label: "登录页面"
452
+ }, {
453
+ default: p(() => [
454
+ n.loading ? (f(), S(r, {
455
+ key: 0,
456
+ class: "gc_i18n_spin"
457
+ })) : (f(), S(h, {
458
+ key: 1,
459
+ border: "",
460
+ height: 380,
461
+ columns: o.columns,
462
+ data: n.data
463
+ }, null, 8, ["columns", "data"]))
464
+ ]),
465
+ _: 1
466
+ })) : K("", !0)
467
+ ]),
468
+ _: 1
469
+ }, 8, ["modelValue", "onOnClick"]),
470
+ b("div", ue, [
471
+ b("div", he, [
472
+ y(j, {
473
+ modelValue: o.firstResult,
474
+ "onUpdate:modelValue": e[3] || (e[3] = (m) => o.firstResult = m),
475
+ total: n.page.totalRows,
476
+ "page-size": 10,
477
+ simple: "",
478
+ "show-total": "",
479
+ onOnChange: o.changePage
480
+ }, null, 8, ["modelValue", "total", "onOnChange"]),
481
+ b("div", null, [
482
+ b("span", null, " 共 " + U(n.page.totalRows) + " 项当前页数据 ", 1)
483
+ ])
484
+ ]),
485
+ b("div", null, [
486
+ y(E, {
487
+ style: { "margin-right": "10px" },
488
+ onClick: o.closeModal
489
+ }, {
490
+ default: p(() => [...e[6] || (e[6] = [
491
+ L("关闭", -1)
492
+ ])]),
493
+ _: 1
494
+ }, 8, ["onClick"]),
495
+ y(E, {
496
+ type: "primary",
497
+ onClick: o.saveData
498
+ }, {
499
+ default: p(() => [...e[7] || (e[7] = [
500
+ L("保存", -1)
501
+ ])]),
502
+ _: 1
503
+ }, 8, ["onClick"])
504
+ ])
505
+ ])
506
+ ])) : K("", !0)
507
+ ]),
508
+ _: 1
509
+ }, 8, ["modelValue", "onOnCancel"]);
510
+ }
511
+ const de = /* @__PURE__ */ G(le, [["render", ge], ["__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]]);
524
+ function V(t) {
525
+ const e = [], a = /(?:\$t|_ctx\.\$t)\s*\(\s*(['"])([^'"]+?)\1/gs;
526
+ if (t.template) {
527
+ let s;
528
+ for (; (s = a.exec(t.template)) !== null; )
529
+ e.push(s[2]);
530
+ }
531
+ if (t.render) {
532
+ const s = t.render.toString();
533
+ let n;
534
+ for (; (n = a.exec(s)) !== null; )
535
+ e.push(n[2]);
536
+ }
537
+ if (t.setup) {
538
+ const s = t.setup.toString();
539
+ let n;
540
+ for (; (n = a.exec(s)) !== null; )
541
+ e.push(n[2]);
542
+ }
543
+ if (t.methods)
544
+ for (const s in t.methods) {
545
+ const n = t.methods[s].toString();
546
+ let o;
547
+ for (; (o = a.exec(n)) !== null; )
548
+ e.push(o[2]);
549
+ }
550
+ if (t.components)
551
+ for (const s in t.components) {
552
+ const n = t.components[s];
553
+ e.push(...V(n));
554
+ }
555
+ return [...new Set(e)];
556
+ }
557
+ function _e(t) {
558
+ return { all: t = t || /* @__PURE__ */ new Map(), on: function(e, a) {
559
+ var s = t.get(e);
560
+ s ? s.push(a) : t.set(e, [a]);
561
+ }, off: function(e, a) {
562
+ var s = t.get(e);
563
+ s && (a ? s.splice(s.indexOf(a) >>> 0, 1) : t.set(e, []));
564
+ }, emit: function(e, a) {
565
+ var s = t.get(e);
566
+ s && s.slice().map(function(n) {
567
+ n(a);
568
+ }), (s = t.get("*")) && s.slice().map(function(n) {
569
+ n(e, a);
570
+ });
571
+ } };
572
+ }
573
+ const P = function() {
574
+ return document.ontouchstart !== null ? "click" : "touchstart";
575
+ }, N = "__vue_click_away__", z = function(t, e, a) {
576
+ B(t);
577
+ let s = a.context, n = e.value, o = !1;
578
+ setTimeout(function() {
579
+ o = !0;
580
+ }, 0), t[N] = function(r) {
581
+ if ((!t || !t.contains(r.target)) && n && o && typeof n == "function")
582
+ return n.call(s, r);
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 = {
589
+ install: function(t) {
590
+ t.directive("click-away", be);
591
+ }
592
+ }, be = {
593
+ mounted: z,
594
+ updated: Se,
595
+ unmounted: B
596
+ };
597
+ function M(t) {
598
+ const e = {
599
+ alg: "HS512"
600
+ // 算法
601
+ }, a = {
602
+ orgCode: t
603
+ }, s = JSON.stringify(e), n = JSON.stringify(a);
604
+ return te.JWS.sign("HS512", s, n, "");
605
+ }
606
+ class v {
607
+ constructor(e = {}) {
608
+ const {
609
+ router: a,
610
+ appCode: s,
611
+ messages: n,
612
+ token: o,
613
+ orgCode: r,
614
+ loginRouteName: h,
615
+ login: g,
616
+ keyboard: i,
617
+ locale: c
618
+ } = e;
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) => {
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 }));
621
+ }), this.setupLanguageChangeListener();
622
+ }
623
+ // 监听浏览器语言变化
624
+ setupLanguageChangeListener() {
625
+ "onlanguagechange" in window && window.addEventListener("languagechange", () => {
626
+ const e = navigator.language;
627
+ e !== this.locale && this.setLanguage(e);
628
+ });
629
+ }
630
+ // 初始化路由守卫
631
+ initRouterGuards() {
632
+ v._routerGuardRegistered || (v._routerGuardRegistered = !0, this.router.beforeEach(async (e, a, s) => {
633
+ var h, g;
634
+ const { language: n, token: o } = e.query;
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;
636
+ const r = this.router.getRoutes().find((i) => i.name === this.loginRouteName || i.path === `/${this.loginRouteName}`);
637
+ if (r && r.components) {
638
+ let i = (h = r.components) == null ? void 0 : h.default;
639
+ if (typeof i == "function" && i.toString().includes("import("))
640
+ try {
641
+ i = await i(), i = i.default;
642
+ } catch (u) {
643
+ console.error("加载异步组件时出错:", u), s();
644
+ return;
645
+ }
646
+ const c = V(i);
647
+ this.loginTranslationKeys = c;
648
+ }
649
+ if (e.matched.length > 0)
650
+ try {
651
+ const i = [];
652
+ for (const c of e.matched) {
653
+ let u = (g = c.components) == null ? void 0 : g.default;
654
+ if (typeof u == "function" && u.toString().includes("import(") && (u = await u(), u = u.default), u) {
655
+ const k = V(u);
656
+ i.push(...k);
657
+ }
658
+ }
659
+ this.translationKeys = i;
660
+ } catch (i) {
661
+ console.error("加载异步组件时出错:", i), s();
662
+ return;
663
+ }
664
+ s();
665
+ }), v._afterEachGuardRegistered || (v._afterEachGuardRegistered = !0, this.router.afterEach(async () => {
666
+ var n, o, r;
667
+ await Z();
668
+ const e = Array.from(this.translationKeySet), a = Array.from(
669
+ /* @__PURE__ */ new Set([...this.translationKeys || [], ...e])
670
+ );
671
+ this.translationKeys = a, ((r = (o = (n = this.router) == null ? void 0 : n.currentRoute) == null ? void 0 : o.value) == null ? void 0 : r.name) === this.loginRouteName && (this.loginTranslationKeys = a);
672
+ })));
673
+ }
674
+ // 初始化 i18n 实例
675
+ initI18n(e) {
676
+ this.i18n = ee({
677
+ locale: this.locale,
678
+ allowComposition: !0,
679
+ globalInjection: !0,
680
+ legacy: !1,
681
+ silentTranslationWarn: !0,
682
+ silentFallbackWarn: !0,
683
+ missingWarn: !1,
684
+ fallbackWarn: !1,
685
+ ...e
686
+ });
687
+ const a = this.i18n.global.t;
688
+ globalThis.$t = this.i18n.global.t = (s, n) => {
689
+ var r, h, g;
690
+ typeof s == "string" && this.translationKeySet.add(s);
691
+ const o = (g = (h = (r = this.router) == null ? void 0 : r.currentRoute) == null ? void 0 : h.value) == null ? void 0 : g.name;
692
+ if (o) {
693
+ const i = `${o}.${s}`, c = a(i);
694
+ if (c !== i && !l.isEmpty(c))
695
+ return c;
696
+ {
697
+ const u = `common.${s}`, k = a(u);
698
+ return k !== u ? k : a(s, n);
699
+ }
700
+ } else
701
+ return a(s, n);
702
+ }, globalThis.$i18nLogin = async (s) => {
703
+ this.setToken(M(s)), this.clearI18n(), await this.setLanguage(this.locale), location.reload();
704
+ }, globalThis.$i18nLogout = (s) => {
705
+ this.clearI18n(), location.reload();
706
+ }, globalThis.$deepScan = function(s) {
707
+ return s;
708
+ }, globalThis.$clearI18n = this.clearI18n = () => {
709
+ _.namespace(`I18N_${l.toUpper(this.appCode)}`).clearAll();
710
+ }, globalThis.$changeLocale = this.changeLocale = this.i18n.global.changeLocale = async (s) => {
711
+ await this.setLanguage(s || this.locale);
712
+ };
713
+ }
714
+ setToken(e) {
715
+ this.token = e, _.set("I18N_TOKEN", e);
716
+ }
717
+ async getLanguages(e = !1) {
718
+ const a = _.get("I18N_LANGUAGES");
719
+ if (a && !e)
720
+ return a;
721
+ {
722
+ const s = await A({
723
+ baseUrl: this.baseUrl,
724
+ appCode: this.appCode,
725
+ token: this.token
726
+ });
727
+ if (s.data) {
728
+ const n = l.get(s.data, "retVal");
729
+ return _.set("I18N_LANGUAGES", n), n;
730
+ }
731
+ }
732
+ }
733
+ async setLanguage(e) {
734
+ let a = _.get("I18N_MESSAGES_COMMON_" + e);
735
+ if (!a) {
736
+ const s = await D.get(
737
+ `https://cdn.ihotel.cn/i18n_messages/${e}.json`
738
+ ), { data: n } = s;
739
+ s.status === 200 && (a = n, _.set("I18N_MESSAGES_COMMON_" + e, n));
740
+ }
741
+ return new Promise(async (s, n) => {
742
+ const o = await ie({
743
+ baseUrl: this.baseUrl,
744
+ appCode: this.appCode,
745
+ language: e || this.locale,
746
+ token: this.token,
747
+ routerName: this.name
748
+ });
749
+ if (o) {
750
+ const r = ae(o), h = l.assign(
751
+ {},
752
+ a,
753
+ l.get(this.messages, e),
754
+ r
755
+ );
756
+ this.i18n.global.setLocaleMessage(e, h);
757
+ }
758
+ this.locale = e, this.i18n.global.locale.value = e, _.set("I18N_LANGUAGE", e), s(!0);
759
+ });
760
+ }
761
+ createModal(e) {
762
+ const a = _e();
763
+ return a.on("closeModal", (s) => {
764
+ this.configInstance = null;
765
+ }), $(de, {
766
+ appCode: this.appCode,
767
+ router: this.router,
768
+ token: this.token,
769
+ setLanguage: this.setLanguage.bind(this, this.locale),
770
+ name: e || this.name,
771
+ translationKeys: this.translationKeys,
772
+ loginRouteName: this.loginRouteName,
773
+ // 登录页路由名称
774
+ loginTranslationKeys: this.loginTranslationKeys,
775
+ login: this.login,
776
+ baseUrl: this.baseUrl,
777
+ // 基础URL
778
+ emitter: a
779
+ // 将事件总线作为 prop 传递
780
+ }).use(R).use(ke).mount(document.createElement("div"));
781
+ }
782
+ install(e, a = {}) {
783
+ e.use(R, {
784
+ i18n: this.i18n
785
+ }), e.use(this.i18n), e.component("i18n-earth", ye);
786
+ }
787
+ }
788
+ export {
789
+ v as I18n,
790
+ v as default
791
+ };
@@ -0,0 +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,le,t,K,r,_,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})=>_.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,g)=>{const u=o+"/i18n-web/kv_translate/kv_translates",l=s?u+"?lastPullDate="+s:u,h=await _({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})=>_({url:n+"/i18n-web/kv_translate/userDicts",method:"POST",headers:{Authorization:e},data:a}),P=async({data:a,token:e,baseUrl: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 g=f.namespace(`I18N_${r.toUpper(e)}`),u={baseUrl:a,appCode:e,language:n,token:s},l=g.get(n);if(!l||!l.lastPullDate){const h=await T(u);h&&(g.set(n,h),i(h.translatesDTOs))}else{const{lastPullDate:h}=l,d=await T({...u,lastPullDate:h});if(d){const y=r.get(l,"translatesDTOs");if(r.isEmpty(d.translatesDTOs))i(y);else{const w=A(y,d.translatesDTOs,o),V={lastPullDate:d.lastPullDate,translatesDTOs:w};f.namespace(`I18N_${r.toUpper(e)}`).set(n,V,":"),i(w)}}}}),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:g}=o;return g?null:t.createVNode(t.resolveComponent("Input"),{modelValue:c,onOnChange:u=>{const l=u.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"),g=t.resolveComponent("Table"),u=t.resolveComponent("TabPane"),l=t.resolveComponent("Icon"),h=t.resolveComponent("Checkbox"),d=t.resolveComponent("DropdownItem"),y=t.resolveComponent("DropdownMenu"),w=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(w,{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(u,{name:"pageData",label:"当前页面"},{default:t.withCtx(()=>[o.loading?(t.openBlock(),t.createBlock(c,{key:0,class:"gc_i18n_spin"})):(t.openBlock(),t.createBlock(g,{key:1,border:"",height:380,columns:i.columns,data:o.data},null,8,["columns","data"]))]),_:1}),t.createVNode(u,{name:"data",label:"当前应用"},{default:t.withCtx(()=>[o.loading?(t.openBlock(),t.createBlock(c,{key:0,class:"gc_i18n_spin"})):(t.openBlock(),t.createBlock(g,{key:1,border:"",height:380,columns:i.columns,data:o.data},null,8,["columns","data"]))]),_:1}),n.login?(t.openBlock(),t.createBlock(u,{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(g,{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 E=function(){return document.ontouchstart!==null?"click":"touchstart"},N="__vue_click_away__",L=function(a,e,n){x(a);let s=n.context,o=e.value,i=!1;setTimeout(function(){i=!0},0),a[N]=function(c){if((!a||!a.contains(c.target))&&o&&i&&typeof o=="function")return o.call(s,c)},document.addEventListener(E(),a[N],!1)},x=function(a){document.removeEventListener(E(),a[N],!1),delete a[N]},ee=function(a,e,n){e.value!==e.oldValue&&L(a,e,n)},te={install:function(a){a.directive("click-away",ae)}},ae={mounted:L,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:g,login:u,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=g||"login",this.login=u,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 g,u;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=(g=c.components)==null?void 0:g.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=(u=h.components)==null?void 0:u.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,g,u;typeof s=="string"&&this.translationKeySet.add(s);const i=(u=(g=(c=this.router)==null?void 0:c.currentRoute)==null?void 0:g.value)==null?void 0:u.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){let n=f.get("I18N_MESSAGES_COMMON_"+e);if(!n){const s=await _.get(`https://cdn.ihotel.cn/i18n_messages/${e}.json`),{data:o}=s;s.status===200&&(n=o,f.set("I18N_MESSAGES_COMMON_"+e,o))}return new Promise(async(s,o)=>{const i=await z({baseUrl:this.baseUrl,appCode:this.appCode,language:e||this.locale,token:this.token,routerName:this.name});if(i){const c=B(i),g=r.assign({},n,r.get(this.messages,e),c);this.i18n.global.setLocaleMessage(e,g)}this.locale=e,this.i18n.global.locale.value=e,f.set("I18N_LANGUAGE",e),s(!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,9 +1,15 @@
1
1
  {
2
2
  "name": "gc_i18n",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "type": "module",
5
- "main": "./lib/gc_i18n.umd.cjs",
6
- "module": "./lib/gc_i18n.js",
5
+ "main": "./lib/gc_i18n.umd.js",
6
+ "module": "./lib/gc_i18n.es.js",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./lib/gc_i18n.es.js",
10
+ "require": "./lib/gc_i18n.umd.js"
11
+ }
12
+ },
7
13
  "scripts": {
8
14
  "dev": "vite",
9
15
  "dev:unit": "vite --mode unit --port 8080",
@@ -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) {
@@ -27,7 +29,8 @@ function generateJWT(orgCode) {
27
29
  // 同步生成 JWT
28
30
  return jws.JWS.sign("HS512", sHeader, sPayload, secret);
29
31
  }
30
- export default class I18n {
32
+
33
+ class I18n {
31
34
  constructor(options = {}) {
32
35
  const {
33
36
  router,
@@ -267,6 +270,18 @@ export default class I18n {
267
270
  }
268
271
  }
269
272
  async setLanguage(language) {
273
+ let commonMessages = store2.get("I18N_MESSAGES_COMMON_" + language);
274
+ if (!commonMessages) {
275
+ const res = await axios.get(
276
+ `https://cdn.ihotel.cn/i18n_messages/${language}.json`
277
+ );
278
+ const { data } = res;
279
+ if (res.status === 200) {
280
+ commonMessages = data;
281
+ store2.set("I18N_MESSAGES_COMMON_" + language, data);
282
+ }
283
+ }
284
+
270
285
  return new Promise(async (resolve, reject) => {
271
286
  const res = await getTranslate({
272
287
  baseUrl: this.baseUrl,
@@ -279,6 +294,7 @@ export default class I18n {
279
294
  const remoteMessages = convertArrayToObject(res);
280
295
  const messages = _.assign(
281
296
  {},
297
+ commonMessages,
282
298
  _.get(this.messages, language),
283
299
  remoteMessages
284
300
  );
@@ -324,5 +340,13 @@ export default class I18n {
324
340
  i18n: this.i18n
325
341
  });
326
342
  app.use(this.i18n);
343
+ // 自动注册全局组件
344
+ app.component("i18n-earth", earthVue);
327
345
  }
328
346
  }
347
+
348
+ // 默认导出
349
+ export default I18n;
350
+
351
+ // 为了兼容不同的导入方式,同时提供命名导出
352
+ export { I18n };
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>
package/vite.config.js CHANGED
@@ -13,7 +13,8 @@ export default defineConfig({
13
13
  // Could also be a dictionary or array of multiple entry points
14
14
  entry: resolve(__dirname, "packages/index.js"),
15
15
  name: "gc_i18n",
16
- fileName: "gc_i18n"
16
+ formats: ["es", "umd"], // 明确指定构建格式
17
+ fileName: (format) => `gc_i18n.${format}.js`
17
18
  },
18
19
 
19
20
  rollupOptions: {