美文网首页
vue-element-admin主题换肤

vue-element-admin主题换肤

作者: E1FANG | 来源:发表于2019-12-20 17:17 被阅读0次

预览:

http://e1fang.gitee.io/change-theme-preview

思路:

  1. themePicker切换主题
  2. vuex(改变state里的theme)
  3. app里判断theme 给最外层div加一个class名, class名用scss层层嵌套改css
  4. vuex分发theme状态到组件 组件内判断theme切换颜色json
  5. 目前最多支持三种主题切换

themePicker

两个主题选项切换 切换成功就弹出信息框并重定向页面帮助组件刷新

data() {
    return {
      themeOptions: [
        { label: 'bright', value: 'bright' },
        { label: 'dark', value: 'dark' }
      ]
    }
  },
  computed: {
    theme() {
      return this.$store.getters.theme
    }
  },
  methods: {
    changeTheme(theme) {
      this.$store.dispatch('app/setTheme', theme)
      console.log(theme)
      this.refreshView()
      this.$message({
        message: 'Switch Theme Success',
        type: 'success'
      })
    },
    refreshView() {
      const { fullPath } = this.$route
      console.log(fullPath)
      this.$nextTick(() => {
        this.$router.replace({
          path: '/redirect' + fullPath
        })
      })
    }
  }

app里动态绑定样式

将cssObj绑定到最外层div

computed: {
    classObj() {
      return {
        hideSidebar: !this.sidebar.opened,
        darkTheme: this.theme === 'dark'
      }
    },
    theme() {
      return this.$store.getters.theme
    }
  },

css覆盖

.darkTheme{
    .app-main{
        background: rgb(34, 41, 55) !important;  
    }
    .navbar{
        background: #2b3343 !important;
        //导航顶部文字
        .el-breadcrumb__inner span{
            color: white !important;
        }
        //顶部图表插件背景色
        .icon-wrapper{
            background: rgb(43,51,67) !important;
        }
        //显示侧边导航的图表填充
        svg{
            fill: rgb(216, 228, 238);
        }
    }
    //模块底部颜色
    .app-container {
        background: rgb(43,54,72);
        //模块字体颜色
        .p-wrapper{
            color: white !important;
        }
      }

    .scrollbar-wrapper {
        background:rgb(22,27,37);
        .el-tooltip{
            background: rgb(22, 27, 37);
        }
    }
    //百度地图背景色
    .bmap-wrapper{
        background: rgb(43,54,72);
        color:white;
    }
    //各模块loding遮罩颜色
    .el-loading-mask{
        background-color: rgba(90, 89, 89, 0.2) !important;
      }
}

组件内根据theme的值判断使用何种主题json

组件
...
import themeJson from '@/assets/json/theme.json'
...
data() {
  return {
    darkTheme: themeJson.darkTheme,
    brightTheme: themeJson.brightTheme,
  }
}

computed:{
  themeStyle() {
      if (this.theme === 'dark') {
        return this.darkTheme
      } else {
        return this.brightTheme
      }
    }
}
json
{
  "darkTheme": {
    "chartColor": {
      "bgColor": "rgb(43,54,72)",
      "fontColor": "white",   
      "tipbgColor":"rgb(43,54,72)",
      "tipfontColor": "white",
      "XaxisLine":"#a1aaff80",
      "xaxisLabel":"#ffffff99",
      "YsplitLine":"#a1aaff80",
      "YaxisLabel":"#ffffff99"
    }
  },
  "brightTheme": {
    "chartColor": {
      "bgColor": "white",
      "fontColor": "black",
      "tipbgColor":"white",
      "tipfontColor": "black",
      "XaxisLine":"black",
      "xaxisLabel":"black",
      "YsplitLine":"black",
      "YaxisLabel":"black"
    }
  }
}

相关文章

  • vue-element-admin主题换肤

    预览: http://e1fang.gitee.io/change-theme-preview 思路: theme...

  • 初步了解安卓的主题更换

    换肤一般分为两种:插件换肤和主题换肤 插件换肤就是所谓的apk换肤,将需要更换的属性写好打成apk包放在asset...

  • DarkMode(2):深色模式解决方案——css颜色变量实现D

    暗黑模式实现,最初的设计,就是参考之前的主题模式。所谓多套主题/配色/皮肤,就是我们很常见的换肤功能。换肤简单的实...

  • 主题 : 换肤框架.

    转载: ximsfei的博客地址:http://blog.csdn.net/ximsfei 1 背景 换肤方案原理...

  • iOSApp换肤(主题换肤、深浅色、自动换肤)

    iOS换肤 - 主题换肤、深浅色、自动换肤 各种情况下的效果,具体请看代码 使用方法: 1、将Lib文件夹下的 X...

  • 换肤

    换肤 1. 换肤的应用场景? 2. 换肤的实现方案 方案1 1. 将图片以及颜色按照主题命名,使用虚拟文件夹, 直...

  • 主题换肤的实现

    本文主要实现主题换肤的管理以及两个常用控件的封装 大致思路: 1.建立一个单例类(ThemeManager)专门用...

  • 换肤

    Android换肤功能 什么是换肤?app的皮肤,比如说黑夜模式,切换之后整体风格改变成以黑色为主题色 换了什么?...

  • Android 切换主题(基础)

    参考 1、Android 切换主题以及换肤的实现 截图 1、默认打开 2、点击【换主题色】 需知 主题色运用:ma...

  • Android 切换主题(基础)

    参考 1、Android 切换主题以及换肤的实现 截图 1、默认打开 2、点击【换主题色】 需知 主题色运用:ma...

网友评论

      本文标题:vue-element-admin主题换肤

      本文链接:https://www.haomeiwen.com/subject/juyinctx.html