agilebuilder-ui 1.0.71-tmp2 → 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.71tmp2",
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
  }
package/src/index.js CHANGED
@@ -34,7 +34,6 @@ import { openPage } from './utils/jump-page-utils'
34
34
  // import SecretInfo from '../packages/secret-info'
35
35
  import plugins from '../packages/plugins/index'
36
36
  import permission from './directives/permission'
37
- import LoadScript from 'vue-plugin-load-script'
38
37
 
39
38
  // 定义 install 方法,接收 Vue 作为参数。如果使用 use 注册插件,则所有的组件都将被注册
40
39
  const install = function (Vue) {
@@ -42,7 +41,6 @@ const install = function (Vue) {
42
41
  permission.install(Vue)
43
42
  window.$vueApp.use(customPlugin)
44
43
  window.$vueApp.use(plugins)
45
- window.$vueApp.use(LoadScript)
46
44
  if (install.installed) return
47
45
  // components.map(component => Vue.component(component.name, component))
48
46
  // components.forEach(component => {
@@ -91,5 +89,5 @@ if (typeof window !== 'undefined' && window.Vue) {
91
89
 
92
90
  export default {
93
91
  // 导出的对象必须具有 install,才能被 Vue.use() 方法安装
94
- install
92
+ install,
95
93
  }
@@ -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
  */
@@ -435,32 +435,37 @@ export function windowOpenUrl(url, projectModel) {
435
435
 
436
436
  // 首次加载业务系统时,缓存当前用户语言
437
437
  export function cacheCurrentLanguageUtil(http) {
438
- const that = this
439
438
  return new Promise((resolve, reject) => {
440
439
  const token = getToken()
441
440
  if (token) {
442
441
  const currentLanguage = getLanguage()
443
- debugger
444
- if (
445
- currentLanguage &&
446
- currentLanguage !== 'undefined' &&
447
- getLangFileUrl(window.$vueApp.config.globalProperties.currentSystem, currentLanguage)
448
- ) {
449
- 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
+ }
450
454
  } else {
451
455
  // http.get(window.$vueApp.config.globalProperties.baseAPI + '/acs/user-languages').then((currentLanguage) => {
452
456
  http
453
- .get(
454
- window.$vueApp.config.globalProperties.baseAPI +
455
- '/acs/user/i18n-languages?systemCode=' +
456
- window.$vueApp.config.globalProperties.currentSystem
457
- )
457
+ .get(window.$vueApp.config.globalProperties.baseAPI + '/acs/user/i18n-languages?systemCode=' + systemCode)
458
458
  .then((langInfo) => {
459
- debugger
460
- if (langInfo.i18nFileUrls && langInfo.i18nFileUrls[langInfo.language]) {
461
- that.$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)
462
468
  }
463
- resolve(langInfo.language)
464
469
  })
465
470
  }
466
471
  } else {
@@ -584,10 +589,3 @@ export function formatFileName(fileName) {
584
589
  }
585
590
  return fileName
586
591
  }
587
- export function setLangFileUrl(systemCode, lang, url) {
588
- window.sessionStorage.setItem('langFileUrl_' + systemCode + '_' + lang, url)
589
- }
590
-
591
- export function getLangFileUrl(systemCode, lang) {
592
- return window.sessionStorage.getItem('langFileUrl_' + systemCode + '_' + lang)
593
- }
@@ -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
+ }