agilebuilder-ui 1.0.74-tmp1 → 1.0.74-tmp3

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.
@@ -2,7 +2,8 @@ import * as Vue from 'vue'
2
2
  import authApi from './auth-api'
3
3
  import { getToken, getLanguage, getAllLanguages, setAllLanguages } from './auth'
4
4
  import { v4 as uuidv4 } from 'uuid'
5
- import {getCookieCache} from './auth'
5
+ import { getCookieCache } from './auth'
6
+ import i18nUtil from './i18n-util'
6
7
  /**
7
8
  * 获得相对地址
8
9
  */
@@ -311,15 +312,7 @@ export function isMobileBrowser() {
311
312
  }
312
313
 
313
314
  export function getLocaleByLang(lang) {
314
- let locale = 'cn'
315
- if (lang && lang.indexOf('_') > 0) {
316
- const language = lang.substring(0, lang.indexOf('_'))
317
- locale = language
318
- }
319
- if (locale === 'zh') {
320
- locale = 'cn'
321
- }
322
- return locale
315
+ return i18nUtil.getLocaleByLang(lang)
323
316
  }
324
317
 
325
318
  export function cacheLangs(langs) {
@@ -436,21 +429,107 @@ export function windowOpenUrl(url, projectModel) {
436
429
  export function cacheCurrentLanguageUtil(http) {
437
430
  return new Promise((resolve, reject) => {
438
431
  const token = getToken()
439
- if (token) {
440
- const currentLanguage = getLanguage()
432
+ if (!token) {
433
+ // 默认是中文
434
+ resolve('zh_CN')
435
+ }
436
+ const currentLanguage = getLanguage()
437
+ const systemCode = getCurrentSystemCode()
438
+ if (isPlateSys(systemCode)) {
439
+ // 平台系统不需要加载国际化文件
441
440
  if (currentLanguage && currentLanguage !== 'undefined') {
442
441
  resolve(currentLanguage)
443
442
  } else {
444
- http.get(window.$vueApp.config.globalProperties.baseAPI + '/acs/user-languages').then((currentLanguage) => {
445
- resolve(currentLanguage)
446
- })
443
+ // 如果没有缓存当前用户的语言,则需要获取
444
+ const params = { systemCode: systemCode }
445
+ http
446
+ .post(window.$vueApp.config.globalProperties.baseAPI + '/acs/user/i18n-languages', params)
447
+ .then((langInfo) => {
448
+ resolve(langInfo.language ? langInfo.language : 'zh_CN')
449
+ })
450
+ .catch(() => {
451
+ resolve('zh_CN')
452
+ })
447
453
  }
448
454
  } else {
449
- // 默认是中文
450
- resolve('zh_CN')
455
+ // 业务系统是否启用了国际化
456
+ const enableI18n = i18nUtil.getEnableI18nState(systemCode)
457
+ if (enableI18n === false && currentLanguage && currentLanguage !== 'undefined') {
458
+ // 如果没有开启国际化, 并且已经缓存了当前用户的语言,则直接返回
459
+ resolve(currentLanguage)
460
+ } else {
461
+ // 启用了国际化并且当前已经加载过了国际化json文件,则需要检查是否是最新的国际化文件
462
+ // 没有加载过国际化文件,则不用传递checkLastestI18nFile参数,后台会返回最新的国际化文件路径和用户当前语言
463
+ let url = i18nUtil.getLangFileUrl(systemCode, currentLanguage)
464
+ const params = { systemCode: systemCode }
465
+ if (url && currentLanguage && currentLanguage !== 'undefined' && enableI18n) {
466
+ params.checkLastestI18nFile = true
467
+ params.i18nFileVersion = i18nUtil.getI18nFileVersion()
468
+ }
469
+ http
470
+ .post(window.$vueApp.config.globalProperties.baseAPI + '/acs/user/i18n-languages', params)
471
+ .then((langInfo) => {
472
+ const i18nCurrentVersion = i18nUtil.getI18nFileVersion()
473
+ i18nUtil.setI18nFileVersion(langInfo.i18nFileVersion)
474
+ if (!url && langInfo.i18nFileUrls[langInfo.language]) {
475
+ url = langInfo.i18nFileUrls[langInfo.language] + '?_t_=' + new Date().getTime()
476
+ i18nUtil.setLangFileUrl(systemCode, langInfo.language, url)
477
+ }
478
+ if (i18nCurrentVersion && Number(i18nCurrentVersion) === langInfo.i18nFileVersion) {
479
+ // 表示是最新的国际化文件,可以直接加载使用
480
+ i18nUtil
481
+ .loadLangFile(systemCode, url, currentLanguage)
482
+ .then(() => {
483
+ resolve(currentLanguage)
484
+ })
485
+ .catch(() => {
486
+ resolve(currentLanguage)
487
+ })
488
+ } else {
489
+ // 不是最新的国际化文件或者没有加载过国际化文件,则后端会返回最新的国际化文件路径和用户当前语言
490
+ i18nUtil.setEnableI18nState(systemCode, langInfo.enableI18n ? true : false)
491
+ if (langInfo.enableI18n && langInfo.i18nFileUrls[langInfo.language]) {
492
+ const url = langInfo.i18nFileUrls[langInfo.language] + '?_t_=' + new Date().getTime()
493
+ i18nUtil.setLangFileUrl(systemCode, langInfo.language, url)
494
+ i18nUtil
495
+ .loadLangFile(systemCode, url, langInfo.language)
496
+ .then(() => {
497
+ resolve(langInfo.language)
498
+ })
499
+ .catch(() => {
500
+ resolve(langInfo.language ? langInfo.language : 'zh_CN')
501
+ })
502
+ } else {
503
+ // 如果没有开启国际化
504
+ resolve(langInfo.language)
505
+ }
506
+ }
507
+ })
508
+ .catch(() => {
509
+ resolve('zh_CN')
510
+ })
511
+ }
451
512
  }
452
513
  })
453
514
  }
515
+
516
+ async function handlePlateSysLang(currentLanguage) {
517
+ if (currentLanguage && currentLanguage !== 'undefined') {
518
+ return currentLanguage
519
+ } else {
520
+ const params = { systemCode: getCurrentSystemCode() }
521
+ try {
522
+ const langInfo = await http.post(
523
+ window.$vueApp.config.globalProperties.baseAPI + '/acs/user/i18n-languages',
524
+ params
525
+ )
526
+ return langInfo.language ? langInfo.language : 'zh_CN'
527
+ } catch {
528
+ return 'zh_CN'
529
+ }
530
+ }
531
+ }
532
+
454
533
  export function setProjectSetting() {
455
534
  const projectSettingCache = Cookies.get('PROJECT_SETTINGS')
456
535
  let projectSettings = null
@@ -518,8 +597,7 @@ export function replacePlaceholders(template, ...args) {
518
597
  })
519
598
  }
520
599
 
521
-
522
- function isOpenMobileGateway () {
600
+ function isOpenMobileGateway() {
523
601
  // 系统参数设置中配置的是否开启移动网关,没有配置默认是开启的
524
602
  let isOpenMobileGatewayCache = getCookieCache('IS_OPEN_MOBILE_GATEWAY')
525
603
  if (isOpenMobileGatewayCache === undefined || isOpenMobileGatewayCache === null) {
@@ -532,13 +610,16 @@ function isOpenMobileGateway () {
532
610
  * @param {*} url
533
611
  * @returns
534
612
  */
535
- export function getReplaceUrlDomain (url) {
613
+ export function getReplaceUrlDomain(url) {
536
614
  const isOpenMobileGatewayCache = isOpenMobileGateway()
537
615
  console.log('===getReplaceUrlDomain==isOpenMobileGatewayCache=', isOpenMobileGatewayCache)
538
616
  if (isOpenMobileGatewayCache === 'true' && url !== undefined && window.$vueApp.config.globalProperties.replaceUrl) {
539
617
  // 表示需要替换url中的"https://域名"
540
618
  const baseApi = uswindow.$vueApp.config.globalProperties.baseAPI
541
- if ((url + '').indexOf(uswindow.$vueApp.config.globalProperties.replaceUrl + '/') < 0 && (url + '').indexOf('://') > 0) {
619
+ if (
620
+ (url + '').indexOf(uswindow.$vueApp.config.globalProperties.replaceUrl + '/') < 0 &&
621
+ (url + '').indexOf('://') > 0
622
+ ) {
542
623
  // 表示路径还未替换
543
624
  console.log('===getReplaceUrlDomain==url.indexOf(uswindow.$vueApp.config.globalProperties.replaceUrl) !== 0')
544
625
  const prefixUrl1 = baseApi.substring(0, baseApi.indexOf('://'))
@@ -561,9 +642,17 @@ export function getReplaceUrlDomain (url) {
561
642
  return url
562
643
  }
563
644
 
564
- export function formatFileName (fileName) {
645
+ export function formatFileName(fileName) {
565
646
  if (fileName) {
566
647
  fileName = fileName.replace('#', '~~').replace('?', '~$').replace('&', '$')
567
648
  }
568
649
  return fileName
569
- }
650
+ }
651
+
652
+ export function getCurrentSystemCode() {
653
+ if (window.$vueApp.config.globalProperties.currentSystem) {
654
+ return window.$vueApp.config.globalProperties.currentSystem
655
+ } else {
656
+ return window.$vueApp.config.globalProperties.systemCode
657
+ }
658
+ }
@@ -0,0 +1,141 @@
1
+ import axios from 'axios'
2
+ export function setLangFileUrl(systemCode, lang, url) {
3
+ let i18nFileUrlsItem = getLocalStorageJson('i18nFileUrls')
4
+ if (!i18nFileUrlsItem) {
5
+ i18nFileUrlsItem = {}
6
+ }
7
+ i18nFileUrlsItem[systemCode + '_' + lang] = url
8
+ window.localStorage.setItem('i18nFileUrls', JSON.stringify(i18nFileUrlsItem))
9
+ }
10
+
11
+ export function getLangFileUrl(systemCode, lang) {
12
+ const i18nFileUrlsItem = getLocalStorageJson('i18nFileUrls')
13
+ if (i18nFileUrlsItem) {
14
+ return i18nFileUrlsItem[systemCode + '_' + lang]
15
+ }
16
+ return null
17
+ }
18
+
19
+ export function removeLangFileUrl(systemCode, lang) {
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')
29
+ }
30
+
31
+ export function setEnableI18nState(systemCode, enableI18n) {
32
+ let allStateObj = {}
33
+ const allState = getLocalStorageJson('enableI18nSystem')
34
+ if (allState) {
35
+ allStateObj = allState
36
+ }
37
+ allStateObj[systemCode] = enableI18n ? true : false
38
+ window.localStorage.setItem('enableI18nSystem', JSON.stringify(allStateObj))
39
+ }
40
+
41
+ export function getEnableI18nState(systemCode) {
42
+ const allState = getLocalStorageJson('enableI18nSystem')
43
+ if (allState) {
44
+ return allState[systemCode]
45
+ }
46
+ return null
47
+ }
48
+
49
+ export function removeEnableI18nState() {
50
+ window.localStorage.removeItem('enableI18nSystem')
51
+ }
52
+
53
+ export function removeEnableI18nWidthSystemCode() {
54
+ const allState = getLocalStorageJson('enableI18nSystem')
55
+ if (allState) {
56
+ delete allState[getCurrentSystemCode()]
57
+ window.localStorage.setItem('enableI18nSystem', JSON.stringify(allState))
58
+ }
59
+ }
60
+
61
+ function getLocalStorageJson(key) {
62
+ const item = window.localStorage.getItem(key)
63
+ if (item) {
64
+ return JSON.parse(item)
65
+ }
66
+ return null
67
+ }
68
+
69
+ function loadLangFile(systemCode, url, language) {
70
+ console.log('loadLangFile', systemCode, url, language)
71
+ if (!url) {
72
+ return Promise.resolve()
73
+ }
74
+ return new Promise((resolve, reject) => {
75
+ if (window.$i18n) {
76
+ axios
77
+ .get(url, {
78
+ withCredential: false
79
+ })
80
+ .then((response) => {
81
+ const lang = getLocaleByLang(language)
82
+ if (response && response.data) {
83
+ // 获取当前的国际化信息
84
+ const currentMessages = window.$i18n.global.getLocaleMessage(lang)
85
+ // 新的国际化信息
86
+ if (currentMessages[systemCode]) {
87
+ Object.assign(currentMessages[systemCode], response.data)
88
+ } else {
89
+ currentMessages[systemCode] = response.data
90
+ }
91
+ // 设置合并后的国际化信息
92
+ window.$i18n.global.setLocaleMessage(lang, currentMessages)
93
+ }
94
+ resolve()
95
+ })
96
+ .catch((error) => {
97
+ reject(error)
98
+ })
99
+ }
100
+ resolve()
101
+ })
102
+ }
103
+ export function getLocaleByLang(lang) {
104
+ let locale = 'cn'
105
+ if (lang && lang.indexOf('_') > 0) {
106
+ const language = lang.substring(0, lang.indexOf('_'))
107
+ locale = language
108
+ }
109
+ if (locale === 'zh') {
110
+ locale = 'cn'
111
+ }
112
+ return locale
113
+ }
114
+
115
+ function clearI18nCache(lang) {
116
+ removeEnableI18nState()
117
+ removeAllLangFileUrl()
118
+ }
119
+
120
+ function setI18nFileVersion(version) {
121
+ window.localStorage.setItem('i18nFileVersion', version)
122
+ }
123
+
124
+ function getI18nFileVersion() {
125
+ return window.localStorage.getItem('i18nFileVersion')
126
+ }
127
+
128
+ export default {
129
+ setLangFileUrl,
130
+ getLangFileUrl,
131
+ removeLangFileUrl,
132
+ setEnableI18nState,
133
+ getEnableI18nState,
134
+ removeEnableI18nState,
135
+ removeEnableI18nWidthSystemCode,
136
+ getLocalStorageJson,
137
+ loadLangFile,
138
+ getLocaleByLang,
139
+ setI18nFileVersion,
140
+ getI18nFileVersion
141
+ }
@@ -1,46 +1,3 @@
1
1
  <template>
2
2
  <router-view />
3
3
  </template>
4
- <script>
5
- import eventBus from '../../../src/utils/eventBus'
6
- export default {
7
- created(){
8
- window.addEventListener('message', this.receiveMessage, false)
9
- },
10
- destroyed () {
11
- window.removeEventListener('message', this.receiveMessage, false)
12
- },
13
- methods: {
14
- receiveMessage (event) {
15
- const result = event.data
16
- console.log('receiveMessage-----result111=', result)
17
- if (result && typeof result === 'string') {
18
- console.log('receiveMessage-----result2222=', result)
19
- // console.log('接收手机端传过来的信息--receiveMessage===', result)
20
- try {
21
- const data = JSON.parse(result)
22
- // console.log('接收手机端传过来的信息--data=', data)
23
- const type = data.type // 'pickFileDone' 选择文件完成,'uploadFileDone' 上传文件完成
24
- console.log('receiveMessage-----result3333=', type, 'data.files=', data.files)
25
- // console.log('接收手机端传过来的信息--type=', type)
26
- if (type && type === 'onResize') {
27
- // 横竖屏切换时重新计算高度
28
- eventBus.$emit('onResize')
29
- } else if (type && type === 'pickFileDone') {
30
- // 选择文件完成
31
- console.log('receiveMessage-----result4444=', type)
32
- // fileNames:[{name:'xx',base64Path:'xxx'},{name:'xxx',base64Path:'xxxxx'}]
33
- eventBus.$emit('pickFileDone', data)
34
- } else if (type && type === 'uploadFileDone') {
35
- eventBus.$emit('uploadFileDone', data)
36
- } else if (type && type === 'scan') {
37
- eventBus.$emit('scan', data)
38
- }
39
- } catch (error) {
40
- console.log(error)
41
- }
42
- }
43
- }
44
- }
45
- }
46
- </script>
@@ -17,7 +17,6 @@
17
17
  import { Sidebar, AppMain, Breadcrumb } from './components'
18
18
  import ResizeMixin from './mixin/ResizeHandler'
19
19
  import { isShowMenuRoute } from '../../../src/utils/common-util'
20
- import eventBus from '../../../src/utils/eventBus'
21
20
 
22
21
  export default {
23
22
  name: 'Layout',
@@ -50,46 +49,10 @@ export default {
50
49
  }
51
50
  },
52
51
  },
53
- created(){
54
- window.addEventListener('message', this.receiveMessage, false)
55
- },
56
- destroyed () {
57
- window.removeEventListener('message', this.receiveMessage, false)
58
- },
59
52
  methods: {
60
53
  handleClickOutside() {
61
54
  this.$store.dispatch('closeSidebar', { withoutAnimation: false })
62
55
  },
63
- receiveMessage (event) {
64
- const result = event.data
65
- console.log('receiveMessage-----result111=', result)
66
- if (result && typeof result === 'string') {
67
- console.log('receiveMessage-----result2222=', result)
68
- // console.log('接收手机端传过来的信息--receiveMessage===', result)
69
- try {
70
- const data = JSON.parse(result)
71
- // console.log('接收手机端传过来的信息--data=', data)
72
- const type = data.type // 'pickFileDone' 选择文件完成,'uploadFileDone' 上传文件完成
73
- console.log('receiveMessage-----result3333=', type, 'data.files=', data.files)
74
- // console.log('接收手机端传过来的信息--type=', type)
75
- if (type && type === 'onResize') {
76
- // 横竖屏切换时重新计算高度
77
- eventBus.$emit('onResize')
78
- } else if (type && type === 'pickFileDone') {
79
- // 选择文件完成
80
- console.log('receiveMessage-----result4444=', type)
81
- // fileNames:[{name:'xx',base64Path:'xxx'},{name:'xxx',base64Path:'xxxxx'}]
82
- eventBus.$emit('pickFileDone', data)
83
- } else if (type && type === 'uploadFileDone') {
84
- eventBus.$emit('uploadFileDone', data)
85
- } else if (type && type === 'scan') {
86
- eventBus.$emit('scan', data)
87
- }
88
- } catch (error) {
89
- console.log(error)
90
- }
91
- }
92
- }
93
56
  },
94
57
  }
95
58
  </script>