-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangeTheme.js
121 lines (107 loc) · 3.07 KB
/
changeTheme.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { environment } from 'edf-utils'
let loadSplitCss = false
const borwserVersion = environment.getBrowserVersion()
if (borwserVersion.ie && borwserVersion.version < 10) {
loadSplitCss = true
}
import moduleGlobal from './modules/loadGlobalModules'
const moduleName = moduleGlobal.moduleName
function getTheme(color) {
let theme = null
//判断主题颜色
switch (color) {
case '#FF913A':
theme = 'YellowTheme'
break;
case '#00B38A':
theme = 'GreenTheme'
break;
case '#0066B3':
theme = 'BlueTheme'
break;
case '#1EB5AD':
theme = 'BusinessBlueTheme'
break;
case '#B4A074':
theme = 'OrangeTheme'
break;
case '#414141':
theme = 'BlackTheme'
break;
case '#0994DC':
theme = 'Tax72Theme'
break;
default:
theme = 'BlueTheme'
break;
}
return theme
}
const createLink = () => {
let link = document.createElement('link')
link.className = 'el-element'
link.rel = 'stylesheet'
link.type = 'text/css'
link.id = 'skin'
return link
}
async function changeTheme(origin, color = {}, source) {
if (loadSplitCss || process.env.MODE_SPLIT) {
return changeThemeforIE(color)
}
if (!window.moduleManifest) {
await moduleGlobal.get('theme')
}
const preLink = document.querySelector('#modules_theme_collection')
let theme = getTheme(color)
//插入link标签
let link = document.createElement('link')
link.className = 'moduleManifest'
link.rel = 'stylesheet'
link.type = 'text/css'
if(source != 'global' || (window.location.href.indexOf('theme=blue') > -1)) {
link.href = `./mergeModule/merge${theme}.${window.moduleManifest.nowtime}.css`
}
document.head.appendChild(link)
if (preLink) {
document.head.removeChild(preLink)
link.id = 'modules_theme_collection'
}
if (window.singleApp) {
let link = document.createElement('link')
link.rel = 'stylesheet'
link.type = 'text/css'
link.href = `./singleStyle.css`
document.head.appendChild(link)
}
}
async function changeThemeforIE(color, i) {
if (!window.moduleManifest) {
await moduleGlobal.get('theme')
}
let theme = getTheme(color)
moduleName.forEach((item, index) => {
let link = null
let preLink = document.querySelector(`#skin${index}`)
link = createLink()
if (window[`moduleManifest`][item] && window[`moduleManifest`][item][`${item}${theme}.css`]) {
link.href = window[`moduleManifest`][item][`${item}${theme}.css`]
}
document.head.appendChild(link)
link.onload = () => {
if (preLink) {
document.head.removeChild(preLink)
}
link.id = `skin${index}`
}
})
}
window.changeTheme = {
changeThemeforIE,
changeTheme,
getTheme
}
export default {
changeThemeforIE,
changeTheme
}