README.md
3.94 KB
介绍
当前UI组件库是基于element二次封装的的组件,当前的"element-ui": "2.15.6",vue版本"2.6.11",适用于 Vue 2 开发。
npm 安装
推荐使用 npm 的方式安装,它能更好地和 webpack 打包工具配合使用。
npm i glsx-components -S
快速上手
本节将介绍如何在项目中使用 glsx-components
引入 glsx-components
你可以根据需要仅引入部分组件,但是样式文件还是要引入哦。我们先介绍如何引入glsx-components。
全部引入
在 main.js 中写入以下内容:
import Vue from 'vue';
import GlComponents from 'glsx-components';
import 'glsx-components/dist/glsx-components.css';
import App from './App.vue';
Vue.use(GlComponents);
new Vue({
el: '#app',
render: h => h(App)
});
以上代码便完成了 glsx-components 的引入。需要注意的是,样式文件需要单独引入。
按需引入
接下来,如果你只希望引入部分组件,比如 Button,那么需要在 main.js 中写入以下内容:
在 main.js 中写入以下内容:
import Vue from 'vue';
import { GLButton } from 'glsx-components';
import 'glsx-components/dist/glsx-components.css';
import App from './App.vue';
// 全局组件
Vue.component(GLButton.name, GLButton);
/* 或写为
* Vue.use(GLButton)
*/
new Vue({
el: '#app',
render: h => h(App)
});
项目结构
├─build // gulp的配置文件
├─documents // 自动生文档静态站点所依赖的库
├─node_modules
├─public // html入口
├─src // 源码目录
├─assets // 静态资源
├─components
├─directives // 自定义指令
├─filters // 自定义过滤器
├─localtest // 用本地打包后的组件 文件测试 umd
├─packages // 封装的组件源码
├─plugins // 使用的插件目录 目前只有element
├─theme // 主题样式
├─utils // 工具函数, 主题切换等
├─App.vue
├─index.js // 组件载入的入口 仅用于本地测试 npm run serve
└─main.js // 项目入口
├─website // 组件文档静态资源网站
├─.browserslistrc
├─.gitignore
├─gulpfile.js // 生成组件文档的gulp配置
├─...
├─babel.config
├─package.json
├─vue.config.js // 项目打包的一些配置
└─README.md
自定义主题
产品 SaaS 化,通常需要有换肤功能,所以我们也实现了一套,主题色及其衍生色(高亮、浅色)的更换功能。通过尝试我们采取的方案是 Scss变量+css变量的方式,这种方式也是目前社区采用的最普遍的一种方式,兼容性良好。
实现的原理
通过接口获取主题色(或者设置主题色) --> js 计算衍生色值 --> 赋值到 css 变量 --> scss 全局变量用 var() 函数引入 css 变量 --> 页面样式引用 scss 全局颜色值
使用栗子
比如我们要在Saas使用(scrm项目采用微前端乾坤+Vue2.x的方式)
主应用的使用
import { convertTheme } from 'glsx-components/src/utils/convertTheme'
//路由守卫
router.beforeEach(async (to, from, next) => {
//设置主题色(flag的目的是为了防止多次设置 主题色)
if (!flag) {
//假设我们在原型上定义了一个颜色,反正就是传入一个颜色,如 #456743
console.log('Vue.prototype.$themeColor',Vue.prototype.$themeColor)
convertTheme(Vue.prototype.$themeColor)
flag = true
}
beforeEachFn(to, from, next)
})





