agilebuilder-ui 1.0.71-tmp3 → 1.0.71-tmp4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agilebuilder-ui",
3
- "version": "1.0.71tmp3",
3
+ "version": "1.0.71tmp4",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./lib/super-ui.js",
@@ -34,6 +34,7 @@
34
34
  "vue": "3.3.4",
35
35
  "vue-i18n": "^9.5.0",
36
36
  "vue-router": "^4.2.5",
37
- "vuex": "^4.1.0"
37
+ "vuex": "^4.1.0",
38
+ "axios": "^1.5.1"
38
39
  }
39
40
  }
@@ -3,7 +3,7 @@ import authApi from './auth-api'
3
3
  import { getToken, getLanguage, getAllLanguages, setAllLanguages } from './auth'
4
4
  import { v4 as uuidv4 } from 'uuid'
5
5
  import { getCookieCache } from './auth'
6
-
6
+ import i18nUtil from './i18n-util'
7
7
  /**
8
8
  * 获得相对地址
9
9
  */
@@ -439,27 +439,33 @@ export function cacheCurrentLanguageUtil(http) {
439
439
  const token = getToken()
440
440
  if (token) {
441
441
  const currentLanguage = getLanguage()
442
- debugger
443
- if (
444
- currentLanguage &&
445
- currentLanguage !== 'undefined' &&
446
- getLangFileUrl(window.$vueApp.config.globalProperties.currentSystem, currentLanguage)
447
- ) {
448
- resolve(currentLanguage)
442
+ const systemCode = i18nUtil.getCurrentSystemCode()
443
+ const enableI18n = i18nUtil.getEnableI18nState(systemCode)
444
+ if (currentLanguage && currentLanguage !== 'undefined' && enableI18n) {
445
+ const url = i18nUtil.getLangFileUrl(systemCode, currentLanguage)
446
+ if (url && enableI18n === 'true') {
447
+ // 表示需要加载国际化文件
448
+ loadLangFile(url, currentLanguage).then(() => {
449
+ resolve(currentLanguage)
450
+ })
451
+ } else {
452
+ resolve(currentLanguage)
453
+ }
449
454
  } else {
450
455
  // http.get(window.$vueApp.config.globalProperties.baseAPI + '/acs/user-languages').then((currentLanguage) => {
451
456
  http
452
- .get(
453
- window.$vueApp.config.globalProperties.baseAPI +
454
- '/acs/user/i18n-languages?systemCode=' +
455
- window.$vueApp.config.globalProperties.currentSystem
456
- )
457
+ .get(window.$vueApp.config.globalProperties.baseAPI + '/acs/user/i18n-languages?systemCode=' + systemCode)
457
458
  .then((langInfo) => {
458
- debugger
459
- if (langInfo.i18nFileUrls && langInfo.i18nFileUrls[langInfo.language]) {
460
- window.$vueApp.config.globalProperties.$loadScript(langInfo.i18nFileUrls[langInfo.language])
459
+ i18nUtil.setEnableI18nState(systemCode, langInfo.enableI18n ? true : false)
460
+ if (langInfo.enableI18n && langInfo.i18nFileUrls[langInfo.language]) {
461
+ const url = langInfo.i18nFileUrls[langInfo.language] + '?_t_=' + new Date().getTime()
462
+ i18nUtil.setLangFileUrl(systemCode, langInfo.language, url)
463
+ i18nUtil.loadLangFile(url, langInfo.language).then(() => {
464
+ resolve(langInfo.language)
465
+ })
466
+ } else {
467
+ resolve(langInfo.language)
461
468
  }
462
- resolve(langInfo.language)
463
469
  })
464
470
  }
465
471
  } else {
@@ -583,10 +589,3 @@ export function formatFileName(fileName) {
583
589
  }
584
590
  return fileName
585
591
  }
586
- export function setLangFileUrl(systemCode, lang, url) {
587
- window.sessionStorage.setItem('langFileUrl_' + systemCode + '_' + lang, url)
588
- }
589
-
590
- export function getLangFileUrl(systemCode, lang) {
591
- return window.sessionStorage.getItem('langFileUrl_' + systemCode + '_' + lang)
592
- }
@@ -0,0 +1,98 @@
1
+ import axios from 'axios'
2
+ export function setLangFileUrl(systemCode, lang, url) {
3
+ window.localStorage.setItem('langFileUrl_' + systemCode + '_' + lang, url)
4
+ }
5
+
6
+ export function getLangFileUrl(systemCode, lang) {
7
+ return window.localStorage.getItem('langFileUrl_' + systemCode + '_' + lang)
8
+ }
9
+
10
+ export function removeLangFileUrl(systemCode, lang) {
11
+ return window.localStorage.removeItem('langFileUrl_' + systemCode + '_' + lang)
12
+ }
13
+
14
+ export function setEnableI18nState(systemCode, enableI18n) {
15
+ let allStateObj = {}
16
+ const allState = getEnableI18System()
17
+ if (allState) {
18
+ allStateObj = allState
19
+ }
20
+ allStateObj[systemCode] = enableI18n ? true : false
21
+ window.localStorage.setItem('enableI18System', JSON.stringify(allStateObj))
22
+ }
23
+
24
+ export function getEnableI18nState(systemCode) {
25
+ const allState = getLocalStorageJson('enableI18System')
26
+ if (allState) {
27
+ return allState[systemCode]
28
+ }
29
+ return null
30
+ }
31
+
32
+ export function removeEnableI18nState() {
33
+ window.localStorage.removeItem('enableI18System')
34
+ }
35
+
36
+ export function removeEnableI18nWidthSystemCode() {
37
+ const allState = getLocalStorageJson('enableI18System')
38
+ if (allState) {
39
+ delete allState[getCurrentSystemCode()]
40
+ window.localStorage.setItem('enableI18System', JSON.stringify(allState))
41
+ }
42
+ }
43
+
44
+ function getLocalStorageJson(key) {
45
+ const item = window.localStorage.getItem(key)
46
+ if (item) {
47
+ return JSON.parse(item)
48
+ }
49
+ return null
50
+ }
51
+
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
+ function loadLangFile(systemCode, url, language) {
61
+ return new Promise((resolve, reject) => {
62
+ axios
63
+ .get(url, {
64
+ withCredential: false
65
+ })
66
+ .then((response) => {
67
+ const lang = getLocaleByLang(language)
68
+ if (response && response.data) {
69
+ // 获取当前的国际化消息
70
+ const currentMessages = window.$i18n.global.getLocaleMessage(lang)
71
+ // 新的国际化消息
72
+ if (currentMessages[systemCode]) {
73
+ Object.assign(currentMessages[systemCode], response.data)
74
+ } else {
75
+ currentMessages[systemCode] = response.data
76
+ }
77
+ // 设置合并后的国际化消息
78
+ window.$i18n.global.setLocaleMessage(lang, currentMessages)
79
+ }
80
+ resolve()
81
+ })
82
+ .catch((error) => {
83
+ reject(error)
84
+ })
85
+ })
86
+ }
87
+ export default {
88
+ setLangFileUrl,
89
+ getLangFileUrl,
90
+ removeLangFileUrl,
91
+ setEnableI18nState,
92
+ getEnableI18nState,
93
+ removeEnableI18nState,
94
+ removeEnableI18nWidthSystemCode,
95
+ getLocalStorageJson,
96
+ getCurrentSystemCode,
97
+ loadLangFile
98
+ }