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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<template>
<span v-if="themeBar">
<vab-icon title="主题配置" :icon="['fas', 'palette']" @click="handleChangeTheme" />
<div class="theme-bar-setting">
<div @click="handleChangeTheme">
<vab-icon :icon="['fas', 'palette']" />
<p>主题配置</p>
</div>
<div @click="handleGetCode">
<vab-icon :icon="['fas', 'laptop-code']"></vab-icon>
<p>拷贝代码</p>
</div>
<!--<div @click="handleChangeQq">
<vab-remix-icon icon-class="qq-fill" />
<p>学习交流</p>
</div>-->
</div>
<el-drawer
title="主题配置"
:visible.sync="drawerVisible"
direction="rtl"
append-to-body
size="300px"
>
<el-scrollbar style="height: 94vh; overflow: hidden;">
<div class="el-drawer__body">
<el-form ref="form" :model="theme">
<el-form-item label="布局">
<el-radio-group v-model="theme.layout">
<el-radio-button label="vertical">纵向布局</el-radio-button>
<el-radio-button label="horizontal">横向布局</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="头部">
<el-radio-group v-model="theme.header">
<el-radio-button label="fixed">固定头部</el-radio-button>
<el-radio-button label="noFixed">不固定头部</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="多标签">
<el-radio-group v-model="theme.tagsBar">
<el-radio-button label="true">开启</el-radio-button>
<el-radio-button label="false">不开启</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="菜单背景色">
<el-color-picker
v-model="theme.menuBackground"
:predefine="[
'#2a58ad',
'#001529',
'#f56c6c',
'#0fd59d',
'#3fb884',
'#ff7a47',
'#a80505',
]"
show-alpha
></el-color-picker>
</el-form-item>
<el-form-item label="菜单子级背景色">
<el-color-picker
v-model="theme.menuChildrenBackground"
:predefine="[
'#2a58ad',
'#001529',
'#f56c6c',
'#0fd59d',
'#3fb884',
'#ff7a47',
'#a80505',
]"
show-alpha
></el-color-picker>
</el-form-item>
<el-form-item label="菜单选中色">
<el-color-picker
v-model="theme.menuBackgroundActive"
:predefine="['#22468a', '#1890ff', '#21e6af', '#f57e6c']"
show-alpha
></el-color-picker>
</el-form-item>
<el-form-item label="菜单文字色">
<el-color-picker v-model="theme.menuColor" :predefine="['#000', '#fff']" show-alpha></el-color-picker>
</el-form-item>
<el-form-item label="标签主题色">
<el-color-picker
v-model="theme.tagsBarBackgroundActive"
:predefine="['#1890ff', '#0fd59d', '#f56c6c']"
show-alpha
></el-color-picker>
</el-form-item>
<el-form-item label="默认按钮主题色">
<el-color-picker
v-model="theme.buttonBackground"
:predefine="['#1890ff', '#0fd59d', '#f56c6c']"
show-alpha
></el-color-picker>
</el-form-item>
<el-form-item label="分页选中色">
<el-color-picker
v-model="theme.paginationBackgroundActive"
:predefine="['#1890ff', '#0fd59d', '#f56c6c']"
show-alpha
></el-color-picker>
</el-form-item>
<el-form-item>
<el-button @click="handleSetDfaultTheme">恢复默认</el-button>
<el-button type="primary" @click="handleSaveTheme">保存</el-button>
</el-form-item>
</el-form>
</div>
</el-scrollbar>
</el-drawer>
</span>
</template>
<script>
import variables from "@/styles/variables.scss";
import { mapGetters } from "vuex";
import GetCode from "@/layouts/mixin/GetCode";
export default {
name: "ThemeBar",
mixins: [GetCode],
data() {
return {
drawerVisible: false,
theme: {
layout: "",
header: "",
tagsBar: "",
menuBackground: variables["menu-background"],
menuChildrenBackground: variables["menu-children-background"],
menuBackgroundActive: variables["menu-background-active"],
menuColor: variables["menu-color"],
tagsBarBackgroundActive: variables["tags-bar-background-active"],
buttonBackground: variables["button-background"],
paginationBackgroundActive: variables["pagination-background-active"],
},
};
},
computed: {
...mapGetters({
layout: "settings/layout",
header: "settings/header",
tagsBar: "settings/tagsBar",
themeBar: "settings/themeBar",
}),
},
mounted() {},
created() {
this.$baseEventBus.$on("theme", () => {
this.handleChangeTheme();
});
const theme = localStorage.getItem("BYUI-VUE-THEME");
this.theme.layout = this.layout;
this.theme.header = this.header;
this.theme.tagsBar = this.tagsBar;
if (null !== theme) {
this.$set(this.theme, "menuBackground", JSON.parse(theme).menuBackground);
this.$set(
this.theme,
"menuChildrenBackground",
JSON.parse(theme).menuChildrenBackground
);
this.$set(
this.theme,
"menuBackgroundActive",
JSON.parse(theme).menuBackgroundActive
);
this.$set(this.theme, "menuColor", JSON.parse(theme).menuColor);
this.$set(
this.theme,
"tagsBarBackgroundActive",
JSON.parse(theme).tagsBarBackgroundActive
);
this.$set(
this.theme,
"buttonBackground",
JSON.parse(theme).buttonBackground
);
this.$set(
this.theme,
"paginationBackgroundActive",
JSON.parse(theme).paginationBackgroundActive
);
this.handleSetTheme();
}
},
methods: {
handleChangeTheme() {
this.drawerVisible = true;
},
handleChangeQq() {
window.open("tencent://message/?uin=1204505056");
},
handleSetTheme() {
let {
layout,
header,
tagsBar,
menuBackground,
menuChildrenBackground,
menuBackgroundActive,
menuColor,
tagsBarBackgroundActive,
buttonBackground,
paginationBackgroundActive,
} = this.theme;
let style = document.createElement("style");
style.id = "BYUI-VUE-THEME";
style.innerHTML = `
.top-bar-container,
.top-bar-container .vab-main,
.side-bar-container,
.logo-container-vertical,
.logo-container-horizontal,
.el-menu,
.el-menu-item,
.el-submenu.is-active.is-opened,
.el-submenu__title,
.el-menu-item.is-active,
.el-menu-item .is-active {
background-color:${menuBackground}!important;
}
body .el-menu--horizontal .top-bar-item-container .el-menu-item:hover,
body .el-menu--horizontal .top-bar-item-container .el-menu-item.is-active,
body .vue-admin-beautiful-wrapper .side-bar-container .el-submenu .el-menu-item.is-active,
body .vue-admin-beautiful-wrapper .side-bar-container .el-menu-item:hover,
body .side-bar-container .el-menu .el-menu-item.is-active {
background-color:${menuBackgroundActive}!important;
}
.tags-bar-item.router-link-exact-active.router-link-active.active {
background-color: ${tagsBarBackgroundActive}!important;
border: 1px solid ${tagsBarBackgroundActive}!important;
}
.vab-main .tags-bar-container .tags-content .el-tabs__header .el-tabs__item.is-active {
background: ${tagsBarBackgroundActive}!important;
border: 1px solid ${tagsBarBackgroundActive}!important;
}
.el-button.el-button--primary {
background-color: ${buttonBackground}!important;
border-color: ${buttonBackground}!important;
}
.el-pagination.is-background .el-pager li:not(.disabled).active {
background-color: ${paginationBackgroundActive}!important;
border-color: ${paginationBackgroundActive}!important;
}
body .vue-admin-beautiful-wrapper .side-bar-container .nest-menu .el-menu-item {
background-color: ${menuChildrenBackground}!important;
}
body .vue-admin-beautiful-wrapper .side-bar-container .el-menu .nest-menu [class*=menu] {
background-color: ${menuChildrenBackground}!important
}
body .vue-admin-beautiful-wrapper .side-bar-container .el-menu .nest-menu [class*=menu].is-active {
background-color:${menuBackgroundActive}!important
}
body .vue-admin-beautiful-wrapper .side-bar-container .el-menu [class*=menu] span,
body .vue-admin-beautiful-wrapper .side-bar-container .el-menu [class*=menu] svg,
body .vue-admin-beautiful-wrapper .side-bar-container .el-menu [class*=menu] i
{
color:${menuColor}!important
}
`;
document.getElementsByTagName("head").item(0).appendChild(style);
localStorage.setItem(
"BYUI-VUE-THEME",
`{
"menuBackground":"${menuBackground}",
"menuChildrenBackground":"${menuChildrenBackground}",
"menuBackgroundActive":"${menuBackgroundActive}",
"menuColor":"${menuColor}",
"tagsBarBackgroundActive":"${tagsBarBackgroundActive}",
"layout":"${layout}",
"header":"${header}",
"tagsBar":"${tagsBar}",
"buttonBackground":"${buttonBackground}",
"paginationBackgroundActive":"${paginationBackgroundActive}"
}`
);
this.handleSwitchLayout(layout);
this.handleSwitchHeader(header);
this.handleSwitchTagsBar(tagsBar);
this.drawerVisible = false;
},
handleSaveTheme() {
this.handleSetTheme();
location.reload();
},
handleSetDfaultTheme() {
localStorage.removeItem("BYUI-VUE-THEME");
this.$store.dispatch("settings/changeLayout", this.theme.layout);
this.$refs["form"].resetFields();
Object.assign(this.$data, this.$options.data());
this.drawerVisible = false;
location.reload();
},
handleSwitchLayout(layout) {
this.$store.dispatch("settings/changeLayout", layout);
},
handleSwitchHeader(header) {
this.$store.dispatch("settings/changeHeader", header);
},
handleSwitchTagsBar(tagsBar) {
this.$store.dispatch("settings/changeTagsBar", tagsBar);
},
},
};
</script>
<style lang="scss" scoped>
@mixin right-bar {
position: fixed;
right: 0;
z-index: $base-z-index;
width: 60px;
min-height: 60px;
text-align: center;
cursor: pointer;
background: $base-color-blue;
border-radius: $base-border-radius;
> div {
padding-top: 10px;
border-bottom: 1px solid $base-color-white;
&:hover {
opacity: 0.9;
}
p {
font-size: $base-font-size-small;
line-height: 30px;
color: $base-color-white;
}
}
}
.theme-bar-setting {
@include right-bar;
top: 40vh;
::v-deep {
svg:not(:root).svg-inline--fa {
display: block;
margin-right: auto;
margin-left: auto;
color: $base-color-white;
}
.svg-icon {
display: block;
margin-right: auto !important;
margin-left: auto !important;
font-size: 20px !important;
color: $base-color-white !important;
fill: $base-color-white !important;
}
}
}
.el-drawer__body {
padding: 20px;
}
</style>