agilebuilder-ui 1.0.71-tmp4 → 1.0.71-tmp7
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/package.json +1 -1
- package/src/permission.js +1 -1
- package/src/utils/common-util.js +74 -34
- package/src/utils/i18n-util.js +70 -41
package/package.json
CHANGED
package/src/permission.js
CHANGED
|
@@ -113,7 +113,7 @@ router.beforeEach((to, from, next) => {
|
|
|
113
113
|
if (to.query._systemName_) {
|
|
114
114
|
window.top.document.title = to.query._systemName_
|
|
115
115
|
}
|
|
116
|
-
if (to.query.customSystem) {
|
|
116
|
+
if (to.query.customSystem && to.query.customSystem !== 'undefined' && to.query.customSystem !== 'null') {
|
|
117
117
|
window.$vueApp.config.globalProperties.currentSystem = to.query.customSystem
|
|
118
118
|
}
|
|
119
119
|
// 表示需要设置浏览器页签名
|
package/src/utils/common-util.js
CHANGED
|
@@ -312,15 +312,7 @@ export function isMobileBrowser() {
|
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
export function getLocaleByLang(lang) {
|
|
315
|
-
|
|
316
|
-
if (lang && lang.indexOf('_') > 0) {
|
|
317
|
-
const language = lang.substring(0, lang.indexOf('_'))
|
|
318
|
-
locale = language
|
|
319
|
-
}
|
|
320
|
-
if (locale === 'zh') {
|
|
321
|
-
locale = 'cn'
|
|
322
|
-
}
|
|
323
|
-
return locale
|
|
315
|
+
return i18nUtil.getLocaleByLang(lang)
|
|
324
316
|
}
|
|
325
317
|
|
|
326
318
|
export function cacheLangs(langs) {
|
|
@@ -439,34 +431,74 @@ export function cacheCurrentLanguageUtil(http) {
|
|
|
439
431
|
const token = getToken()
|
|
440
432
|
if (token) {
|
|
441
433
|
const currentLanguage = getLanguage()
|
|
442
|
-
const systemCode =
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
if (url && enableI18n === 'true') {
|
|
447
|
-
// 表示需要加载国际化文件
|
|
448
|
-
loadLangFile(url, currentLanguage).then(() => {
|
|
449
|
-
resolve(currentLanguage)
|
|
450
|
-
})
|
|
451
|
-
} else {
|
|
434
|
+
const systemCode = getCurrentSystemCode()
|
|
435
|
+
if (isPlateSys(systemCode)) {
|
|
436
|
+
// 平台系统不需要加载国际化文件
|
|
437
|
+
if (currentLanguage && currentLanguage !== 'undefined') {
|
|
452
438
|
resolve(currentLanguage)
|
|
439
|
+
} else {
|
|
440
|
+
// 如果没有缓存当前用户的语言,则需要获取
|
|
441
|
+
const params = { systemCode: systemCode }
|
|
442
|
+
http
|
|
443
|
+
.post(window.$vueApp.config.globalProperties.baseAPI + '/acs/user/i18n-languages', params)
|
|
444
|
+
.then((langInfo) => {
|
|
445
|
+
resolve(langInfo.language ? langInfo.language : 'zh_CN')
|
|
446
|
+
})
|
|
447
|
+
.catch(() => {
|
|
448
|
+
resolve('zh_CN')
|
|
449
|
+
})
|
|
453
450
|
}
|
|
454
451
|
} else {
|
|
455
|
-
//
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
452
|
+
// 业务系统是否启用了国际化
|
|
453
|
+
const enableI18n = i18nUtil.getEnableI18nState(systemCode)
|
|
454
|
+
if (enableI18n === false && currentLanguage && currentLanguage !== 'undefined') {
|
|
455
|
+
// 如果没有开启国际化, 并且已经缓存了当前用户的语言,则直接返回
|
|
456
|
+
resolve(currentLanguage)
|
|
457
|
+
} else {
|
|
458
|
+
// 启用了国际化并且当前已经加载过了国际化json文件,则需要检查是否是最新的国际化文件
|
|
459
|
+
// 没有加载过国际化文件,则不用传递checkLastestI18nFile参数,后台会返回最新的国际化文件路径和用户当前语言
|
|
460
|
+
const url = i18nUtil.getLangFileUrl(systemCode, currentLanguage)
|
|
461
|
+
const params = { systemCode: systemCode }
|
|
462
|
+
if (url && currentLanguage && currentLanguage !== 'undefined' && enableI18n) {
|
|
463
|
+
params.checkLastestI18nFile = true
|
|
464
|
+
}
|
|
465
|
+
http
|
|
466
|
+
.post(window.$vueApp.config.globalProperties.baseAPI + '/acs/user/i18n-languages', params)
|
|
467
|
+
.then((langInfo) => {
|
|
468
|
+
if (langInfo.isLastestI18nFile) {
|
|
469
|
+
// 表示是最新的国际化文件,可以直接加载使用
|
|
470
|
+
i18nUtil
|
|
471
|
+
.loadLangFile(systemCode, url, currentLanguage)
|
|
472
|
+
.then(() => {
|
|
473
|
+
resolve(currentLanguage)
|
|
474
|
+
})
|
|
475
|
+
.catch(() => {
|
|
476
|
+
resolve(currentLanguage)
|
|
477
|
+
})
|
|
478
|
+
} else {
|
|
479
|
+
// 不是最新的国际化文件或者没有加载过国际化文件,则后端会返回最新的国际化文件路径和用户当前语言
|
|
480
|
+
i18nUtil.setEnableI18nState(systemCode, langInfo.enableI18n ? true : false)
|
|
481
|
+
if (langInfo.enableI18n && langInfo.i18nFileUrls[langInfo.language]) {
|
|
482
|
+
const url = langInfo.i18nFileUrls[langInfo.language] + '?_t_=' + new Date().getTime()
|
|
483
|
+
i18nUtil.setLangFileUrl(systemCode, langInfo.language, url)
|
|
484
|
+
i18nUtil
|
|
485
|
+
.loadLangFile(systemCode, url, langInfo.language)
|
|
486
|
+
.then(() => {
|
|
487
|
+
resolve(langInfo.language)
|
|
488
|
+
})
|
|
489
|
+
.catch(() => {
|
|
490
|
+
resolve(langInfo.language ? langInfo.language : 'zh_CN')
|
|
491
|
+
})
|
|
492
|
+
} else {
|
|
493
|
+
// 如果没有开启国际化
|
|
494
|
+
resolve(langInfo.language)
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
})
|
|
498
|
+
.catch(() => {
|
|
499
|
+
resolve('zh_CN')
|
|
500
|
+
})
|
|
501
|
+
}
|
|
470
502
|
}
|
|
471
503
|
} else {
|
|
472
504
|
// 默认是中文
|
|
@@ -589,3 +621,11 @@ export function formatFileName(fileName) {
|
|
|
589
621
|
}
|
|
590
622
|
return fileName
|
|
591
623
|
}
|
|
624
|
+
|
|
625
|
+
export function getCurrentSystemCode() {
|
|
626
|
+
if (window.$vueApp.config.globalProperties.currentSystem) {
|
|
627
|
+
return window.$vueApp.config.globalProperties.currentSystem
|
|
628
|
+
} else {
|
|
629
|
+
return window.$vueApp.config.globalProperties.systemCode
|
|
630
|
+
}
|
|
631
|
+
}
|
package/src/utils/i18n-util.js
CHANGED
|
@@ -1,28 +1,45 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
2
|
export function setLangFileUrl(systemCode, lang, url) {
|
|
3
|
-
|
|
3
|
+
let i18nFileUrlsItem = getLocalStorageJson('i18nFileUrls')
|
|
4
|
+
if (!i18nFileUrlsItem) {
|
|
5
|
+
i18nFileUrlsItem = {}
|
|
6
|
+
}
|
|
7
|
+
i18nFileUrlsItem[systemCode + '_' + lang] = url
|
|
8
|
+
window.localStorage.setItem('i18nFileUrls', JSON.stringify(i18nFileUrlsItem))
|
|
4
9
|
}
|
|
5
10
|
|
|
6
11
|
export function getLangFileUrl(systemCode, lang) {
|
|
7
|
-
|
|
12
|
+
const i18nFileUrlsItem = getLocalStorageJson('i18nFileUrls')
|
|
13
|
+
if (i18nFileUrlsItem) {
|
|
14
|
+
return i18nFileUrlsItem[systemCode + '_' + lang]
|
|
15
|
+
}
|
|
16
|
+
return null
|
|
8
17
|
}
|
|
9
18
|
|
|
10
19
|
export function removeLangFileUrl(systemCode, lang) {
|
|
11
|
-
|
|
20
|
+
const i18nFileUrlsItem = getLocalStorageJson('i18nFileUrls')
|
|
21
|
+
if (i18nFileUrlsItem) {
|
|
22
|
+
delete i18nFileUrlsItem[systemCode + '_' + lang]
|
|
23
|
+
window.localStorage.setItem('i18nFileUrls', JSON.stringify(i18nFileUrlsItem))
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function removeAllLangFileUrl(systemCode, lang) {
|
|
28
|
+
window.localStorage.removeItem('i18nFileUrls')
|
|
12
29
|
}
|
|
13
30
|
|
|
14
31
|
export function setEnableI18nState(systemCode, enableI18n) {
|
|
15
32
|
let allStateObj = {}
|
|
16
|
-
const allState =
|
|
33
|
+
const allState = getLocalStorageJson('enableI18nSystem')
|
|
17
34
|
if (allState) {
|
|
18
35
|
allStateObj = allState
|
|
19
36
|
}
|
|
20
37
|
allStateObj[systemCode] = enableI18n ? true : false
|
|
21
|
-
window.localStorage.setItem('
|
|
38
|
+
window.localStorage.setItem('enableI18nSystem', JSON.stringify(allStateObj))
|
|
22
39
|
}
|
|
23
40
|
|
|
24
41
|
export function getEnableI18nState(systemCode) {
|
|
25
|
-
const allState = getLocalStorageJson('
|
|
42
|
+
const allState = getLocalStorageJson('enableI18nSystem')
|
|
26
43
|
if (allState) {
|
|
27
44
|
return allState[systemCode]
|
|
28
45
|
}
|
|
@@ -30,14 +47,14 @@ export function getEnableI18nState(systemCode) {
|
|
|
30
47
|
}
|
|
31
48
|
|
|
32
49
|
export function removeEnableI18nState() {
|
|
33
|
-
window.localStorage.removeItem('
|
|
50
|
+
window.localStorage.removeItem('enableI18nSystem')
|
|
34
51
|
}
|
|
35
52
|
|
|
36
53
|
export function removeEnableI18nWidthSystemCode() {
|
|
37
|
-
const allState = getLocalStorageJson('
|
|
54
|
+
const allState = getLocalStorageJson('enableI18nSystem')
|
|
38
55
|
if (allState) {
|
|
39
56
|
delete allState[getCurrentSystemCode()]
|
|
40
|
-
window.localStorage.setItem('
|
|
57
|
+
window.localStorage.setItem('enableI18nSystem', JSON.stringify(allState))
|
|
41
58
|
}
|
|
42
59
|
}
|
|
43
60
|
|
|
@@ -49,41 +66,53 @@ function getLocalStorageJson(key) {
|
|
|
49
66
|
return null
|
|
50
67
|
}
|
|
51
68
|
|
|
52
|
-
function getCurrentSystemCode() {
|
|
53
|
-
if (window.$vueApp.config.globalProperties.currentSystem) {
|
|
54
|
-
return window.$vueApp.config.globalProperties.currentSystem
|
|
55
|
-
} else {
|
|
56
|
-
return window.$vueApp.config.globalProperties.systemCode
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
69
|
function loadLangFile(systemCode, url, language) {
|
|
70
|
+
console.log('loadLangFile', systemCode, url, language)
|
|
61
71
|
return new Promise((resolve, reject) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
if (window.$i18n) {
|
|
73
|
+
axios
|
|
74
|
+
.get(url, {
|
|
75
|
+
withCredential: false
|
|
76
|
+
})
|
|
77
|
+
.then((response) => {
|
|
78
|
+
const lang = getLocaleByLang(language)
|
|
79
|
+
if (response && response.data) {
|
|
80
|
+
// 获取当前的国际化消息
|
|
81
|
+
const currentMessages = window.$i18n.global.getLocaleMessage(lang)
|
|
82
|
+
// 新的国际化消息
|
|
83
|
+
if (currentMessages[systemCode]) {
|
|
84
|
+
Object.assign(currentMessages[systemCode], response.data)
|
|
85
|
+
} else {
|
|
86
|
+
currentMessages[systemCode] = response.data
|
|
87
|
+
}
|
|
88
|
+
// 设置合并后的国际化消息
|
|
89
|
+
window.$i18n.global.setLocaleMessage(lang, currentMessages)
|
|
76
90
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
})
|
|
91
|
+
resolve()
|
|
92
|
+
})
|
|
93
|
+
.catch((error) => {
|
|
94
|
+
reject(error)
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
resolve()
|
|
85
98
|
})
|
|
86
99
|
}
|
|
100
|
+
export function getLocaleByLang(lang) {
|
|
101
|
+
let locale = 'cn'
|
|
102
|
+
if (lang && lang.indexOf('_') > 0) {
|
|
103
|
+
const language = lang.substring(0, lang.indexOf('_'))
|
|
104
|
+
locale = language
|
|
105
|
+
}
|
|
106
|
+
if (locale === 'zh') {
|
|
107
|
+
locale = 'cn'
|
|
108
|
+
}
|
|
109
|
+
return locale
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function clearI18nCache(lang) {
|
|
113
|
+
removeEnableI18nState()
|
|
114
|
+
removeAllLangFileUrl()
|
|
115
|
+
}
|
|
87
116
|
export default {
|
|
88
117
|
setLangFileUrl,
|
|
89
118
|
getLangFileUrl,
|
|
@@ -93,6 +122,6 @@ export default {
|
|
|
93
122
|
removeEnableI18nState,
|
|
94
123
|
removeEnableI18nWidthSystemCode,
|
|
95
124
|
getLocalStorageJson,
|
|
96
|
-
|
|
97
|
-
|
|
125
|
+
loadLangFile,
|
|
126
|
+
getLocaleByLang
|
|
98
127
|
}
|