xt-element-ui 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/demo.html +10 -1
- package/lib/index.common.js +281 -113
- package/lib/index.css +1 -1
- package/lib/index.umd.js +265 -137
- package/lib/index.umd.min.js +1 -1
- package/package.json +15 -13
- package/src/index.js +106 -10
- package/docs/.vuepress/config.js +0 -23
- package/docs/.vuepress/enhanceApp.js +0 -8
- package/docs/README.md +0 -6
- package/docs/components/base/button.md +0 -5
- package/docs/components/base/input.md +0 -22
- package/examples/App.vue +0 -13
- package/examples/favicon.ico +0 -0
- package/examples/index.html +0 -11
- package/examples/main.js +0 -9
- package/vue.config.js +0 -46
- /package/lib/fonts/{element-icons.ff18efd1.woff → element-icons.535877f5.woff} +0 -0
- /package/lib/fonts/{element-icons.f1a45d74.ttf → element-icons.732389de.ttf} +0 -0
package/src/index.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
// 导入 Vue
|
|
2
2
|
import Vue from 'vue'
|
|
3
3
|
|
|
4
|
+
// 在导入 Element UI 之前,先将 Vue 设置为全局变量
|
|
5
|
+
if (typeof window !== 'undefined') {
|
|
6
|
+
window.Vue = Vue
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
// 导入 Element UI 并注册
|
|
5
10
|
import ElementUI from 'element-ui'
|
|
6
11
|
import 'element-ui/lib/theme-chalk/index.css'
|
|
7
12
|
|
|
8
13
|
// 导入组件
|
|
9
|
-
|
|
10
|
-
|
|
11
14
|
import Button from './components/button'
|
|
12
15
|
import Input from './components/input'
|
|
13
16
|
|
|
@@ -31,7 +34,6 @@ const install = function (Vue) {
|
|
|
31
34
|
})
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
|
|
35
37
|
// 支持全局 script 标签引入
|
|
36
38
|
if (typeof window !== 'undefined' && window.Vue) {
|
|
37
39
|
install(window.Vue)
|
|
@@ -50,25 +52,119 @@ export default {
|
|
|
50
52
|
// 导出 Vue 和 ElementUI 以便用户使用
|
|
51
53
|
export { Vue, ElementUI }
|
|
52
54
|
|
|
53
|
-
//
|
|
55
|
+
// 默认配置
|
|
56
|
+
const defaultConfig = {
|
|
57
|
+
theme: 'light',
|
|
58
|
+
size: 'medium',
|
|
59
|
+
primaryColor: '#1890ff'
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 当前配置
|
|
63
|
+
let currentConfig = { ...defaultConfig }
|
|
64
|
+
|
|
65
|
+
// 配置变更事件处理
|
|
66
|
+
const configChangeListeners = []
|
|
67
|
+
|
|
68
|
+
const emitConfigChange = function(key, value) {
|
|
69
|
+
configChangeListeners.forEach(listener => {
|
|
70
|
+
listener(key, value)
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 获取所有配置
|
|
75
|
+
export const getConfig = function() {
|
|
76
|
+
return { ...currentConfig }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 设置全局配置
|
|
80
|
+
export const setConfig = function(config) {
|
|
81
|
+
if (typeof config !== 'object' || config === null) {
|
|
82
|
+
console.warn('[XtElementUI] setConfig 必须传入对象参数')
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (config.theme !== undefined) {
|
|
87
|
+
setTheme(config.theme)
|
|
88
|
+
}
|
|
89
|
+
if (config.size !== undefined) {
|
|
90
|
+
setSize(config.size)
|
|
91
|
+
}
|
|
92
|
+
if (config.primaryColor !== undefined) {
|
|
93
|
+
setPrimaryColor(config.primaryColor)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 设置主题
|
|
54
98
|
export const setTheme = function(theme) {
|
|
55
99
|
const validThemes = ['light', 'dark', 'compact']
|
|
56
|
-
if (validThemes.includes(theme)) {
|
|
57
|
-
|
|
100
|
+
if (!validThemes.includes(theme)) {
|
|
101
|
+
console.warn(`[XtElementUI] 无效的主题值: ${theme},可选值: ${validThemes.join(', ')}`)
|
|
102
|
+
return
|
|
58
103
|
}
|
|
104
|
+
|
|
105
|
+
currentConfig.theme = theme
|
|
106
|
+
document.documentElement.setAttribute('data-theme', theme)
|
|
107
|
+
emitConfigChange('theme', theme)
|
|
59
108
|
}
|
|
60
109
|
|
|
110
|
+
// 设置字体大小
|
|
61
111
|
export const setSize = function(size) {
|
|
62
112
|
const validSizes = ['small', 'medium', 'large']
|
|
63
|
-
if (validSizes.includes(size)) {
|
|
64
|
-
|
|
113
|
+
if (!validSizes.includes(size)) {
|
|
114
|
+
console.warn(`[XtElementUI] 无效的大小值: ${size},可选值: ${validSizes.join(', ')}`)
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
currentConfig.size = size
|
|
119
|
+
document.documentElement.setAttribute('data-size', size)
|
|
120
|
+
emitConfigChange('size', size)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 设置主色调
|
|
124
|
+
export const setPrimaryColor = function(color) {
|
|
125
|
+
// 简单的颜色格式验证
|
|
126
|
+
const colorRegex = /^#[0-9A-Fa-f]{6}$|^#[0-9A-Fa-f]{3}$/
|
|
127
|
+
if (!colorRegex.test(color)) {
|
|
128
|
+
console.warn(`[XtElementUI] 无效的颜色值: ${color},请使用十六进制颜色格式,如 #1890ff`)
|
|
129
|
+
return
|
|
65
130
|
}
|
|
131
|
+
|
|
132
|
+
currentConfig.primaryColor = color
|
|
133
|
+
document.documentElement.style.setProperty('--xt-color-primary', color)
|
|
134
|
+
emitConfigChange('primaryColor', color)
|
|
66
135
|
}
|
|
67
136
|
|
|
137
|
+
// 获取当前主题
|
|
68
138
|
export const getTheme = function() {
|
|
69
|
-
return
|
|
139
|
+
return currentConfig.theme
|
|
70
140
|
}
|
|
71
141
|
|
|
142
|
+
// 获取当前字体大小
|
|
72
143
|
export const getSize = function() {
|
|
73
|
-
return
|
|
144
|
+
return currentConfig.size
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// 获取当前主色调
|
|
148
|
+
export const getPrimaryColor = function() {
|
|
149
|
+
return currentConfig.primaryColor
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// 重置为默认配置
|
|
153
|
+
export const resetConfig = function() {
|
|
154
|
+
setConfig(defaultConfig)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// 监听配置变更
|
|
158
|
+
export const onConfigChange = function(listener) {
|
|
159
|
+
if (typeof listener === 'function') {
|
|
160
|
+
configChangeListeners.push(listener)
|
|
161
|
+
return function() {
|
|
162
|
+
const index = configChangeListeners.indexOf(listener)
|
|
163
|
+
if (index > -1) {
|
|
164
|
+
configChangeListeners.splice(index, 1)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
console.warn('[XtElementUI] onConfigChange 必须传入函数')
|
|
169
|
+
}
|
|
74
170
|
}
|
package/docs/.vuepress/config.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
title: '组件文档',
|
|
3
|
-
themeConfig: {
|
|
4
|
-
nav: [
|
|
5
|
-
{ text: '首页', link: '/' },
|
|
6
|
-
{ text: '组件', link: '/components/base/button' }
|
|
7
|
-
],
|
|
8
|
-
sidebarDepth: 2,
|
|
9
|
-
nextLinks: true,
|
|
10
|
-
prevLinks: true,
|
|
11
|
-
// 直接写完整路径,最稳、最简单、不踩坑
|
|
12
|
-
sidebar: [
|
|
13
|
-
{
|
|
14
|
-
title: '基础组件',
|
|
15
|
-
path: '/components/base/button',
|
|
16
|
-
children: [
|
|
17
|
-
['/components/base/button', '按钮'],
|
|
18
|
-
['/components/base/input', '输入框']
|
|
19
|
-
]
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
}
|
|
23
|
-
}
|
package/docs/README.md
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# Input 输入框
|
|
2
|
-
|
|
3
|
-
基于 el-input 封装的统一输入框
|
|
4
|
-
|
|
5
|
-
## 基础用法
|
|
6
|
-
<xt-input v-model="inputVal" placeholder="请输入内容"></xt-input>
|
|
7
|
-
|
|
8
|
-
<script>
|
|
9
|
-
export default {
|
|
10
|
-
data() {
|
|
11
|
-
return {
|
|
12
|
-
inputVal: ''
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
</script>
|
|
17
|
-
|
|
18
|
-
## 属性
|
|
19
|
-
| 参数 | 说明 | 类型 | 默认值 |
|
|
20
|
-
| --- | --- | --- | --- |
|
|
21
|
-
| v-model | 绑定值 | string / number | - |
|
|
22
|
-
| placeholder | 占位符 | string | '请输入内容' |
|
package/examples/App.vue
DELETED
package/examples/favicon.ico
DELETED
|
Binary file
|
package/examples/index.html
DELETED
package/examples/main.js
DELETED
package/vue.config.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
// 关闭生产环境 sourcemap
|
|
3
|
-
productionSourceMap: false,
|
|
4
|
-
// 单页面标准入口配置
|
|
5
|
-
pages: {
|
|
6
|
-
index: {
|
|
7
|
-
entry: './examples/main.js', // 你的项目启动入口
|
|
8
|
-
template: './examples/index.html',
|
|
9
|
-
filename: 'index.html'
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
css: {
|
|
13
|
-
// 开启 CSS 提取(打包成独立 css 文件,给 npm 使用)
|
|
14
|
-
extract: true,
|
|
15
|
-
// 启用 CSS sourcemap
|
|
16
|
-
sourceMap: false,
|
|
17
|
-
// 给 scss 传入全局变量(主题色、字体大小)
|
|
18
|
-
loaderOptions: {
|
|
19
|
-
scss: {
|
|
20
|
-
// 这里可以自动注入全局 SCSS 变量文件(非常重要)
|
|
21
|
-
additionalData: `@import "~@/styles/variables.scss";`
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
// 组件库打包配置
|
|
27
|
-
chainWebpack: (config) => {
|
|
28
|
-
if (process.env.NODE_ENV === "production") {
|
|
29
|
-
// 入口改为组件库总入口
|
|
30
|
-
config.entry("index").clear().add("./src/index.js").end();
|
|
31
|
-
|
|
32
|
-
// 输出 UMD 格式(支持 npm / script 引入)
|
|
33
|
-
config.output
|
|
34
|
-
.filename("index.js")
|
|
35
|
-
.library("xt-element-ui")
|
|
36
|
-
.libraryTarget("umd")
|
|
37
|
-
.umdNamedDefine(true);
|
|
38
|
-
|
|
39
|
-
// 只在生产环境配置 externals(打包组件库时不打包 Vue 和 Element UI)
|
|
40
|
-
config.externals({
|
|
41
|
-
vue: "Vue",
|
|
42
|
-
"element-ui": "ElementUI",
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
};
|
|
File without changes
|
|
File without changes
|