gc_i18n 1.3.1 → 1.3.2
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 +61 -3
- package/lib/gc_i18n.css +1 -0
- package/lib/gc_i18n.es.js +771 -0
- package/lib/gc_i18n.umd.js +1 -0
- package/package.json +9 -3
- package/packages/index.js +8 -1
- package/vite.config.js +2 -1
package/README.md
CHANGED
|
@@ -1,5 +1,63 @@
|
|
|
1
|
-
#
|
|
1
|
+
# gc_i18n
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
一个基于 Vue 3 和 Vite 的国际化解决方案库。
|
|
4
4
|
|
|
5
|
-
|
|
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/lib/gc_i18n.css
ADDED
|
@@ -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}
|
|
@@ -0,0 +1,771 @@
|
|
|
1
|
+
import './gc_i18n.css';
|
|
2
|
+
import J from "keyboardjs";
|
|
3
|
+
import K, { Message as w } from "view-ui-plus";
|
|
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";
|
|
7
|
+
import l from "lodash-es";
|
|
8
|
+
import N from "axios";
|
|
9
|
+
import _ from "store2";
|
|
10
|
+
import { jws as ee } from "jsrsasign";
|
|
11
|
+
const te = (t) => {
|
|
12
|
+
const e = {};
|
|
13
|
+
for (const a of t)
|
|
14
|
+
e[a.key] = a.value;
|
|
15
|
+
return e;
|
|
16
|
+
}, ae = (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 }) => N.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 N({
|
|
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
|
+
}), se = async ({ data: t, token: e, baseUrl: a }) => N({
|
|
46
|
+
url: a + "/i18n-web/kv_translate/userDicts",
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: {
|
|
49
|
+
Authorization: e
|
|
50
|
+
},
|
|
51
|
+
data: t
|
|
52
|
+
}), ne = async ({ data: t, token: e, baseUrl: a }) => N({
|
|
53
|
+
url: a + "/i18n-web/kv_translate/batch",
|
|
54
|
+
method: "POST",
|
|
55
|
+
data: t,
|
|
56
|
+
headers: {
|
|
57
|
+
Authorization: e
|
|
58
|
+
}
|
|
59
|
+
}), oe = 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 v = ae(
|
|
86
|
+
k,
|
|
87
|
+
u.translatesDTOs,
|
|
88
|
+
n
|
|
89
|
+
), C = {
|
|
90
|
+
lastPullDate: u.lastPullDate,
|
|
91
|
+
translatesDTOs: v
|
|
92
|
+
};
|
|
93
|
+
_.namespace(`I18N_${l.toUpper(e)}`).set(a, C, ":"), o(v);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}), ie = {
|
|
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(m("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
|
+
w.error({
|
|
240
|
+
content: "没有需要保存的数据"
|
|
241
|
+
});
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const s = await ne({
|
|
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 ? (w.success({
|
|
254
|
+
content: t || s.data.msg
|
|
255
|
+
}), this.setLanguage(), this.initialData = l.cloneDeep(this.data.datas), this.mySaveData = [], this.router.go(0)) : w.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 se({
|
|
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
|
+
w.error("获取语言失败,出错了");
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}, le = (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" }, ge = { style: { display: "flex" } };
|
|
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, {
|
|
336
|
+
modelValue: n.isModalVisible,
|
|
337
|
+
"onUpdate:modelValue": e[4] || (e[4] = (d) => n.isModalVisible = d),
|
|
338
|
+
"mask-closable": !1,
|
|
339
|
+
width: 70,
|
|
340
|
+
title: "多语言管理中心",
|
|
341
|
+
"footer-hide": "",
|
|
342
|
+
onOnCancel: o.closeModal
|
|
343
|
+
}, {
|
|
344
|
+
default: p(() => [
|
|
345
|
+
n.isModalVisible ? (f(), O("div", re, [
|
|
346
|
+
y(I, {
|
|
347
|
+
modelValue: n.type,
|
|
348
|
+
"onUpdate:modelValue": e[2] || (e[2] = (d) => n.type = d),
|
|
349
|
+
type: "card",
|
|
350
|
+
class: "gc_i18n_tabs",
|
|
351
|
+
onOnClick: o.changeTab
|
|
352
|
+
}, {
|
|
353
|
+
extra: p(() => [
|
|
354
|
+
b("div", ce, [
|
|
355
|
+
q((f(), S(v, {
|
|
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), O(Q, null, X(n.languages, (d) => (f(), S(u, {
|
|
366
|
+
key: d.code
|
|
367
|
+
}, {
|
|
368
|
+
default: p(() => [
|
|
369
|
+
y(c, {
|
|
370
|
+
modelValue: d.checked,
|
|
371
|
+
"onUpdate:modelValue": (H) => d.checked = H,
|
|
372
|
+
onOnChange: o.saveLanguageSetting
|
|
373
|
+
}, {
|
|
374
|
+
default: p(() => [
|
|
375
|
+
b("span", null, E(d.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] = (...d) => o.handleLanguageSettingOpen && o.handleLanguageSettingOpen(...d))
|
|
390
|
+
}, [
|
|
391
|
+
e[5] || (e[5] = L(" 语言 ", -1)),
|
|
392
|
+
y(i, { type: "ios-arrow-down" })
|
|
393
|
+
])
|
|
394
|
+
]),
|
|
395
|
+
_: 1
|
|
396
|
+
}, 8, ["visible"])), [
|
|
397
|
+
[W, 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] = (d) => n.searchText = d),
|
|
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
|
+
})) : U("", !0)
|
|
467
|
+
]),
|
|
468
|
+
_: 1
|
|
469
|
+
}, 8, ["modelValue", "onOnClick"]),
|
|
470
|
+
b("div", ue, [
|
|
471
|
+
b("div", ge, [
|
|
472
|
+
y(B, {
|
|
473
|
+
modelValue: o.firstResult,
|
|
474
|
+
"onUpdate:modelValue": e[3] || (e[3] = (d) => o.firstResult = d),
|
|
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, " 共 " + E(n.page.totalRows) + " 项当前页数据 ", 1)
|
|
483
|
+
])
|
|
484
|
+
]),
|
|
485
|
+
b("div", null, [
|
|
486
|
+
y(R, {
|
|
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(R, {
|
|
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
|
+
])) : U("", !0)
|
|
507
|
+
]),
|
|
508
|
+
_: 1
|
|
509
|
+
}, 8, ["modelValue", "onOnCancel"]);
|
|
510
|
+
}
|
|
511
|
+
const de = /* @__PURE__ */ le(ie, [["render", he], ["__scopeId", "data-v-1f438196"]]);
|
|
512
|
+
function V(t) {
|
|
513
|
+
const e = [], a = /(?:\$t|_ctx\.\$t)\s*\(\s*(['"])([^'"]+?)\1/gs;
|
|
514
|
+
if (t.template) {
|
|
515
|
+
let s;
|
|
516
|
+
for (; (s = a.exec(t.template)) !== null; )
|
|
517
|
+
e.push(s[2]);
|
|
518
|
+
}
|
|
519
|
+
if (t.render) {
|
|
520
|
+
const s = t.render.toString();
|
|
521
|
+
let n;
|
|
522
|
+
for (; (n = a.exec(s)) !== null; )
|
|
523
|
+
e.push(n[2]);
|
|
524
|
+
}
|
|
525
|
+
if (t.setup) {
|
|
526
|
+
const s = t.setup.toString();
|
|
527
|
+
let n;
|
|
528
|
+
for (; (n = a.exec(s)) !== null; )
|
|
529
|
+
e.push(n[2]);
|
|
530
|
+
}
|
|
531
|
+
if (t.methods)
|
|
532
|
+
for (const s in t.methods) {
|
|
533
|
+
const n = t.methods[s].toString();
|
|
534
|
+
let o;
|
|
535
|
+
for (; (o = a.exec(n)) !== null; )
|
|
536
|
+
e.push(o[2]);
|
|
537
|
+
}
|
|
538
|
+
if (t.components)
|
|
539
|
+
for (const s in t.components) {
|
|
540
|
+
const n = t.components[s];
|
|
541
|
+
e.push(...V(n));
|
|
542
|
+
}
|
|
543
|
+
return [...new Set(e)];
|
|
544
|
+
}
|
|
545
|
+
function me(t) {
|
|
546
|
+
return { all: t = t || /* @__PURE__ */ new Map(), on: function(e, a) {
|
|
547
|
+
var s = t.get(e);
|
|
548
|
+
s ? s.push(a) : t.set(e, [a]);
|
|
549
|
+
}, off: function(e, a) {
|
|
550
|
+
var s = t.get(e);
|
|
551
|
+
s && (a ? s.splice(s.indexOf(a) >>> 0, 1) : t.set(e, []));
|
|
552
|
+
}, emit: function(e, a) {
|
|
553
|
+
var s = t.get(e);
|
|
554
|
+
s && s.slice().map(function(n) {
|
|
555
|
+
n(a);
|
|
556
|
+
}), (s = t.get("*")) && s.slice().map(function(n) {
|
|
557
|
+
n(e, a);
|
|
558
|
+
});
|
|
559
|
+
} };
|
|
560
|
+
}
|
|
561
|
+
const G = function() {
|
|
562
|
+
return document.ontouchstart !== null ? "click" : "touchstart";
|
|
563
|
+
}, T = "__vue_click_away__", P = function(t, e, a) {
|
|
564
|
+
z(t);
|
|
565
|
+
let s = a.context, n = e.value, o = !1;
|
|
566
|
+
setTimeout(function() {
|
|
567
|
+
o = !0;
|
|
568
|
+
}, 0), t[T] = function(r) {
|
|
569
|
+
if ((!t || !t.contains(r.target)) && n && o && typeof n == "function")
|
|
570
|
+
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 = {
|
|
577
|
+
install: function(t) {
|
|
578
|
+
t.directive("click-away", ye);
|
|
579
|
+
}
|
|
580
|
+
}, ye = {
|
|
581
|
+
mounted: P,
|
|
582
|
+
updated: pe,
|
|
583
|
+
unmounted: z
|
|
584
|
+
};
|
|
585
|
+
function M(t) {
|
|
586
|
+
const e = {
|
|
587
|
+
alg: "HS512"
|
|
588
|
+
// 算法
|
|
589
|
+
}, a = {
|
|
590
|
+
orgCode: t
|
|
591
|
+
}, s = JSON.stringify(e), n = JSON.stringify(a);
|
|
592
|
+
return ee.JWS.sign("HS512", s, n, "");
|
|
593
|
+
}
|
|
594
|
+
class D {
|
|
595
|
+
constructor(e = {}) {
|
|
596
|
+
const {
|
|
597
|
+
router: a,
|
|
598
|
+
appCode: s,
|
|
599
|
+
messages: n,
|
|
600
|
+
token: o,
|
|
601
|
+
orgCode: r,
|
|
602
|
+
loginRouteName: h,
|
|
603
|
+
login: g,
|
|
604
|
+
keyboard: i,
|
|
605
|
+
locale: c
|
|
606
|
+
} = 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) => {
|
|
608
|
+
!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
|
+
}), this.setupLanguageChangeListener();
|
|
610
|
+
}
|
|
611
|
+
// 监听浏览器语言变化
|
|
612
|
+
setupLanguageChangeListener() {
|
|
613
|
+
"onlanguagechange" in window && window.addEventListener("languagechange", () => {
|
|
614
|
+
const e = navigator.language;
|
|
615
|
+
e !== this.locale && this.setLanguage(e);
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
// 初始化路由守卫
|
|
619
|
+
initRouterGuards() {
|
|
620
|
+
D._routerGuardRegistered || (D._routerGuardRegistered = !0, this.router.beforeEach(async (e, a, s) => {
|
|
621
|
+
var h, g;
|
|
622
|
+
const { language: n, token: o } = e.query;
|
|
623
|
+
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;
|
|
624
|
+
const r = this.router.getRoutes().find((i) => i.name === this.loginRouteName || i.path === `/${this.loginRouteName}`);
|
|
625
|
+
if (r && r.components) {
|
|
626
|
+
let i = (h = r.components) == null ? void 0 : h.default;
|
|
627
|
+
if (typeof i == "function" && i.toString().includes("import("))
|
|
628
|
+
try {
|
|
629
|
+
i = await i(), i = i.default;
|
|
630
|
+
} catch (u) {
|
|
631
|
+
console.error("加载异步组件时出错:", u), s();
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
const c = V(i);
|
|
635
|
+
this.loginTranslationKeys = c;
|
|
636
|
+
}
|
|
637
|
+
if (e.matched.length > 0)
|
|
638
|
+
try {
|
|
639
|
+
const i = [];
|
|
640
|
+
for (const c of e.matched) {
|
|
641
|
+
let u = (g = c.components) == null ? void 0 : g.default;
|
|
642
|
+
if (typeof u == "function" && u.toString().includes("import(") && (u = await u(), u = u.default), u) {
|
|
643
|
+
const k = V(u);
|
|
644
|
+
i.push(...k);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
this.translationKeys = i;
|
|
648
|
+
} catch (i) {
|
|
649
|
+
console.error("加载异步组件时出错:", i), s();
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
s();
|
|
653
|
+
}), D._afterEachGuardRegistered || (D._afterEachGuardRegistered = !0, this.router.afterEach(async () => {
|
|
654
|
+
var n, o, r;
|
|
655
|
+
await Y();
|
|
656
|
+
const e = Array.from(this.translationKeySet), a = Array.from(
|
|
657
|
+
/* @__PURE__ */ new Set([...this.translationKeys || [], ...e])
|
|
658
|
+
);
|
|
659
|
+
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);
|
|
660
|
+
})));
|
|
661
|
+
}
|
|
662
|
+
// 初始化 i18n 实例
|
|
663
|
+
initI18n(e) {
|
|
664
|
+
this.i18n = $({
|
|
665
|
+
locale: this.locale,
|
|
666
|
+
allowComposition: !0,
|
|
667
|
+
globalInjection: !0,
|
|
668
|
+
legacy: !1,
|
|
669
|
+
silentTranslationWarn: !0,
|
|
670
|
+
silentFallbackWarn: !0,
|
|
671
|
+
missingWarn: !1,
|
|
672
|
+
fallbackWarn: !1,
|
|
673
|
+
...e
|
|
674
|
+
});
|
|
675
|
+
const a = this.i18n.global.t;
|
|
676
|
+
globalThis.$t = this.i18n.global.t = (s, n) => {
|
|
677
|
+
var r, h, g;
|
|
678
|
+
typeof s == "string" && this.translationKeySet.add(s);
|
|
679
|
+
const o = (g = (h = (r = this.router) == null ? void 0 : r.currentRoute) == null ? void 0 : h.value) == null ? void 0 : g.name;
|
|
680
|
+
if (o) {
|
|
681
|
+
const i = `${o}.${s}`, c = a(i);
|
|
682
|
+
if (c !== i && !l.isEmpty(c))
|
|
683
|
+
return c;
|
|
684
|
+
{
|
|
685
|
+
const u = `common.${s}`, k = a(u);
|
|
686
|
+
return k !== u ? k : a(s, n);
|
|
687
|
+
}
|
|
688
|
+
} else
|
|
689
|
+
return a(s, n);
|
|
690
|
+
}, globalThis.$i18nLogin = async (s) => {
|
|
691
|
+
this.setToken(M(s)), this.clearI18n(), await this.setLanguage(this.locale), location.reload();
|
|
692
|
+
}, globalThis.$i18nLogout = (s) => {
|
|
693
|
+
this.clearI18n(), location.reload();
|
|
694
|
+
}, globalThis.$deepScan = function(s) {
|
|
695
|
+
return s;
|
|
696
|
+
}, globalThis.$clearI18n = this.clearI18n = () => {
|
|
697
|
+
_.namespace(`I18N_${l.toUpper(this.appCode)}`).clearAll();
|
|
698
|
+
}, globalThis.$changeLocale = this.changeLocale = this.i18n.global.changeLocale = async (s) => {
|
|
699
|
+
await this.setLanguage(s || this.locale);
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
setToken(e) {
|
|
703
|
+
this.token = e, _.set("I18N_TOKEN", e);
|
|
704
|
+
}
|
|
705
|
+
async getLanguages(e = !1) {
|
|
706
|
+
const a = _.get("I18N_LANGUAGES");
|
|
707
|
+
if (a && !e)
|
|
708
|
+
return a;
|
|
709
|
+
{
|
|
710
|
+
const s = await A({
|
|
711
|
+
baseUrl: this.baseUrl,
|
|
712
|
+
appCode: this.appCode,
|
|
713
|
+
token: this.token
|
|
714
|
+
});
|
|
715
|
+
if (s.data) {
|
|
716
|
+
const n = l.get(s.data, "retVal");
|
|
717
|
+
return _.set("I18N_LANGUAGES", n), n;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
async setLanguage(e) {
|
|
722
|
+
return new Promise(async (a, s) => {
|
|
723
|
+
const n = await oe({
|
|
724
|
+
baseUrl: this.baseUrl,
|
|
725
|
+
appCode: this.appCode,
|
|
726
|
+
language: e || this.locale,
|
|
727
|
+
token: this.token,
|
|
728
|
+
routerName: this.name
|
|
729
|
+
});
|
|
730
|
+
if (n) {
|
|
731
|
+
const o = te(n), r = l.assign(
|
|
732
|
+
{},
|
|
733
|
+
l.get(this.messages, e),
|
|
734
|
+
o
|
|
735
|
+
);
|
|
736
|
+
this.i18n.global.setLocaleMessage(e, r);
|
|
737
|
+
}
|
|
738
|
+
this.locale = e, this.i18n.global.locale.value = e, _.set("I18N_LANGUAGE", e), a(!0);
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
createModal(e) {
|
|
742
|
+
const a = me();
|
|
743
|
+
return a.on("closeModal", (s) => {
|
|
744
|
+
this.configInstance = null;
|
|
745
|
+
}), Z(de, {
|
|
746
|
+
appCode: this.appCode,
|
|
747
|
+
router: this.router,
|
|
748
|
+
token: this.token,
|
|
749
|
+
setLanguage: this.setLanguage.bind(this, this.locale),
|
|
750
|
+
name: e || this.name,
|
|
751
|
+
translationKeys: this.translationKeys,
|
|
752
|
+
loginRouteName: this.loginRouteName,
|
|
753
|
+
// 登录页路由名称
|
|
754
|
+
loginTranslationKeys: this.loginTranslationKeys,
|
|
755
|
+
login: this.login,
|
|
756
|
+
baseUrl: this.baseUrl,
|
|
757
|
+
// 基础URL
|
|
758
|
+
emitter: a
|
|
759
|
+
// 将事件总线作为 prop 传递
|
|
760
|
+
}).use(K).use(fe).mount(document.createElement("div"));
|
|
761
|
+
}
|
|
762
|
+
install(e, a = {}) {
|
|
763
|
+
e.use(K, {
|
|
764
|
+
i18n: this.i18n
|
|
765
|
+
}), e.use(this.i18n);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
export {
|
|
769
|
+
D as I18n,
|
|
770
|
+
D as default
|
|
771
|
+
};
|
|
@@ -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,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"}})}));
|
package/package.json
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gc_i18n",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "./lib/gc_i18n.umd.
|
|
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",
|
package/packages/index.js
CHANGED
|
@@ -27,7 +27,8 @@ function generateJWT(orgCode) {
|
|
|
27
27
|
// 同步生成 JWT
|
|
28
28
|
return jws.JWS.sign("HS512", sHeader, sPayload, secret);
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
|
|
31
|
+
class I18n {
|
|
31
32
|
constructor(options = {}) {
|
|
32
33
|
const {
|
|
33
34
|
router,
|
|
@@ -326,3 +327,9 @@ export default class I18n {
|
|
|
326
327
|
app.use(this.i18n);
|
|
327
328
|
}
|
|
328
329
|
}
|
|
330
|
+
|
|
331
|
+
// 默认导出
|
|
332
|
+
export default I18n;
|
|
333
|
+
|
|
334
|
+
// 为了兼容不同的导入方式,同时提供命名导出
|
|
335
|
+
export { I18n };
|
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
|
-
|
|
16
|
+
formats: ["es", "umd"], // 明确指定构建格式
|
|
17
|
+
fileName: (format) => `gc_i18n.${format}.js`
|
|
17
18
|
},
|
|
18
19
|
|
|
19
20
|
rollupOptions: {
|