agilebuilder-ui 1.0.71-tmp7 → 1.0.72

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.
@@ -1,127 +0,0 @@
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
- }