v-uni-app-ui 1.0.0 → 1.0.4
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/README.md +147 -0
- package/components/config/css/basic.scss +19 -0
- package/components/config/interface/basic-type.js +16 -0
- package/components/config/interface/components-interface.ts +0 -0
- package/components/config/interface/monitor/components/input-monitor.js +0 -0
- package/components/config/interface/monitor/property-monitor.ts +136 -0
- package/components/config/interface/props/basic-props.ts +88 -0
- package/components/config/interface/props/components/button-props.ts +85 -0
- package/components/config/interface/props/components/input-props.ts +69 -0
- package/components/config/interface/props/props-tools.ts +64 -0
- package/components/config/style/basic.js +346 -0
- package/components/config/style/component-registry.js +142 -0
- package/components/config/style/components/button-style.js +160 -0
- package/components/config/style/components/input-style.js +98 -0
- package/components/config/style/components-style.js +622 -0
- package/components/config/style/property-mapper.js +377 -0
- package/components/config/style/pseudo-processor.js +213 -0
- package/components/config.js +123 -0
- package/components/icon/iconfont.css +87 -0
- package/components/icon/iconfont.js +1 -0
- package/components/icon/iconfont.json +135 -0
- package/components/icon/iconfont.ttf +0 -0
- package/components/icon/iconfont.woff +0 -0
- package/components/icon/iconfont.woff2 +0 -0
- package/components/layout/v-card/v-card.vue +108 -0
- package/components/layout/v-grid/v-grid.vue +162 -0
- package/components/layout/v-icon-grid/v-icon-grid.vue +195 -0
- package/components/layout/v-infinite-scroll/v-infinite-scroll.vue +172 -0
- package/components/layout/v-list/v-list.vue +43 -0
- package/components/layout/v-row/v-row.vue +142 -0
- package/components/layout/v-waterfall/v-waterfall.vue +79 -0
- package/components/model/compound/v-checkbox-group/v-checkbox-group.vue +96 -0
- package/components/model/compound/v-console/v-console.js +20 -0
- package/components/model/compound/v-console/v-console.vue +299 -0
- package/components/model/compound/v-date-time/v-date-time.vue +261 -0
- package/components/model/compound/v-dialog/v-dialog.vue +178 -0
- package/components/model/compound/v-drum-select-picker/v-drum-select-picker.vue +83 -0
- package/components/model/compound/v-form/v-form.vue +226 -0
- package/components/model/compound/v-form-item/v-form-item.vue +255 -0
- package/components/model/compound/v-image/v-image.vue +357 -0
- package/components/model/compound/v-input-desensitize/v-input-desensitize.vue +101 -0
- package/components/model/compound/v-page/v-page.vue +11 -0
- package/components/model/compound/v-pages/v-pages.vue +141 -0
- package/components/model/compound/v-picker-list/v-picker-list.vue +109 -0
- package/components/model/compound/v-popup/v-popup.vue +151 -0
- package/components/model/compound/v-radio-group/v-radio-group.vue +86 -0
- package/components/model/compound/v-select-picker/v-select-picker.vue +202 -0
- package/components/model/compound/v-series-picker-list/v-series-picker-list.vue +221 -0
- package/components/model/compound/v-series-select-picker/v-series-select-picker.vue +203 -0
- package/components/model/compound/v-switch/v-switch.vue +136 -0
- package/components/model/compound/v-tabs-page/v-tabs-page.vue +138 -0
- package/components/model/native/v-badge/v-badge.vue +143 -0
- package/components/model/native/v-button/v-button.vue +81 -0
- package/components/model/native/v-carousel/v-carousel.vue +138 -0
- package/components/model/native/v-checkbox/v-checkbox.vue +215 -0
- package/components/model/native/v-collapse/v-collapse.vue +190 -0
- package/components/model/native/v-header-navigation-bar/v-header-navigation-bar.vue +92 -0
- package/components/model/native/v-input/v-input.vue +163 -0
- package/components/model/native/v-input-code/v-input-code.vue +146 -0
- package/components/model/native/v-loading/v-loading.vue +206 -0
- package/components/model/native/v-menu/v-menu.vue +222 -0
- package/components/model/native/v-menu-slide/v-menu-slide.vue +364 -0
- package/components/model/native/v-min-loading/v-min-loading.vue +80 -0
- package/components/model/native/v-null/v-null.vue +97 -0
- package/components/model/native/v-overlay/v-overlay.vue +96 -0
- package/components/model/native/v-pull-up-refresh/v-pull-up-refresh.vue +157 -0
- package/components/model/native/v-radio/v-radio.vue +138 -0
- package/components/model/native/v-scroll-list/v-scroll-list.vue +169 -0
- package/components/model/native/v-steps/v-steps.vue +253 -0
- package/components/model/native/v-table/v-table.vue +203 -0
- package/components/model/native/v-tabs/v-tabs.vue +235 -0
- package/components/model/native/v-tag/v-tag.vue +206 -0
- package/components/model/native/v-text/v-text.vue +187 -0
- package/components/model/native/v-textarea/v-textarea.vue +178 -0
- package/components/model/native/v-title/v-title.vue +91 -0
- package/components/model/native/v-toast/info.png +0 -0
- package/components/model/native/v-toast/success.png +0 -0
- package/components/model/native/v-toast/v-toast.vue +198 -0
- package/components/model/native/v-toast/warn.png +0 -0
- package/components/model/native/v-upload-file-button/v-upload-file-button.vue +296 -0
- package/components/model/native/v-video/v-video.vue +175 -0
- package/components/model/native/v-window/v-window.vue +158 -0
- package/components/utils/event-modifiers.ts +139 -0
- package/components/utils/validator.ts +451 -0
- package/index.js +372 -0
- package/package.json +25 -93
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import {
|
|
2
|
+
styleConfig
|
|
3
|
+
} from '@/components/config/style/basic.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 属性映射规则配置
|
|
7
|
+
* 定义属性名如何映射到样式
|
|
8
|
+
*/
|
|
9
|
+
export const PropertyMappingRules = {
|
|
10
|
+
// 通用属性映射规则
|
|
11
|
+
common: {
|
|
12
|
+
// 尺寸属性 - 映射到尺寸相关的样式
|
|
13
|
+
size: {
|
|
14
|
+
target: 'size',
|
|
15
|
+
transform: (value, componentConfig, props) => {
|
|
16
|
+
return componentConfig.size && componentConfig.size[value] ?
|
|
17
|
+
componentConfig.size[value] :
|
|
18
|
+
null
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
// 类型属性 - 映射到类型相关的样式
|
|
23
|
+
type: {
|
|
24
|
+
target: 'type',
|
|
25
|
+
transform: (value, componentConfig, props) => {
|
|
26
|
+
const typeKey = otherTypeClassName(props, value)
|
|
27
|
+
return componentConfig.type && componentConfig.type[typeKey] ?
|
|
28
|
+
componentConfig.type[typeKey] :
|
|
29
|
+
null
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
// 形状/模型属性 - 映射到形状相关的样式
|
|
34
|
+
shape: {
|
|
35
|
+
target: 'shape',
|
|
36
|
+
transform: (value, componentConfig) => {
|
|
37
|
+
return componentConfig.shape && componentConfig.shape[value] ?
|
|
38
|
+
componentConfig.shape[value] :
|
|
39
|
+
null
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
// 状态属性 - 映射到状态相关的样式
|
|
44
|
+
disabled: {
|
|
45
|
+
target: 'status',
|
|
46
|
+
transform: (value, componentConfig) => {
|
|
47
|
+
if (!value) return null
|
|
48
|
+
return componentConfig.status && componentConfig.status.disabled ?
|
|
49
|
+
componentConfig.status.disabled : {
|
|
50
|
+
opacity: styleConfig.basic.opacity.disabled,
|
|
51
|
+
cursor: 'not-allowed'
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
loading: {
|
|
57
|
+
target: 'status',
|
|
58
|
+
transform: (value, componentConfig) => {
|
|
59
|
+
if (!value) return null
|
|
60
|
+
return componentConfig.status && componentConfig.status.loading ?
|
|
61
|
+
componentConfig.status.loading : {
|
|
62
|
+
opacity: styleConfig.basic.opacity.disabled,
|
|
63
|
+
cursor: 'progress'
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
// 变体属性
|
|
69
|
+
variant: {
|
|
70
|
+
target: 'variant',
|
|
71
|
+
transform: (value, componentConfig) => {
|
|
72
|
+
return componentConfig.variant && componentConfig.variant[value] ?
|
|
73
|
+
componentConfig.variant[value] :
|
|
74
|
+
null
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
// 布尔属性
|
|
79
|
+
block: {
|
|
80
|
+
target: 'overrides',
|
|
81
|
+
transform: (value, componentConfig) => {
|
|
82
|
+
if (!value) return null
|
|
83
|
+
return componentConfig.overrides && componentConfig.overrides.block ?
|
|
84
|
+
componentConfig.overrides.block : {
|
|
85
|
+
width: '100%',
|
|
86
|
+
display: 'flex'
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
iconOnly: {
|
|
92
|
+
target: 'overrides',
|
|
93
|
+
transform: (value, componentConfig) => {
|
|
94
|
+
if (!value) return null
|
|
95
|
+
return componentConfig.overrides && componentConfig.overrides.iconOnly ?
|
|
96
|
+
componentConfig.overrides.iconOnly : {
|
|
97
|
+
padding: '0',
|
|
98
|
+
display: 'flex',
|
|
99
|
+
alignItems: 'center',
|
|
100
|
+
justifyContent: 'center'
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
plain: {
|
|
106
|
+
target: 'type',
|
|
107
|
+
transform: () => null
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
text: {
|
|
111
|
+
target: 'type',
|
|
112
|
+
transform: () => null
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
// 组件特定的属性映射规则(可以覆盖通用规则)
|
|
117
|
+
componentSpecific: {
|
|
118
|
+
button: {
|
|
119
|
+
// 按钮特有的属性映射
|
|
120
|
+
stabilizationTime: {
|
|
121
|
+
target: 'custom',
|
|
122
|
+
transform: (value) => value > 0 ? {
|
|
123
|
+
transition: 'all 0.3s ease'
|
|
124
|
+
} : null
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function otherTypeClassName(props, value) {
|
|
131
|
+
// 处理镂空类型
|
|
132
|
+
if (props.plain) {
|
|
133
|
+
return `${value}-plain`
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 处理文本类型
|
|
137
|
+
if (props.text) {
|
|
138
|
+
return `${value}-text`
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return value
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 属性映射器
|
|
146
|
+
*/
|
|
147
|
+
export class PropertyMapper {
|
|
148
|
+
constructor(componentName, componentConfig, customMaps = {}) {
|
|
149
|
+
this.componentName = componentName
|
|
150
|
+
this.componentConfig = componentConfig
|
|
151
|
+
this.customMaps = customMaps
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 映射单个属性
|
|
156
|
+
*/
|
|
157
|
+
mapProperty(propName, propValue, allProps) {
|
|
158
|
+
// 获取映射规则
|
|
159
|
+
let rule = this.getRule(propName)
|
|
160
|
+
|
|
161
|
+
if (!rule) {
|
|
162
|
+
// 如果没有找到规则,使用通用映射
|
|
163
|
+
return this.mapGenericProperty(propName, propValue)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// 应用转换规则
|
|
167
|
+
const result = rule.transform(propValue, this.componentConfig, allProps)
|
|
168
|
+
|
|
169
|
+
return result
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 获取属性映射规则
|
|
174
|
+
*/
|
|
175
|
+
getRule(propName) {
|
|
176
|
+
// 1. 首先检查组件特定规则
|
|
177
|
+
const componentRules = PropertyMappingRules.componentSpecific[this.componentName]
|
|
178
|
+
if (componentRules && componentRules[propName]) {
|
|
179
|
+
return componentRules[propName]
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// 2. 检查通用规则
|
|
183
|
+
if (PropertyMappingRules.common[propName]) {
|
|
184
|
+
return PropertyMappingRules.common[propName]
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// 3. 检查自定义映射
|
|
188
|
+
for (const mapType of Object.keys(this.customMaps)) {
|
|
189
|
+
if (this.customMaps[mapType] && this.customMaps[mapType][propName]) {
|
|
190
|
+
return {
|
|
191
|
+
target: mapType,
|
|
192
|
+
transform: (value) => this.customMaps[mapType][propName][value] || null
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return null
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* 映射通用属性(用于没有明确规则的属性)
|
|
202
|
+
*/
|
|
203
|
+
mapGenericProperty(propName, propValue) {
|
|
204
|
+
// 如果属性值本身就是样式对象
|
|
205
|
+
if (propValue && typeof propValue === 'object' && !Array.isArray(propValue)) {
|
|
206
|
+
return propValue
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// 根据属性名猜测映射
|
|
210
|
+
const lowerName = propName.toLowerCase()
|
|
211
|
+
|
|
212
|
+
// 检查是否是颜色属性
|
|
213
|
+
if (lowerName.includes('color') || lowerName.includes('background')) {
|
|
214
|
+
if (typeof propValue === 'string' && propValue.startsWith('#')) {
|
|
215
|
+
return {
|
|
216
|
+
[propName]: propValue
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// 检查是否是尺寸属性
|
|
222
|
+
if (lowerName.includes('width') || lowerName.includes('height') ||
|
|
223
|
+
lowerName.includes('size') || lowerName.includes('padding') ||
|
|
224
|
+
lowerName.includes('margin')) {
|
|
225
|
+
if (typeof propValue === 'string' || typeof propValue === 'number') {
|
|
226
|
+
return {
|
|
227
|
+
[propName]: propValue
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// 检查是否是边框属性
|
|
233
|
+
if (lowerName.includes('border') || lowerName.includes('radius')) {
|
|
234
|
+
if (typeof propValue === 'string' || typeof propValue === 'number') {
|
|
235
|
+
return {
|
|
236
|
+
[propName]: propValue
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return null
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* 映射所有属性
|
|
246
|
+
*/
|
|
247
|
+
mapAllProperties(props) {
|
|
248
|
+
const style = {}
|
|
249
|
+
|
|
250
|
+
// 1. 首先应用组件的默认样式(不包括 _pseudo)
|
|
251
|
+
this.applyDefaultStyle(style)
|
|
252
|
+
|
|
253
|
+
// 2. 遍历所有属性
|
|
254
|
+
for (const [propName, propValue] of Object.entries(props)) {
|
|
255
|
+
// 跳过不需要处理的属性
|
|
256
|
+
if (this.shouldSkipProperty(propName)) {
|
|
257
|
+
continue
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// 映射属性
|
|
261
|
+
const mappedStyle = this.mapProperty(propName, propValue, props)
|
|
262
|
+
// 合并到结果
|
|
263
|
+
if (mappedStyle && typeof mappedStyle === 'object') {
|
|
264
|
+
Object.assign(style, mappedStyle)
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// 3. 处理自定义映射
|
|
269
|
+
this.applyCustomMaps(style, props)
|
|
270
|
+
|
|
271
|
+
// 4. 最后应用自定义样式(来自props.style)
|
|
272
|
+
this.applyInlineStyle(style, props)
|
|
273
|
+
return style
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* 应用组件的默认样式
|
|
278
|
+
*/
|
|
279
|
+
applyDefaultStyle(style) {
|
|
280
|
+
// 如果组件配置中有default对象,将其样式合并(排除 _pseudo)
|
|
281
|
+
if (this.componentConfig && this.componentConfig.default) {
|
|
282
|
+
const {
|
|
283
|
+
_pseudo,
|
|
284
|
+
...defaultStyles
|
|
285
|
+
} = this.componentConfig.default
|
|
286
|
+
Object.assign(style, defaultStyles)
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* 获取组件的伪类样式配置
|
|
292
|
+
*/
|
|
293
|
+
getPseudoStyles() {
|
|
294
|
+
if (this.componentConfig && this.componentConfig.default && this.componentConfig.default._pseudo) {
|
|
295
|
+
return this.componentConfig.default._pseudo
|
|
296
|
+
}
|
|
297
|
+
return {}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* 应用内联样式
|
|
302
|
+
*/
|
|
303
|
+
applyInlineStyle(style, props) {
|
|
304
|
+
if (props.style && typeof props.style === 'object') {
|
|
305
|
+
Object.assign(style, props.style)
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* 检查是否应该跳过该属性
|
|
311
|
+
*/
|
|
312
|
+
shouldSkipProperty(propName) {
|
|
313
|
+
// 跳过 Vue 内置属性
|
|
314
|
+
const skipProps = ['key', 'ref', 'class', 'style', 'id', 'slot', 'boxStyle', 'className']
|
|
315
|
+
if (skipProps.includes(propName)) {
|
|
316
|
+
return true
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// 跳过事件处理器
|
|
320
|
+
if (propName.startsWith('on') || propName.startsWith('@')) {
|
|
321
|
+
return true
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return false
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* 应用自定义映射
|
|
329
|
+
*/
|
|
330
|
+
applyCustomMaps(style, props) {
|
|
331
|
+
// 处理自定义尺寸映射
|
|
332
|
+
if (this.customMaps.size && props.size && this.customMaps.size[props.size]) {
|
|
333
|
+
Object.assign(style, this.customMaps.size[props.size])
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// 处理自定义类型映射
|
|
337
|
+
if (this.customMaps.type && props.type) {
|
|
338
|
+
const typeKey = props.plain ? `${props.type}-plain` : props.type
|
|
339
|
+
if (this.customMaps.type[typeKey]) {
|
|
340
|
+
Object.assign(style, this.customMaps.type[typeKey])
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// 处理其他自定义映射
|
|
345
|
+
for (const [mapType, mapConfig] of Object.entries(this.customMaps)) {
|
|
346
|
+
if (mapType === 'size' || mapType === 'type') {
|
|
347
|
+
continue
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (typeof mapConfig === 'object') {
|
|
351
|
+
for (const [key, value] of Object.entries(mapConfig)) {
|
|
352
|
+
if (props[key] !== undefined && value[props[key]]) {
|
|
353
|
+
Object.assign(style, value[props[key]])
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* 注册新的属性映射规则
|
|
363
|
+
*/
|
|
364
|
+
export function registerPropertyRule(componentName, propName, rule) {
|
|
365
|
+
if (!PropertyMappingRules.componentSpecific[componentName]) {
|
|
366
|
+
PropertyMappingRules.componentSpecific[componentName] = {}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
PropertyMappingRules.componentSpecific[componentName][propName] = rule
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* 注册通用属性映射规则
|
|
374
|
+
*/
|
|
375
|
+
export function registerCommonPropertyRule(propName, rule) {
|
|
376
|
+
PropertyMappingRules.common[propName] = rule
|
|
377
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
export class PseudoProcessor {
|
|
2
|
+
constructor(config = {}) {
|
|
3
|
+
// 默认配置
|
|
4
|
+
this.config = {
|
|
5
|
+
// 变体优先级顺序
|
|
6
|
+
variantPriority: ['type', 'mode', 'size', 'shape', 'status'],
|
|
7
|
+
|
|
8
|
+
// 状态属性映射
|
|
9
|
+
stateMapping: {
|
|
10
|
+
plain: {
|
|
11
|
+
mode: 'outline'
|
|
12
|
+
},
|
|
13
|
+
text: {
|
|
14
|
+
mode: 'text'
|
|
15
|
+
},
|
|
16
|
+
disabled: {
|
|
17
|
+
status: 'disabled'
|
|
18
|
+
},
|
|
19
|
+
loading: {
|
|
20
|
+
status: 'loading'
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
// 查找策略配置
|
|
25
|
+
lookupStrategies: [
|
|
26
|
+
// 策略1: 完全匹配的组合键 (如: 'default-outline-small')
|
|
27
|
+
(obj, props, variantKey) => obj.combined && obj.combined[variantKey],
|
|
28
|
+
|
|
29
|
+
// 策略2: 基础类型匹配 (如: 'default')
|
|
30
|
+
(obj, props) => obj.type && obj.type[props.type || 'default'],
|
|
31
|
+
|
|
32
|
+
// 策略3: 状态属性匹配 (plain, text, disabled, loading)
|
|
33
|
+
(obj, props) => {
|
|
34
|
+
if (props.plain && obj.plain !== undefined) return obj.plain;
|
|
35
|
+
if (props.text && obj.text !== undefined) return obj.text;
|
|
36
|
+
if (props.disabled && obj.disabled !== undefined) return obj.disabled;
|
|
37
|
+
if (props.loading && obj.loading !== undefined) return obj.loading;
|
|
38
|
+
return null;
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
// 策略4: 变体属性匹配 (variant, size, shape)
|
|
42
|
+
(obj, props) => {
|
|
43
|
+
const variantProps = ['variant', 'size', 'shape', 'mode', 'status'];
|
|
44
|
+
for (const prop of variantProps) {
|
|
45
|
+
if (props[prop] && obj[prop] && obj[prop][props[prop]]) {
|
|
46
|
+
return obj[prop][props[prop]];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
// 策略5: 默认值
|
|
53
|
+
(obj) => obj.default
|
|
54
|
+
]
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// 合并自定义配置
|
|
58
|
+
if (config.variantPriority) this.config.variantPriority = config.variantPriority;
|
|
59
|
+
if (config.stateMapping) this.config.stateMapping = config.stateMapping;
|
|
60
|
+
if (config.lookupStrategies) this.config.lookupStrategies = config.lookupStrategies;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 构建变体键名
|
|
65
|
+
*/
|
|
66
|
+
buildVariantKey(props) {
|
|
67
|
+
const parts = [props.type || 'default'];
|
|
68
|
+
|
|
69
|
+
// 合并状态映射
|
|
70
|
+
const allVariants = {
|
|
71
|
+
...props
|
|
72
|
+
};
|
|
73
|
+
for (const [state, mapping] of Object.entries(this.config.stateMapping)) {
|
|
74
|
+
if (props[state]) {
|
|
75
|
+
Object.assign(allVariants, mapping);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 按优先级添加变体
|
|
80
|
+
for (const variant of this.config.variantPriority) {
|
|
81
|
+
if (allVariants[variant] && allVariants[variant] !== 'default') {
|
|
82
|
+
parts.push(allVariants[variant]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return parts.join('-');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 查找匹配的值
|
|
91
|
+
*/
|
|
92
|
+
findValue(value, props) {
|
|
93
|
+
// 如果是普通值,直接返回
|
|
94
|
+
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 构建变体键
|
|
99
|
+
const variantKey = this.buildVariantKey(props);
|
|
100
|
+
|
|
101
|
+
// 按策略优先级查找值
|
|
102
|
+
for (const strategy of this.config.lookupStrategies) {
|
|
103
|
+
const result = strategy(value, props, variantKey);
|
|
104
|
+
if (result !== undefined && result !== null) {
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 合并伪类样式
|
|
114
|
+
*/
|
|
115
|
+
mergeWithPseudo(baseStyle, pseudoStyles, pseudoKey, isActive, componentProps = {}) {
|
|
116
|
+
if (!isActive || !pseudoStyles?.[pseudoKey]) {
|
|
117
|
+
return {
|
|
118
|
+
...baseStyle
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const mergedStyle = {
|
|
123
|
+
...baseStyle
|
|
124
|
+
};
|
|
125
|
+
const pseudoStyle = pseudoStyles[pseudoKey];
|
|
126
|
+
|
|
127
|
+
for (const [property, value] of Object.entries(pseudoStyle)) {
|
|
128
|
+
if (value == null) continue;
|
|
129
|
+
|
|
130
|
+
const resolvedValue = this.findValue(value, componentProps);
|
|
131
|
+
if (resolvedValue != null) {
|
|
132
|
+
mergedStyle[property] = resolvedValue;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return mergedStyle;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 批量合并伪类
|
|
141
|
+
*/
|
|
142
|
+
mergeMultiplePseudo(baseStyle, pseudoStyles, activePseudoStates, componentProps = {}) {
|
|
143
|
+
let result = {
|
|
144
|
+
...baseStyle
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// 按定义的顺序合并伪类(优先级)
|
|
148
|
+
const pseudoOrder = ['--disabled', '--focus', '--hover', '--active'];
|
|
149
|
+
|
|
150
|
+
for (const pseudoKey of pseudoOrder) {
|
|
151
|
+
if (activePseudoStates[pseudoKey]) {
|
|
152
|
+
result = this.mergeWithPseudo(
|
|
153
|
+
result,
|
|
154
|
+
pseudoStyles,
|
|
155
|
+
pseudoKey,
|
|
156
|
+
true,
|
|
157
|
+
componentProps
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* 简化版合并方法 - 兼容原方法签名
|
|
167
|
+
*/
|
|
168
|
+
merge(baseStyle, pseudoStyles, pseudoKey, isActive, componentProps = {}) {
|
|
169
|
+
return this.mergeWithPseudo(
|
|
170
|
+
baseStyle,
|
|
171
|
+
pseudoStyles,
|
|
172
|
+
pseudoKey,
|
|
173
|
+
isActive,
|
|
174
|
+
componentProps
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 添加自定义查找策略
|
|
180
|
+
*/
|
|
181
|
+
addStrategy(strategyFn, priority = 0) {
|
|
182
|
+
this.config.lookupStrategies.push({
|
|
183
|
+
fn: strategyFn,
|
|
184
|
+
priority
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// 按优先级排序
|
|
188
|
+
this.config.lookupStrategies.sort((a, b) => b.priority - a.priority);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* 自定义状态映射
|
|
193
|
+
*/
|
|
194
|
+
addStateMapping(state, mapping) {
|
|
195
|
+
this.config.stateMapping[state] = mapping;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// 创建默认处理器实例
|
|
200
|
+
export const defaultPseudoProcessor = new PseudoProcessor();
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* 创建快捷函数
|
|
204
|
+
*/
|
|
205
|
+
export function mergeWithPseudo(baseStyle, pseudoStyles, pseudoKey, isActive, componentProps = {}) {
|
|
206
|
+
return defaultPseudoProcessor.mergeWithPseudo(
|
|
207
|
+
baseStyle,
|
|
208
|
+
pseudoStyles,
|
|
209
|
+
pseudoKey,
|
|
210
|
+
isActive,
|
|
211
|
+
componentProps
|
|
212
|
+
);
|
|
213
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export const config = {
|
|
2
|
+
//背景颜色
|
|
3
|
+
backgroundColor: {
|
|
4
|
+
default: '#307fff',
|
|
5
|
+
delete: '#ff5e5e',
|
|
6
|
+
success: '#31d283',
|
|
7
|
+
info: '#888888',
|
|
8
|
+
warn: '#fba000',
|
|
9
|
+
reversal: '#ffffff',
|
|
10
|
+
disabled: '#f5f5f5'
|
|
11
|
+
},
|
|
12
|
+
//字体颜色
|
|
13
|
+
fontColor: {
|
|
14
|
+
default: '#307fff',
|
|
15
|
+
delete: '#ff5e5e',
|
|
16
|
+
success: '#31d283',
|
|
17
|
+
info: '#888888',
|
|
18
|
+
warn: '#fba000',
|
|
19
|
+
mianTitle: '#222222',
|
|
20
|
+
subTitle: '#666666',
|
|
21
|
+
mainText: '#333333',
|
|
22
|
+
text: '#969696',
|
|
23
|
+
hintText: '#cccccc',
|
|
24
|
+
reversal: '#ffffff'
|
|
25
|
+
},
|
|
26
|
+
//字体大小
|
|
27
|
+
fontSize: {
|
|
28
|
+
largeTitle: '42.5rpx',
|
|
29
|
+
mediumTitle: '34.5rpx',
|
|
30
|
+
smallTitle: '31.5rpx',
|
|
31
|
+
largeText: '29.5rpx',
|
|
32
|
+
mediumText: '25.5rpx',
|
|
33
|
+
smallText: '22.5rpx',
|
|
34
|
+
messageText: '20.5rpx',
|
|
35
|
+
hintText: '18.5rpx'
|
|
36
|
+
},
|
|
37
|
+
//字体其他
|
|
38
|
+
fontOther: {
|
|
39
|
+
fontFamily: "'Noto Sans CJK'"
|
|
40
|
+
},
|
|
41
|
+
//文字间距
|
|
42
|
+
letterSpacing: {},
|
|
43
|
+
//边框
|
|
44
|
+
border: {
|
|
45
|
+
default: '#307fff',
|
|
46
|
+
delete: '#ff5e5e',
|
|
47
|
+
success: '#31d283',
|
|
48
|
+
info: '#888888',
|
|
49
|
+
warn: '#fba000',
|
|
50
|
+
color: '#e0e0e0'
|
|
51
|
+
},
|
|
52
|
+
borderRadius: {
|
|
53
|
+
semicircle: '8rpx',
|
|
54
|
+
square: '0',
|
|
55
|
+
circle: '35rpx'
|
|
56
|
+
},
|
|
57
|
+
//透明度
|
|
58
|
+
opacity: {
|
|
59
|
+
//悬浮
|
|
60
|
+
hover: 0.9,
|
|
61
|
+
//点击
|
|
62
|
+
click: 0.8,
|
|
63
|
+
//禁用
|
|
64
|
+
disabled: 0.7,
|
|
65
|
+
//消息提示
|
|
66
|
+
toast: 0.7,
|
|
67
|
+
//遮罩层
|
|
68
|
+
mask: 0.4,
|
|
69
|
+
//边框
|
|
70
|
+
border: 0.3
|
|
71
|
+
},
|
|
72
|
+
//暗黑模式
|
|
73
|
+
darkMode: {
|
|
74
|
+
backgroundColor: '#333333',
|
|
75
|
+
fontColor: '#ffffff',
|
|
76
|
+
border: '#e0e0e0'
|
|
77
|
+
},
|
|
78
|
+
//图片
|
|
79
|
+
VImage: {
|
|
80
|
+
prefix: '/21cqttttttttttttttttttttttttttt/ldxyb/static/images/'
|
|
81
|
+
},
|
|
82
|
+
//文本框
|
|
83
|
+
VInput: {
|
|
84
|
+
boxShadow: '0 0 0 4rpx rgba(24, 144, 255, 0.2)'
|
|
85
|
+
},
|
|
86
|
+
//表单
|
|
87
|
+
VTable: {
|
|
88
|
+
backgroundColor: '#f5f5f5'
|
|
89
|
+
},
|
|
90
|
+
//上传图片按钮
|
|
91
|
+
VUploadFileButton: {
|
|
92
|
+
backgroundColor: '#f5f5f5'
|
|
93
|
+
},
|
|
94
|
+
//菜单
|
|
95
|
+
VMenu: {
|
|
96
|
+
backgroundColor: '#f5f5f5',
|
|
97
|
+
highlightBackgroundColor: '#e0e0e0'
|
|
98
|
+
},
|
|
99
|
+
//步骤条
|
|
100
|
+
VSteps: {
|
|
101
|
+
lineBackgroundColor: '#e0e0e0'
|
|
102
|
+
},
|
|
103
|
+
//下拉框
|
|
104
|
+
VSelectPicker: {
|
|
105
|
+
backgroundColor: '#f5f5f5'
|
|
106
|
+
},
|
|
107
|
+
//时间选择器
|
|
108
|
+
VDateTime: {
|
|
109
|
+
backgroundColor: '#f5f5f5'
|
|
110
|
+
},
|
|
111
|
+
//表单行
|
|
112
|
+
VFormItem: {
|
|
113
|
+
borderColor: '#e0e0e0'
|
|
114
|
+
},
|
|
115
|
+
//开关
|
|
116
|
+
VSwitch: {
|
|
117
|
+
backgroundColor: '#f5f5f5'
|
|
118
|
+
},
|
|
119
|
+
//宫格布局
|
|
120
|
+
VGrid:{
|
|
121
|
+
backgroundColor: '#f5f5f5'
|
|
122
|
+
}
|
|
123
|
+
};
|