Skip to content

Commit 5ed1292

Browse files
authored
Merge branch 'master' into master
2 parents eb6175b + 9f5b59c commit 5ed1292

File tree

15 files changed

+9949
-136
lines changed

15 files changed

+9949
-136
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<template>
2+
<el-color-picker
3+
v-model="theme"
4+
:predefine="['#409EFF', '#1890ff', '#304156','#212121','#11a983', '#13c2c2', '#6959CD', '#f5222d', ]"
5+
class="theme-picker"
6+
popper-class="theme-picker-dropdown"
7+
/>
8+
</template>
9+
10+
<script>
11+
const version = require('element-ui/package.json').version // element-ui version from node_modules
12+
const ORIGINAL_THEME = '#409EFF' // default color
13+
export default {
14+
data() {
15+
return {
16+
chalk: '', // content of theme-chalk css
17+
theme: ''
18+
}
19+
},
20+
computed: {
21+
defaultTheme() {
22+
return this.$store.state.app.theme
23+
}
24+
},
25+
watch: {
26+
defaultTheme: {
27+
handler: function(val, oldVal) {
28+
this.theme = val
29+
},
30+
immediate: true
31+
},
32+
async theme(val) {
33+
const oldVal = this.chalk ? this.theme : ORIGINAL_THEME
34+
if (typeof val !== 'string') return
35+
const themeCluster = this.getThemeCluster(val.replace('#', ''))
36+
const originalCluster = this.getThemeCluster(oldVal.replace('#', ''))
37+
const $message = this.$message({
38+
message: '修改主题色中',
39+
customClass: 'theme-message',
40+
type: 'success',
41+
duration: 0,
42+
iconClass: 'el-icon-loading'
43+
})
44+
const getHandler = (variable, id) => {
45+
return () => {
46+
const originalCluster = this.getThemeCluster(ORIGINAL_THEME.replace('#', ''))
47+
const newStyle = this.updateStyle(this[variable], originalCluster, themeCluster)
48+
let styleTag = document.getElementById(id)
49+
if (!styleTag) {
50+
styleTag = document.createElement('style')
51+
styleTag.setAttribute('id', id)
52+
document.head.appendChild(styleTag)
53+
}
54+
styleTag.innerText = newStyle
55+
}
56+
}
57+
if (!this.chalk) {
58+
const url = `https://unpkg.com/element-ui@${version}/lib/theme-chalk/index.css`
59+
await this.getCSSString(url, 'chalk')
60+
}
61+
const chalkHandler = getHandler('chalk', 'chalk-style')
62+
chalkHandler()
63+
const styles = [].slice.call(document.querySelectorAll('style'))
64+
.filter(style => {
65+
const text = style.innerText
66+
return new RegExp(oldVal, 'i').test(text) && !/Chalk Variables/.test(text)
67+
})
68+
styles.forEach(style => {
69+
const { innerText } = style
70+
if (typeof innerText !== 'string') return
71+
style.innerText = this.updateStyle(innerText, originalCluster, themeCluster)
72+
})
73+
this.$emit('change', val)
74+
$message.close()
75+
}
76+
},
77+
methods: {
78+
updateStyle(style, oldCluster, newCluster) {
79+
let newStyle = style
80+
oldCluster.forEach((color, index) => {
81+
newStyle = newStyle.replace(new RegExp(color, 'ig'), newCluster[index])
82+
})
83+
return newStyle
84+
},
85+
getCSSString(url, variable) {
86+
return new Promise(resolve => {
87+
const xhr = new XMLHttpRequest()
88+
xhr.onreadystatechange = () => {
89+
if (xhr.readyState === 4 && xhr.status === 200) {
90+
this[variable] = xhr.responseText.replace(/@font-face{[^}]+}/, '')
91+
resolve()
92+
}
93+
}
94+
xhr.open('GET', url)
95+
xhr.send()
96+
})
97+
},
98+
getThemeCluster(theme) {
99+
const tintColor = (color, tint) => {
100+
let red = parseInt(color.slice(0, 2), 16)
101+
let green = parseInt(color.slice(2, 4), 16)
102+
let blue = parseInt(color.slice(4, 6), 16)
103+
if (tint === 0) { // when primary color is in its rgb space
104+
return [red, green, blue].join(',')
105+
} else {
106+
red += Math.round(tint * (255 - red))
107+
green += Math.round(tint * (255 - green))
108+
blue += Math.round(tint * (255 - blue))
109+
red = red.toString(16)
110+
green = green.toString(16)
111+
blue = blue.toString(16)
112+
return `#${red}${green}${blue}`
113+
}
114+
}
115+
const shadeColor = (color, shade) => {
116+
let red = parseInt(color.slice(0, 2), 16)
117+
let green = parseInt(color.slice(2, 4), 16)
118+
let blue = parseInt(color.slice(4, 6), 16)
119+
red = Math.round((1 - shade) * red)
120+
green = Math.round((1 - shade) * green)
121+
blue = Math.round((1 - shade) * blue)
122+
red = red.toString(16)
123+
green = green.toString(16)
124+
blue = blue.toString(16)
125+
return `#${red}${green}${blue}`
126+
}
127+
const clusters = [theme]
128+
for (let i = 0; i <= 9; i++) {
129+
clusters.push(tintColor(theme, Number((i / 10).toFixed(2))))
130+
}
131+
clusters.push(shadeColor(theme, 0.1))
132+
return clusters
133+
}
134+
}
135+
}
136+
</script>
137+
138+
<style>
139+
.theme-message,
140+
.theme-picker-dropdown {
141+
z-index: 99999 !important;
142+
}
143+
.theme-picker .el-color-picker__trigger {
144+
height: 26px !important;
145+
width: 26px !important;
146+
padding: 2px;
147+
}
148+
.theme-picker-dropdown .el-color-dropdown__link-btn {
149+
display: none;
150+
}
151+
</style>

web/src/core/element_lazy.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ import {
5858
Upload,
5959
Progress,
6060
MessageBox,
61-
Image
61+
Image,
62+
ColorPicker
6263
} from 'element-ui'
6364

6465
Vue.use(Button)
@@ -110,6 +111,7 @@ Vue.use(Progress)
110111
Vue.use(Scrollbar)
111112
Vue.use(Loading.directive)
112113
Vue.use(Image)
114+
Vue.use(ColorPicker)
113115

114116
Vue.prototype.$loading = Loading.service
115117
Vue.prototype.$message = Message

web/src/core/gin-vue-admin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import '../../node_modules/timeline-vuejs/dist/timeline-vuejs.css'
1111
// 路由守卫
1212
import Bus from '@/utils/bus'
1313
// 加载网站配置文件夹
14+
import '../style/element_visiable.scss' // 导入主题色配置
1415
import config from './config'
1516
Vue.prototype.$GIN_VUE_ADMIN = config
1617
Vue.use(Bus)

web/src/store/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import VuexPersistence from 'vuex-persist'
55
import { user } from '@/store/module/user'
66
import { router } from '@/store/module/router'
77
import { dictionary } from '@/store/module/dictionary'
8+
import { app } from '@/store/module/app'
89
Vue.use(Vuex)
910

1011
const vuexLocal = new VuexPersistence({
@@ -15,7 +16,8 @@ export const store = new Vuex.Store({
1516
modules: {
1617
user,
1718
router,
18-
dictionary
19+
dictionary,
20+
app
1921
},
2022
plugins: [vuexLocal.plugin]
2123
})

web/src/store/module/app.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import variables from '@/style/element_visiable.scss'
2+
export const app = {
3+
namespaced: true,
4+
state: {
5+
theme: variables.colorPrimary,
6+
sideMode: 'dark'
7+
},
8+
mutations: {
9+
CHANGETHEME: (state, value) => {
10+
state.theme = value
11+
},
12+
CHANGESIDEMODE: (state) => {
13+
if (state.sideMode === 'dark') {
14+
state.sideMode = 'light'
15+
} else {
16+
state.sideMode = 'dark'
17+
}
18+
}
19+
},
20+
actions: {
21+
changeTheme({ commit }, data) {
22+
commit('CHANGETHEME', data)
23+
},
24+
changeSideMode({ commit }) {
25+
commit('CHANGESIDEMODE')
26+
}
27+
},
28+
getters: {
29+
getSIdeMode(state) {
30+
return state.sideMode
31+
}
32+
}
33+
}

web/src/style/basics.scss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
// basice
23
$font-size: 14px;
34
$icon-size:17px;
@@ -14,10 +15,11 @@ $width-mobile-aside:210px;
1415
$color-aside:rgba(255, 255, 255,.9);
1516
$icon-arrow-size-aside:12px;
1617
$width-submenu-aside:55px;
17-
$bg-aside:#191a23;
18+
$bg-aside:#fff;
1819
$height-aside-tilte:64px;
1920
$height-aside-img:30px;
2021
$width-aside-img:30px;
22+
$aside-color:#000;
2123
// header
2224
$height-header: 60px;
2325
// nav-scroll
@@ -35,3 +37,8 @@ $height-car:68px;
3537
// mobile
3638
$padding-xs: 5px;
3739
$margin-xs: 5px;
40+
41+
:export{
42+
bg_aside : $bg-aside ;
43+
color_aside : $aside-color
44+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* 改变主题色变量 */
2+
$--color-primary: #1890ff;
3+
4+
/* 改变 icon 字体路径变量,必需 */
5+
$--font-path: '~element-ui/lib/theme-chalk/fonts';
6+
7+
8+
9+
@import "~element-ui/packages/theme-chalk/src/index";
10+
11+
12+
13+
:export {
14+
colorPrimary: $--color-primary
15+
}

0 commit comments

Comments
 (0)