agilebuilder-ui 1.0.69 → 1.0.71-temp8

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.
Files changed (33) hide show
  1. package/lib/super-ui.css +1 -1
  2. package/lib/super-ui.js +44667 -42821
  3. package/lib/super-ui.umd.cjs +94 -86
  4. package/package.json +4 -2
  5. package/packages/department-tree/src/department-tree.vue +28 -10
  6. package/packages/department-tree-mobile/src/department-tree-app.vue +6 -6
  7. package/packages/department-user-tree/src/department-user-tree.vue +16 -2
  8. package/packages/department-user-tree-mobile/src/department-user-tree-app.vue +6 -6
  9. package/packages/fs-upload-new/src/file-upload-mobile/file-upload-app.vue +410 -0
  10. package/packages/fs-upload-new/src/file-upload-mobile/file-upload-browser.vue +484 -0
  11. package/packages/fs-upload-new/src/file-upload-mobile/file-upload-component.vue +140 -0
  12. package/packages/fs-upload-new/src/file-upload-mobile/file-upload-input.vue +220 -0
  13. package/packages/fs-upload-new/src/file-upload-mobile/file-upload.vue +249 -0
  14. package/packages/fs-upload-new/src/fs-button-upload.vue +9 -13
  15. package/packages/fs-upload-new/src/fs-drag-upload.vue +4 -8
  16. package/packages/fs-upload-new/src/fs-preview-new.vue +103 -36
  17. package/packages/fs-upload-new/src/fs-upload-new.vue +88 -8
  18. package/packages/super-grid/src/apis.js +6 -6
  19. package/packages/super-grid/src/custom-formatter.js +2 -1
  20. package/packages/super-grid/src/search-button.vue +18 -14
  21. package/packages/super-grid/src/search-form-mobile.vue +250 -0
  22. package/packages/super-grid/src/search-form.vue +159 -82
  23. package/packages/super-grid/src/super-grid.vue +21 -5
  24. package/src/api/sso-service.js +25 -14
  25. package/src/i18n/langs/cn.js +4 -1
  26. package/src/i18n/langs/en.js +4 -1
  27. package/src/permission.js +108 -122
  28. package/src/styles/theme/green/sidebar.scss +11 -0
  29. package/src/utils/common-util.js +217 -124
  30. package/src/utils/i18n-util.js +127 -0
  31. package/src/utils/jump-page-utils.js +34 -13
  32. package/src/utils/permissionAuth.js +47 -8
  33. package/src/utils/util.js +1 -1
@@ -2,6 +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'
6
+ import i18nUtil from './i18n-util'
5
7
  /**
6
8
  * 获得相对地址
7
9
  */
@@ -22,9 +24,7 @@ export function getRelativeBaseUrl(originalBaseUrl) {
22
24
  if (baseUrls.length >= 3) {
23
25
  const baseUrlPrefix = baseUrls[0] + '//' + baseUrls[2]
24
26
  // console.log('getRelativeBaseUrl---baseUrlPrefix=',baseUrlPrefix)
25
- baseUrlSuffix = originalBaseUrl.substring(
26
- originalBaseUrl.indexOf(baseUrlPrefix) + baseUrlPrefix.length
27
- )
27
+ baseUrlSuffix = originalBaseUrl.substring(originalBaseUrl.indexOf(baseUrlPrefix) + baseUrlPrefix.length)
28
28
  // console.log('getRelativeBaseUrl---baseUrlSuffix=',baseUrlSuffix)
29
29
  }
30
30
  if (relativeUrl.lastIndexOf('/') === relativeUrl.length - 1) {
@@ -83,19 +83,14 @@ export function replacePrefix(originalUrl) {
83
83
  // console.log('replacePrefix---locationPrefixUrl=',locationPrefixUrl)
84
84
  if (orginalPrefixUrl !== locationPrefixUrl) {
85
85
  // 获得/demo/#/notice/task需要替换为http://127.0.0.1/demo/#/notice/task
86
- let suffixUrl = originalUrl.substring(
87
- originalUrl.indexOf(orginalPrefixUrl) + orginalPrefixUrl.length
88
- )
86
+ let suffixUrl = originalUrl.substring(originalUrl.indexOf(orginalPrefixUrl) + orginalPrefixUrl.length)
89
87
  if (suffixUrl.indexOf('/') !== 0) {
90
88
  suffixUrl = '/' + suffixUrl
91
89
  }
92
90
  // console.log('replacePrefix---suffixUrl=',suffixUrl)
93
91
  if (locationPrefixUrl.lastIndexOf('/') === locationPrefixUrl.length - 1) {
94
92
  // 表示以“/”结尾,去掉最后一个“/”
95
- locationPrefixUrl = locationPrefixUrl.substring(
96
- 0,
97
- locationPrefixUrl.lastIndexOf('/')
98
- )
93
+ locationPrefixUrl = locationPrefixUrl.substring(0, locationPrefixUrl.lastIndexOf('/'))
99
94
  }
100
95
  // console.log('replacePrefix---locationPrefixUrl2=',locationPrefixUrl)
101
96
  newUrl = locationPrefixUrl + suffixUrl
@@ -132,12 +127,7 @@ export function getLoginUrl() {
132
127
  }
133
128
  getPortalFrontendUrl()
134
129
  .then((portalUrl) => {
135
- let loginUrl =
136
- portalUrl +
137
- '#/login?systemPath=' +
138
- systemPath +
139
- '&routerPath=' +
140
- routerPath
130
+ let loginUrl = portalUrl + '#/login?systemPath=' + systemPath + '&routerPath=' + routerPath
141
131
  if (param) {
142
132
  loginUrl += '&' + param
143
133
  }
@@ -171,8 +161,7 @@ export function isShowSystemMenu() {
171
161
  export function getSystemFrontendUrl(frontendUrl) {
172
162
  if (
173
163
  window.$vueApp.config.globalProperties.projectModel &&
174
- window.$vueApp.config.globalProperties.projectModel ===
175
- 'developing.model' &&
164
+ window.$vueApp.config.globalProperties.projectModel === 'developing.model' &&
176
165
  window.$vueApp.config.globalProperties.frontUrl
177
166
  ) {
178
167
  return window.$vueApp.config.globalProperties.frontUrl
@@ -184,8 +173,7 @@ export function getSystemFrontendUrl(frontendUrl) {
184
173
  export function getSystemBackendUrl(backendUrl) {
185
174
  if (
186
175
  window.$vueApp.config.globalProperties.projectModel &&
187
- window.$vueApp.config.globalProperties.projectModel ===
188
- 'developing.model' &&
176
+ window.$vueApp.config.globalProperties.projectModel === 'developing.model' &&
189
177
  window.$vueApp.config.globalProperties.baseURL
190
178
  ) {
191
179
  return window.$vueApp.config.globalProperties.baseURL
@@ -263,16 +251,12 @@ export function getTimeZone() {
263
251
  const dateStr = new Date() + ''
264
252
  let timeZone = ''
265
253
  if (dateStr.indexOf('GMT') > 0) {
266
- const timeZoneSuffix = dateStr
267
- .substring(dateStr.indexOf('GMT') + 3, dateStr.indexOf('('))
268
- .trim()
254
+ const timeZoneSuffix = dateStr.substring(dateStr.indexOf('GMT') + 3, dateStr.indexOf('(')).trim()
269
255
  const partPrefix = timeZoneSuffix.substring(0, timeZoneSuffix.length - 2)
270
256
  const partSuffix = timeZoneSuffix.substring(timeZoneSuffix.length - 2)
271
257
  timeZone = 'UTC' + partPrefix + ':' + partSuffix
272
258
  } else if (dateStr.indexOf('UTC') > 0) {
273
- timeZone =
274
- 'UTC' +
275
- dateStr.substring(dateStr.indexOf('UTC') + 3, dateStr.indexOf('(')).trim()
259
+ timeZone = 'UTC' + dateStr.substring(dateStr.indexOf('UTC') + 3, dateStr.indexOf('(')).trim()
276
260
  }
277
261
  return timeZone
278
262
  }
@@ -286,8 +270,7 @@ export function setCustomSystemBackendUrl(customSystem) {
286
270
  // 表示是生产环境时,需要根据数据库配置获得对应的后端地址
287
271
  const backendUrl = window.$authApi.getSystemCacheUrlByCode(customSystem)
288
272
  if (backendUrl) {
289
- window.$vueApp.config.globalProperties.baseURL =
290
- getRelativeBaseUrl(backendUrl)
273
+ window.$vueApp.config.globalProperties.baseURL = getRelativeBaseUrl(backendUrl)
291
274
  }
292
275
  }
293
276
  }
@@ -305,13 +288,13 @@ export function pushCustomControlValidatorRef(pageCode, refName, ref) {
305
288
  pageCustomControlRef.set(refName, ref)
306
289
  }
307
290
 
308
- export function removeCustomControlValidatorRef (pageCode, refName) {
309
- if (window.customValidatorRef) {
310
- const pageCustomControlRef = window.customValidatorRef.get(pageCode)
311
- if (pageCustomControlRef) {
312
- pageCustomControlRef.delete(refName)
313
- }
314
- }
291
+ export function removeCustomControlValidatorRef(pageCode, refName) {
292
+ if (window.customValidatorRef) {
293
+ const pageCustomControlRef = window.customValidatorRef.get(pageCode)
294
+ if (pageCustomControlRef) {
295
+ pageCustomControlRef.delete(refName)
296
+ }
297
+ }
315
298
  }
316
299
 
317
300
  export function isMobileBrowser() {
@@ -329,15 +312,7 @@ export function isMobileBrowser() {
329
312
  }
330
313
 
331
314
  export function getLocaleByLang(lang) {
332
- let locale = 'cn'
333
- if (lang && lang.indexOf('_') > 0) {
334
- const language = lang.substring(0, lang.indexOf('_'))
335
- locale = language
336
- }
337
- if (locale === 'zh') {
338
- locale = 'cn'
339
- }
340
- return locale
315
+ return i18nUtil.getLocaleByLang(lang)
341
316
  }
342
317
 
343
318
  export function cacheLangs(langs) {
@@ -379,33 +354,28 @@ export function cacheAllLanguagesUtil(http) {
379
354
  setAllLanguages(cookieCacheLangs)
380
355
  resolve()
381
356
  } else {
382
- http
383
- .get(
384
- window.$vueApp.config.globalProperties.baseAPI +
385
- '/component/all-languages'
386
- )
387
- .then((langList) => {
388
- const langResult = {}
389
- if (langList) {
390
- langList.forEach((item) => {
391
- // 例如:zh_CN、en_US
392
- const lang = item.value
393
- let langShort
394
- if (lang.indexOf('_') > 0) {
395
- langShort = lang.substring(0, lang.indexOf('_'))
396
- }
397
- if (langShort && langShort === 'zh') {
398
- // 中文处理,为了兼容历史逻辑
399
- langShort = 'cn'
400
- }
401
- if (langShort) {
402
- langResult[langShort] = lang
403
- }
404
- })
405
- }
406
- cacheLangs(langResult)
407
- resolve()
408
- })
357
+ http.get(window.$vueApp.config.globalProperties.baseAPI + '/component/all-languages').then((langList) => {
358
+ const langResult = {}
359
+ if (langList) {
360
+ langList.forEach((item) => {
361
+ // 例如:zh_CN、en_US
362
+ const lang = item.value
363
+ let langShort
364
+ if (lang.indexOf('_') > 0) {
365
+ langShort = lang.substring(0, lang.indexOf('_'))
366
+ }
367
+ if (langShort && langShort === 'zh') {
368
+ // 中文处理,为了兼容历史逻辑
369
+ langShort = 'cn'
370
+ }
371
+ if (langShort) {
372
+ langResult[langShort] = lang
373
+ }
374
+ })
375
+ }
376
+ cacheLangs(langResult)
377
+ resolve()
378
+ })
409
379
  }
410
380
  } else {
411
381
  resolve()
@@ -437,8 +407,8 @@ export function windowOpenUrl(url, projectModel) {
437
407
  // _systemName_参数用于设置浏览器页签名的,国际化使用,在imatrix ui的beforeEach中有使用这个参数
438
408
  if (param) {
439
409
  jumpUrl += '&' + param
440
- }
441
- if (jumpUrl.indexOf('_systemName_=') === -1) {
410
+ }
411
+ if (jumpUrl.indexOf('_systemName_=') === -1) {
442
412
  jumpUrl += '&_systemName_=' + systemName
443
413
  }
444
414
  window.open(jumpUrl)
@@ -455,19 +425,80 @@ export function windowOpenUrl(url, projectModel) {
455
425
  }
456
426
  }
457
427
 
458
-
459
428
  // 首次加载业务系统时,缓存当前用户语言
460
429
  export function cacheCurrentLanguageUtil(http) {
461
430
  return new Promise((resolve, reject) => {
462
431
  const token = getToken()
463
432
  if (token) {
464
433
  const currentLanguage = getLanguage()
465
- if (currentLanguage && currentLanguage!=='undefined') {
466
- resolve(currentLanguage)
434
+ const systemCode = getCurrentSystemCode()
435
+ if (isPlateSys(systemCode)) {
436
+ // 平台系统不需要加载国际化文件
437
+ if (currentLanguage && currentLanguage !== 'undefined') {
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
+ })
450
+ }
467
451
  } else {
468
- http.get(window.$vueApp.config.globalProperties.baseAPI + '/acs/user-languages').then((currentLanguage) => {
452
+ // 业务系统是否启用了国际化
453
+ const enableI18n = i18nUtil.getEnableI18nState(systemCode)
454
+ if (enableI18n === false && currentLanguage && currentLanguage !== 'undefined') {
455
+ // 如果没有开启国际化, 并且已经缓存了当前用户的语言,则直接返回
469
456
  resolve(currentLanguage)
470
- })
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
+ }
471
502
  }
472
503
  } else {
473
504
  // 默认是中文
@@ -476,63 +507,125 @@ export function cacheCurrentLanguageUtil(http) {
476
507
  })
477
508
  }
478
509
  export function setProjectSetting() {
479
- const projectSettingCache = Cookies.get("PROJECT_SETTINGS")
480
- let projectSettings = null
481
- if(projectSettingCache){
482
- projectSettings = JSON.parse(projectSettingCache)
483
- this.setLogoUrl(projectSettings)
484
- } else {
485
- this.$http.get(window.$vueApp.config.globalProperties.baseAPI + '/cfg/project-settings').then((data) => {
486
- Cookies.set("PROJECT_SETTINGS", JSON.stringify(data))
487
- projectSettings = data
488
- })
489
- }
490
- if (projectSettings.browserImageUuid) {
491
- const linkElement = document.getElementById('ambBrowserIcon');
492
- if (linkElement) {
493
- linkElement.href = window.$vueApp.config.globalProperties.baseAPI + '/cfg/project/icon/browserIcon'
494
- }
495
- }
510
+ const projectSettingCache = Cookies.get('PROJECT_SETTINGS')
511
+ let projectSettings = null
512
+ if (projectSettingCache) {
513
+ projectSettings = JSON.parse(projectSettingCache)
514
+ this.setLogoUrl(projectSettings)
515
+ } else {
516
+ this.$http.get(window.$vueApp.config.globalProperties.baseAPI + '/cfg/project-settings').then((data) => {
517
+ Cookies.set('PROJECT_SETTINGS', JSON.stringify(data))
518
+ projectSettings = data
519
+ })
520
+ }
521
+ if (projectSettings.browserImageUuid) {
522
+ const linkElement = document.getElementById('ambBrowserIcon')
523
+ if (linkElement) {
524
+ linkElement.href = window.$vueApp.config.globalProperties.baseAPI + '/cfg/project/icon/browserIcon'
525
+ }
526
+ }
496
527
  }
497
528
 
498
529
  // 动态加载css
499
530
  export function loadCSS() {
500
531
  var theme
501
- if(!theme){
502
- theme = localStorage.getItem('CURRENT_THEME')
503
- }
504
- if(!theme){
505
- console.error('皮肤主题为空!')
506
- return
507
- }
508
- const baseAPI = localStorage.getItem('_baseAPI_')
509
- if(baseAPI){
510
- const href = replacePrefix(baseAPI) + '/component/theme/load-theme?theme=' + theme + '&_t_=' + new Date().getTime()
511
- let isHasLink = true
512
- let cssLink = document.getElementById('_loadTheme_')
513
- if(!cssLink){
514
- cssLink = document.createElement("link")
515
- isHasLink = false
516
- }
517
- cssLink.rel = "stylesheet";
518
- cssLink.type = "text/css";
519
- cssLink.id="_loadTheme_"
520
- cssLink.href = href;
521
- if(!isHasLink){
522
- document.getElementsByTagName("head")[0].appendChild(cssLink)
523
- }
532
+ if (!theme) {
533
+ theme = localStorage.getItem('CURRENT_THEME')
534
+ }
535
+ if (!theme) {
536
+ console.error('皮肤主题为空!')
537
+ return
538
+ }
539
+ const baseAPI = localStorage.getItem('_baseAPI_')
540
+ if (baseAPI) {
541
+ const href = replacePrefix(baseAPI) + '/component/theme/load-theme?theme=' + theme + '&_t_=' + new Date().getTime()
542
+ let isHasLink = true
543
+ let cssLink = document.getElementById('_loadTheme_')
544
+ if (!cssLink) {
545
+ cssLink = document.createElement('link')
546
+ isHasLink = false
524
547
  }
525
- const body = document.querySelector('body')
526
- if(body){
527
- body.setAttribute('class', theme)
548
+ cssLink.rel = 'stylesheet'
549
+ cssLink.type = 'text/css'
550
+ cssLink.id = '_loadTheme_'
551
+ cssLink.href = href
552
+ if (!isHasLink) {
553
+ document.getElementsByTagName('head')[0].appendChild(cssLink)
528
554
  }
529
555
  }
556
+ const body = document.querySelector('body')
557
+ if (body) {
558
+ body.setAttribute('class', theme)
559
+ }
560
+ }
530
561
 
531
-
532
- /**
562
+ /**
533
563
  * 获取UUID,去掉破折号
534
564
  * @returns
535
565
  */
536
566
  export function getUuidv4() {
537
567
  return uuidv4().replace(/-/g, '')
538
- }
568
+ }
569
+
570
+ export function replacePlaceholders(template, ...args) {
571
+ return template.replace(/{(\d+)}/g, (match, index) => {
572
+ return typeof args[index] !== 'undefined' ? args[index] : match
573
+ })
574
+ }
575
+
576
+ function isOpenMobileGateway() {
577
+ // 系统参数设置中配置的是否开启移动网关,没有配置默认是开启的
578
+ let isOpenMobileGatewayCache = getCookieCache('IS_OPEN_MOBILE_GATEWAY')
579
+ if (isOpenMobileGatewayCache === undefined || isOpenMobileGatewayCache === null) {
580
+ isOpenMobileGatewayCache = 'true'
581
+ }
582
+ return isOpenMobileGatewayCache
583
+ }
584
+ /**
585
+ * 获得替换域名后的url
586
+ * @param {*} url
587
+ * @returns
588
+ */
589
+ export function getReplaceUrlDomain(url) {
590
+ const isOpenMobileGatewayCache = isOpenMobileGateway()
591
+ console.log('===getReplaceUrlDomain==isOpenMobileGatewayCache=', isOpenMobileGatewayCache)
592
+ if (isOpenMobileGatewayCache === 'true' && url !== undefined && window.$vueApp.config.globalProperties.replaceUrl) {
593
+ // 表示需要替换url中的"https://域名"
594
+ const baseApi = uswindow.$vueApp.config.globalProperties.baseAPI
595
+ if ((url + '').indexOf(uswindow.$vueApp.config.globalProperties.replaceUrl + '/') < 0 && (url + '').indexOf('://') > 0) {
596
+ // 表示路径还未替换
597
+ console.log('===getReplaceUrlDomain==url.indexOf(uswindow.$vueApp.config.globalProperties.replaceUrl) !== 0')
598
+ const prefixUrl1 = baseApi.substring(0, baseApi.indexOf('://'))
599
+ const urlSuffix1 = baseApi.substring(baseApi.indexOf('://') + 3)
600
+ const domainUrl1 = urlSuffix1.substring(0, urlSuffix1.indexOf('/'))
601
+ const prefixUrlBase = prefixUrl1 + '://' + domainUrl1
602
+ const prefixUrl2 = baseApi.substring(0, baseApi.indexOf('://'))
603
+ let urlSuffix = url.substring(url.indexOf('://') + 3)
604
+ const domainUrl2 = urlSuffix.substring(0, urlSuffix.indexOf('/'))
605
+ const prefixUrl = prefixUrl2 + '://' + domainUrl2
606
+ if (prefixUrl === prefixUrlBase) {
607
+ urlSuffix = urlSuffix.substring(urlSuffix.indexOf('/'))
608
+ url = uswindow.$vueApp.config.globalProperties.replaceUrl + urlSuffix
609
+ console.log('===getReplaceUrlDomain==url=', url)
610
+ }
611
+ } else {
612
+ console.log('===getReplaceUrlDomain==has-replace-url=', url)
613
+ }
614
+ }
615
+ return url
616
+ }
617
+
618
+ export function formatFileName(fileName) {
619
+ if (fileName) {
620
+ fileName = fileName.replace('#', '~~').replace('?', '~$').replace('&', '$')
621
+ }
622
+ return fileName
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
+ }
@@ -0,0 +1,127 @@
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
+ return new Promise((resolve, reject) => {
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)
90
+ }
91
+ resolve()
92
+ })
93
+ .catch((error) => {
94
+ reject(error)
95
+ })
96
+ }
97
+ resolve()
98
+ })
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
+ }
116
+ export default {
117
+ setLangFileUrl,
118
+ getLangFileUrl,
119
+ removeLangFileUrl,
120
+ setEnableI18nState,
121
+ getEnableI18nState,
122
+ removeEnableI18nState,
123
+ removeEnableI18nWidthSystemCode,
124
+ getLocalStorageJson,
125
+ loadLangFile,
126
+ getLocaleByLang
127
+ }