Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加切换任意主题色的功能 #1307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"vuedraggable": "^2.16.0",
"vuex": "^3.0.1",
"wangeditor": "^3.1.1",
"webpack-theme-color-replacer": "^1.2.15",
"xlsx": "^0.13.3"
},
"devDependencies": {
Expand Down
48 changes: 48 additions & 0 deletions src/components/main/components/change-theme/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<ColorPicker class="change-theme" v-model="primaryColor" @input="changeThemeColor"/>
</template>

<script>
import client from 'webpack-theme-color-replacer/client'
import colorUtil from 'webpack-theme-color-replacer/forElementUI'

export default {
data () {
return {
primaryColor: localStorage.getItem('theme_color') || '#2d8cf0'
}
},
created () {
this.changeThemeColor(this.primaryColor)
},
methods: {
changeThemeColor (primaryColor) {
let options = {
newColors: colorUtil.getElementUISeries(primaryColor).concat('#fff'),
changeUrl (cssUrl) {
return `/${cssUrl}` // while router is not `hash` mode, it needs absolute path
}
}
client.changer.changeColor(options, Promise).then(t => {
localStorage.setItem('theme_color', primaryColor)
})
}
}
}
</script>

<style lang="less" scoped>
.change-theme {
/deep/ .ivu-color-picker-input {
width: 34px;
cursor: pointer;
border-color: transparent;
padding-right: 8px;
margin-right: 4px;
}

/deep/ .ivu-icon-ios-arrow-down {
display: none;
}
}
</style>
3 changes: 3 additions & 0 deletions src/components/main/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<language v-if="$config.useI18n" @on-lang-change="setLocal" style="margin-right: 10px;" :lang="local"/>
<error-store v-if="$config.plugin['error-store'] && $config.plugin['error-store'].showInHeader" :has-read="hasReadErrorPage" :count="errorCount"></error-store>
<fullscreen v-model="isFullscreen" style="margin-right: 10px;"/>
<change-theme></change-theme>
</header-bar>
</Header>
<Content class="main-content-con">
Expand All @@ -41,6 +42,7 @@ import TagsNav from './components/tags-nav'
import User from './components/user'
import ABackTop from './components/a-back-top'
import Fullscreen from './components/fullscreen'
import ChangeTheme from './components/change-theme'
import Language from './components/language'
import ErrorStore from './components/error-store'
import { mapMutations, mapActions, mapGetters } from 'vuex'
Expand All @@ -57,6 +59,7 @@ export default {
Language,
TagsNav,
Fullscreen,
ChangeTheme,
ErrorStore,
User,
ABackTop
Expand Down
18 changes: 17 additions & 1 deletion vue.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const ThemeColorReplacer = require('webpack-theme-color-replacer')
const colorUtil = require('webpack-theme-color-replacer/forElementUI')

const path = require('path')

const resolve = dir => {
Expand Down Expand Up @@ -35,9 +38,22 @@ module.exports = {
.set('_c', resolve('src/components'))
},
// 设为false打包时不生成.map文件
productionSourceMap: false
productionSourceMap: false,
// 这里写你调用接口的基础路径,来解决跨域,如果设置了代理,那你本地开发环境的axios的baseUrl要写为 '' ,即空字符串
// devServer: {
// proxy: 'localhost:3000'
// }

configureWebpack: {
plugins: [
new ThemeColorReplacer({
fileName: 'css/theme-colors-[contenthash:8].css',
matchColors: colorUtil.getElementUISeries('#2d8cf0').concat('#fff'), // 主色系列
// 改变样式选择器,解决样式覆盖问题
changeSelector (selector) {
return selector
}
})
]
}
}