wui-components-v2 1.2.23 → 1.2.25
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/components/fold-card2/fold-card2.vue +46 -15
- package/components/wui-list/wui-list.vue +7 -0
- package/package.json +1 -1
- package/utils/index.ts +116 -118
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { computed, defineEmits, defineOptions, defineProps, ref } from 'vue'
|
|
3
3
|
import type { Columns, Entities, Enums, FoldCardModel, Groups } from '../../type'
|
|
4
|
-
import { formatItemData } from '../../utils'
|
|
4
|
+
import { formatItemData, getEnumColor } from '../../utils'
|
|
5
5
|
import LabelValue from '../label-value/label-value.vue'
|
|
6
6
|
import { useManualTheme } from '../../composables/useManualTheme'
|
|
7
7
|
|
|
@@ -16,19 +16,29 @@ const emit = defineEmits<{
|
|
|
16
16
|
(e: 'click'): void
|
|
17
17
|
}>()
|
|
18
18
|
|
|
19
|
-
const props =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
const props = withDefaults(
|
|
20
|
+
defineProps<{
|
|
21
|
+
columns: Columns[]
|
|
22
|
+
collapseNum?: number
|
|
23
|
+
primaryColumn?: Columns
|
|
24
|
+
secondColumn?: Columns
|
|
25
|
+
labelColumn?: Columns
|
|
26
|
+
data: Entities
|
|
27
|
+
model: FoldCardModel
|
|
28
|
+
sourceId: string
|
|
29
|
+
groups: Groups
|
|
30
|
+
enumColumn?: Enums
|
|
31
|
+
index: number
|
|
32
|
+
/**
|
|
33
|
+
* 标题旁标签是否展示,由父级读取控制,默认不展示。
|
|
34
|
+
*/
|
|
35
|
+
showLabel?: boolean
|
|
36
|
+
}>(),
|
|
37
|
+
{
|
|
38
|
+
// 标题旁标签默认不展示
|
|
39
|
+
showLabel: false,
|
|
40
|
+
}
|
|
41
|
+
)
|
|
32
42
|
const { currentThemeColor } = useManualTheme()
|
|
33
43
|
// 展示内容
|
|
34
44
|
const exhibitData = computed(() => {
|
|
@@ -63,6 +73,20 @@ const labelColumns = computed(() => {
|
|
|
63
73
|
}
|
|
64
74
|
})
|
|
65
75
|
|
|
76
|
+
// 标题旁的标签:根据 labelColumn 字段值匹配枚举,得到显示文案与背景色
|
|
77
|
+
const labelTag = computed(() => {
|
|
78
|
+
if (!props.labelColumn?.sourceId) return null
|
|
79
|
+
const value = props.data.fieldMap[props.labelColumn.sourceId]
|
|
80
|
+
const matched = labelColumns.value.find(item => item.value === value)
|
|
81
|
+
if (!matched) return null
|
|
82
|
+
// 背景色使用 utils 中的 getEnumColor(枚举项 css.color)
|
|
83
|
+
const color = getEnumColor(labelColumns.value, value)?.color
|
|
84
|
+
return {
|
|
85
|
+
title: matched.title,
|
|
86
|
+
color,
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
|
|
66
90
|
// 折叠图标:未展开为 left,展开为 down
|
|
67
91
|
const collapseIcon = ref('left')
|
|
68
92
|
|
|
@@ -114,7 +138,14 @@ function toggleCollapse(contentId: string) {
|
|
|
114
138
|
<view class="mr-1 h-4 w-1 rounded-2xl" :style="{ backgroundColor: currentThemeColor.primary }" />
|
|
115
139
|
</view>
|
|
116
140
|
<view class="min-w-0 flex-1">
|
|
117
|
-
<view class="flex min-w-0 flex-1 items-center gap-
|
|
141
|
+
<view class="flex min-w-0 flex-1 items-center gap-1">
|
|
142
|
+
<wd-tag
|
|
143
|
+
style="font-size: 18px; padding: 3px 6px"
|
|
144
|
+
:bg-color="labelTag?.color"
|
|
145
|
+
v-if="showLabel && labelTag?.title"
|
|
146
|
+
>
|
|
147
|
+
{{ labelTag?.title || '' }}
|
|
148
|
+
</wd-tag>
|
|
118
149
|
<view class="min-w-0 flex-1 truncate font-700">
|
|
119
150
|
{{
|
|
120
151
|
formatItemData(
|
|
@@ -28,12 +28,18 @@ withDefaults(
|
|
|
28
28
|
* 顶部操作按钮区(新增等)是否显示,默认显示。
|
|
29
29
|
*/
|
|
30
30
|
showTopButtons?: boolean
|
|
31
|
+
/**
|
|
32
|
+
* 标题旁标签(labelTag)是否展示,由父级读取控制,默认不展示。
|
|
33
|
+
*/
|
|
34
|
+
showLabel?: boolean
|
|
31
35
|
}>(),
|
|
32
36
|
{
|
|
33
37
|
// 操作按钮区域(编辑/删除/morebutns)默认显示
|
|
34
38
|
isShowAction: true,
|
|
35
39
|
// 顶部操作按钮区默认显示
|
|
36
40
|
showTopButtons: true,
|
|
41
|
+
// 标题旁标签默认不展示
|
|
42
|
+
showLabel: false,
|
|
37
43
|
}
|
|
38
44
|
)
|
|
39
45
|
|
|
@@ -274,6 +280,7 @@ function tabSearchClick(data: any) {
|
|
|
274
280
|
:primary-column="config.primaryColumn"
|
|
275
281
|
:second-column="config.secondColumn"
|
|
276
282
|
:label-column="config.labelColumn"
|
|
283
|
+
:show-label="showLabel"
|
|
277
284
|
model="complex"
|
|
278
285
|
>
|
|
279
286
|
<template #buttons>
|
package/package.json
CHANGED
package/utils/index.ts
CHANGED
|
@@ -31,7 +31,10 @@ export function formatItemData(data: any, type: string) {
|
|
|
31
31
|
}
|
|
32
32
|
// 字符串中是否包含@,@
|
|
33
33
|
if (typeof data === 'string' && data.includes('@,@')) {
|
|
34
|
-
return data
|
|
34
|
+
return data
|
|
35
|
+
.split('@,@')
|
|
36
|
+
.map((item: string) => item.split('@R@')[1])
|
|
37
|
+
.join(',')
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
// 字符串中是否包含@R@
|
|
@@ -51,14 +54,15 @@ export function formatItemData(data: any, type: string) {
|
|
|
51
54
|
// 判断是否为JSON文件
|
|
52
55
|
if (typeof data === 'string') {
|
|
53
56
|
const a = JSON.parse(data)
|
|
54
|
-
return [
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
return [
|
|
58
|
+
{
|
|
59
|
+
url: `${baseUrl}/v3/files${a.base.path}?@token=${token}&@programToken=${hydrocarbonProgramToken}&name=${a.base.fileName || ''}`,
|
|
60
|
+
name: a.base.fileName,
|
|
61
|
+
type: a.base.type,
|
|
62
|
+
},
|
|
63
|
+
]
|
|
64
|
+
} else if (Array.isArray(data)) {
|
|
65
|
+
return data.map(item => {
|
|
62
66
|
if (item.includes('@R@')) {
|
|
63
67
|
const a = JSON.parse(item.split('@R@')[1])
|
|
64
68
|
return {
|
|
@@ -66,8 +70,7 @@ export function formatItemData(data: any, type: string) {
|
|
|
66
70
|
name: a.base.fileName,
|
|
67
71
|
type: a.base.type,
|
|
68
72
|
}
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
73
|
+
} else {
|
|
71
74
|
const a = JSON.parse(item)
|
|
72
75
|
return {
|
|
73
76
|
url: `${baseUrl}/v3/files${a.base.path}?@token=${token}&@programToken=${hydrocarbonProgramToken}&name=${a.base.fileName || ''}`,
|
|
@@ -76,20 +79,23 @@ export function formatItemData(data: any, type: string) {
|
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
})
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
} else {
|
|
83
|
+
return [
|
|
84
|
+
{
|
|
85
|
+
url: data.url,
|
|
86
|
+
name: data.name,
|
|
87
|
+
type: getAfterLastMatch(data.name, '.') || getAfterLastMatch(data.url, '.'),
|
|
88
|
+
},
|
|
89
|
+
]
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
|
-
return [
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
return [
|
|
93
|
+
{
|
|
94
|
+
url: 'https://',
|
|
95
|
+
name: '',
|
|
96
|
+
type: 'img',
|
|
97
|
+
},
|
|
98
|
+
]
|
|
93
99
|
}
|
|
94
100
|
|
|
95
101
|
return data
|
|
@@ -112,7 +118,7 @@ export function downloadFile(url: string) {
|
|
|
112
118
|
console.log('下载', url)
|
|
113
119
|
uni.downloadFile({
|
|
114
120
|
url, // 文件的网络地址
|
|
115
|
-
success:
|
|
121
|
+
success: res => {
|
|
116
122
|
if (res.statusCode === 200) {
|
|
117
123
|
console.log('下载成功', res.tempFilePath)
|
|
118
124
|
// 打开文件(如PDF、Word等)
|
|
@@ -121,8 +127,7 @@ export function downloadFile(url: string) {
|
|
|
121
127
|
showMenu: true,
|
|
122
128
|
success: () => console.log('打开文件成功'),
|
|
123
129
|
})
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
130
|
+
} else {
|
|
126
131
|
console.error('下载失败', res)
|
|
127
132
|
uni.showToast({
|
|
128
133
|
title: '下载失败',
|
|
@@ -130,7 +135,7 @@ export function downloadFile(url: string) {
|
|
|
130
135
|
})
|
|
131
136
|
}
|
|
132
137
|
},
|
|
133
|
-
fail:
|
|
138
|
+
fail: err => {
|
|
134
139
|
console.error('下载失败', err)
|
|
135
140
|
uni.showToast({
|
|
136
141
|
title: '下载失败',
|
|
@@ -147,8 +152,7 @@ export function downloadFile(url: string) {
|
|
|
147
152
|
*/
|
|
148
153
|
function getAfterLastMatch(str: string, pattern: string) {
|
|
149
154
|
const lastIndex = str.lastIndexOf(pattern)
|
|
150
|
-
if (lastIndex === -1)
|
|
151
|
-
return null
|
|
155
|
+
if (lastIndex === -1) return null
|
|
152
156
|
return str.substring(lastIndex + pattern.length)
|
|
153
157
|
}
|
|
154
158
|
|
|
@@ -159,11 +163,7 @@ function getAfterLastMatch(str: string, pattern: string) {
|
|
|
159
163
|
*
|
|
160
164
|
*
|
|
161
165
|
*/
|
|
162
|
-
export function comparator(
|
|
163
|
-
comparator: Comparator,
|
|
164
|
-
val: string,
|
|
165
|
-
defaultValue: string,
|
|
166
|
-
): boolean {
|
|
166
|
+
export function comparator(comparator: Comparator, val: string, defaultValue: string): boolean {
|
|
167
167
|
let dvs: string[]
|
|
168
168
|
let value = val
|
|
169
169
|
if (val && val.indexOf && val.indexOf('@R@') > 0) {
|
|
@@ -177,8 +177,7 @@ export function comparator(
|
|
|
177
177
|
|
|
178
178
|
if (comparator === 'none1') {
|
|
179
179
|
return !value || value === ''
|
|
180
|
-
}
|
|
181
|
-
else if (comparator === 'none1n') {
|
|
180
|
+
} else if (comparator === 'none1n') {
|
|
182
181
|
return !!value && value !== ''
|
|
183
182
|
}
|
|
184
183
|
|
|
@@ -220,8 +219,7 @@ export function comparator(
|
|
|
220
219
|
}
|
|
221
220
|
return false
|
|
222
221
|
|
|
223
|
-
case 'include_all':
|
|
224
|
-
{
|
|
222
|
+
case 'include_all': {
|
|
225
223
|
dvs = toArray(defaultValue)
|
|
226
224
|
vals = toArray(value)
|
|
227
225
|
let count = 0
|
|
@@ -240,32 +238,28 @@ export function comparator(
|
|
|
240
238
|
case 'greater':
|
|
241
239
|
if (!Number.isNaN(Number(value)) && !Number.isNaN(Number(defaultValue))) {
|
|
242
240
|
return Number(value) > Number(defaultValue)
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
241
|
+
} else {
|
|
245
242
|
return value > defaultValue
|
|
246
243
|
}
|
|
247
244
|
case 'Less':
|
|
248
245
|
case 'less':
|
|
249
246
|
if (!Number.isNaN(Number(value)) && !Number.isNaN(Number(defaultValue))) {
|
|
250
247
|
return Number(value) < Number(defaultValue)
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
248
|
+
} else {
|
|
253
249
|
return value < defaultValue
|
|
254
250
|
}
|
|
255
251
|
case 'noGreater':
|
|
256
252
|
case 'nogreater':
|
|
257
253
|
if (!Number.isNaN(Number(value)) && !Number.isNaN(Number(defaultValue))) {
|
|
258
254
|
return Number(value) <= Number(defaultValue)
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
255
|
+
} else {
|
|
261
256
|
return value <= defaultValue
|
|
262
257
|
}
|
|
263
258
|
case 'noLess':
|
|
264
259
|
case 'noless':
|
|
265
260
|
if (!Number.isNaN(Number(value)) && !Number.isNaN(Number(defaultValue))) {
|
|
266
261
|
return Number(value) >= Number(defaultValue)
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
262
|
+
} else {
|
|
269
263
|
return value >= defaultValue
|
|
270
264
|
}
|
|
271
265
|
case 'unequal':
|
|
@@ -282,28 +276,22 @@ function isEqual(value: string, defaultValue: string) {
|
|
|
282
276
|
if (value === 'true' || value === '是') {
|
|
283
277
|
if (defaultValue === '是' || defaultValue === 'true') {
|
|
284
278
|
return true
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
279
|
+
} else {
|
|
287
280
|
return false
|
|
288
281
|
}
|
|
289
|
-
}
|
|
290
|
-
else if (value === 'false' || value === '否') {
|
|
282
|
+
} else if (value === 'false' || value === '否') {
|
|
291
283
|
if (defaultValue === '否' || defaultValue === 'false') {
|
|
292
284
|
return true
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
285
|
+
} else {
|
|
295
286
|
return false
|
|
296
287
|
}
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
288
|
+
} else {
|
|
299
289
|
return false
|
|
300
290
|
}
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
291
|
+
} else {
|
|
303
292
|
if (!Number.isNaN(Number(value)) && !Number.isNaN(Number(defaultValue))) {
|
|
304
293
|
return Number(value) === Number(defaultValue)
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
294
|
+
} else {
|
|
307
295
|
return value === defaultValue
|
|
308
296
|
}
|
|
309
297
|
}
|
|
@@ -313,11 +301,9 @@ function toArray(value: string) {
|
|
|
313
301
|
let val
|
|
314
302
|
if (typeof value == 'string') {
|
|
315
303
|
val = value.split(',')
|
|
316
|
-
}
|
|
317
|
-
else if (Array.isArray(value)) {
|
|
304
|
+
} else if (Array.isArray(value)) {
|
|
318
305
|
val = value
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
306
|
+
} else {
|
|
321
307
|
val = [value]
|
|
322
308
|
}
|
|
323
309
|
return val
|
|
@@ -335,10 +321,10 @@ export function generateGradientColor(
|
|
|
335
321
|
color: string,
|
|
336
322
|
angle: number = 180,
|
|
337
323
|
startOpacity: number = 1,
|
|
338
|
-
endOpacity: number = 0.3
|
|
324
|
+
endOpacity: number = 0.3
|
|
339
325
|
): string {
|
|
340
326
|
// 处理十六进制颜色转换为RGB
|
|
341
|
-
const hexToRgb = (hex: string): { r: number
|
|
327
|
+
const hexToRgb = (hex: string): { r: number; g: number; b: number } | null => {
|
|
342
328
|
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
|
|
343
329
|
return result
|
|
344
330
|
? {
|
|
@@ -356,8 +342,7 @@ export function generateGradientColor(
|
|
|
356
342
|
if (rgb) {
|
|
357
343
|
return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${opacity})`
|
|
358
344
|
}
|
|
359
|
-
}
|
|
360
|
-
else if (color.startsWith('rgb(')) {
|
|
345
|
+
} else if (color.startsWith('rgb(')) {
|
|
361
346
|
// 处理rgb()格式
|
|
362
347
|
const rgbValues = color.match(/\d+/g)
|
|
363
348
|
if (rgbValues && rgbValues.length === 3) {
|
|
@@ -425,7 +410,7 @@ export function formatChineseDate(date: Date = new Date()): string {
|
|
|
425
410
|
*/
|
|
426
411
|
export function desaturateColor(color: string, opacity: number = 0.04): string {
|
|
427
412
|
// 处理十六进制颜色转换为RGB
|
|
428
|
-
const hexToRgb = (hex: string): { r: number
|
|
413
|
+
const hexToRgb = (hex: string): { r: number; g: number; b: number } | null => {
|
|
429
414
|
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
|
|
430
415
|
return result
|
|
431
416
|
? {
|
|
@@ -442,8 +427,7 @@ export function desaturateColor(color: string, opacity: number = 0.04): string {
|
|
|
442
427
|
if (rgb) {
|
|
443
428
|
return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${opacity})`
|
|
444
429
|
}
|
|
445
|
-
}
|
|
446
|
-
else if (color.startsWith('rgb(')) {
|
|
430
|
+
} else if (color.startsWith('rgb(')) {
|
|
447
431
|
// 处理rgb()格式
|
|
448
432
|
const rgbValues = color.match(/\d+/g)
|
|
449
433
|
if (rgbValues && rgbValues.length === 3) {
|
|
@@ -492,7 +476,10 @@ export function hexToRgb(hex: string) {
|
|
|
492
476
|
|
|
493
477
|
// 处理简写形式如 #FFF
|
|
494
478
|
if (hex.length === 3) {
|
|
495
|
-
hex = hex
|
|
479
|
+
hex = hex
|
|
480
|
+
.split('')
|
|
481
|
+
.map(c => c + c)
|
|
482
|
+
.join('')
|
|
496
483
|
}
|
|
497
484
|
|
|
498
485
|
// 解析十六进制值
|
|
@@ -510,7 +497,7 @@ export function hexToRgb(hex: string) {
|
|
|
510
497
|
* @param {object} rgb - RGB对象 {r, g, b}
|
|
511
498
|
* @returns {string} 十六进制颜色值
|
|
512
499
|
*/
|
|
513
|
-
export function rgbToHex(rgb: { r: any
|
|
500
|
+
export function rgbToHex(rgb: { r: any; g: any; b: any }) {
|
|
514
501
|
const toHex = (c: { toString: (arg0: number) => any }) => {
|
|
515
502
|
const hex = c.toString(16)
|
|
516
503
|
return hex.length === 1 ? `0${hex}` : hex
|
|
@@ -538,19 +525,22 @@ export function rgbToHsl(r: number, g: number, b: number) {
|
|
|
538
525
|
|
|
539
526
|
if (max === min) {
|
|
540
527
|
h = s = 0
|
|
541
|
-
}
|
|
542
|
-
else {
|
|
528
|
+
} else {
|
|
543
529
|
const d = max - min
|
|
544
530
|
s = l > 0.5 ? d / (2 - max - min) : d / (max + min)
|
|
545
531
|
|
|
546
532
|
switch (max) {
|
|
547
|
-
case r:
|
|
533
|
+
case r:
|
|
534
|
+
h = (g - b) / d + (g < b ? 6 : 0)
|
|
548
535
|
break
|
|
549
|
-
case g:
|
|
536
|
+
case g:
|
|
537
|
+
h = (b - r) / d + 2
|
|
550
538
|
break
|
|
551
|
-
case b:
|
|
539
|
+
case b:
|
|
540
|
+
h = (r - g) / d + 4
|
|
552
541
|
break
|
|
553
|
-
default:
|
|
542
|
+
default:
|
|
543
|
+
h = 0 // 添加默认情况,确保h被初始化
|
|
554
544
|
}
|
|
555
545
|
|
|
556
546
|
h /= 6
|
|
@@ -570,7 +560,7 @@ export function rgbToHsl(r: number, g: number, b: number) {
|
|
|
570
560
|
* @param {number} l - 亮度 (0-100)
|
|
571
561
|
* @returns {object} RGB对象 {r, g, b}
|
|
572
562
|
*/
|
|
573
|
-
export function hslToRgb(h: number, s: number = 50, l: number = 50): { r: number
|
|
563
|
+
export function hslToRgb(h: number, s: number = 50, l: number = 50): { r: number; g: number; b: number } {
|
|
574
564
|
h = h !== undefined ? h / 360 : 0
|
|
575
565
|
s = s !== undefined ? s / 100 : 0.5
|
|
576
566
|
l = l !== undefined ? l / 100 : 0.5
|
|
@@ -579,19 +569,13 @@ export function hslToRgb(h: number, s: number = 50, l: number = 50): { r: number
|
|
|
579
569
|
|
|
580
570
|
if (s === 0) {
|
|
581
571
|
r = g = b = l
|
|
582
|
-
}
|
|
583
|
-
else {
|
|
572
|
+
} else {
|
|
584
573
|
const hue2rgb = (p: number, q: number, t: number) => {
|
|
585
|
-
if (t < 0)
|
|
586
|
-
|
|
587
|
-
if (t
|
|
588
|
-
|
|
589
|
-
if (t <
|
|
590
|
-
return p + (q - p) * 6 * t
|
|
591
|
-
if (t < 1 / 2)
|
|
592
|
-
return q
|
|
593
|
-
if (t < 2 / 3)
|
|
594
|
-
return p + (q - p) * (2 / 3 - t) * 6
|
|
574
|
+
if (t < 0) t += 1
|
|
575
|
+
if (t > 1) t -= 1
|
|
576
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t
|
|
577
|
+
if (t < 1 / 2) return q
|
|
578
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6
|
|
595
579
|
return p
|
|
596
580
|
}
|
|
597
581
|
|
|
@@ -616,12 +600,11 @@ export function hslToRgb(h: number, s: number = 50, l: number = 50): { r: number
|
|
|
616
600
|
* @param {object} options - 配置选项
|
|
617
601
|
* @returns {object} 颜色对象
|
|
618
602
|
*/
|
|
619
|
-
export function generateRandomColorFromHex(
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
} = options
|
|
603
|
+
export function generateRandomColorFromHex(
|
|
604
|
+
baseHex: string,
|
|
605
|
+
options = { hueRange: 15, saturationRange: 20, lightnessRange: 20 }
|
|
606
|
+
) {
|
|
607
|
+
const { hueRange = 15, saturationRange = 20, lightnessRange = 20 } = options
|
|
625
608
|
|
|
626
609
|
// 转换为RGB
|
|
627
610
|
const baseRgb = hexToRgb(baseHex)
|
|
@@ -657,7 +640,11 @@ export function generateRandomColorFromHex(baseHex: string, options = { hueRange
|
|
|
657
640
|
* @param {object} options - 配置选项
|
|
658
641
|
* @returns {Array} 颜色数组
|
|
659
642
|
*/
|
|
660
|
-
export function generateHarmoniousColors(
|
|
643
|
+
export function generateHarmoniousColors(
|
|
644
|
+
baseHex: string,
|
|
645
|
+
count: number,
|
|
646
|
+
options = { hueRange: 15, saturationRange: 20, lightnessRange: 20, colorType: 'all' }
|
|
647
|
+
) {
|
|
661
648
|
const colors = []
|
|
662
649
|
const baseRgb = hexToRgb(baseHex)
|
|
663
650
|
const baseHsl = rgbToHsl(baseRgb.r, baseRgb.g, baseRgb.b)
|
|
@@ -677,11 +664,9 @@ export function generateHarmoniousColors(baseHex: string, count: number, options
|
|
|
677
664
|
let baseLightness = baseHsl.l
|
|
678
665
|
if (colorType === 'light') {
|
|
679
666
|
baseLightness = Math.min(80, baseHsl.l + 20)
|
|
680
|
-
}
|
|
681
|
-
else if (colorType === 'dark') {
|
|
667
|
+
} else if (colorType === 'dark') {
|
|
682
668
|
baseLightness = Math.max(20, baseHsl.l - 20)
|
|
683
|
-
}
|
|
684
|
-
else if (colorType === 'muted') {
|
|
669
|
+
} else if (colorType === 'muted') {
|
|
685
670
|
adjustedSaturationRange = Math.min(adjustedSaturationRange, 15)
|
|
686
671
|
}
|
|
687
672
|
|
|
@@ -727,7 +712,7 @@ export function generateIconColors(baseHex: string, count: number) {
|
|
|
727
712
|
|
|
728
713
|
for (let i = 0; i < count; i++) {
|
|
729
714
|
// 创建更均匀的色相分布
|
|
730
|
-
let hue = (baseHsl.h +
|
|
715
|
+
let hue = (baseHsl.h + i * hueStep) % 360
|
|
731
716
|
|
|
732
717
|
// 保持主色调附近有一些颜色
|
|
733
718
|
if (i < 3) {
|
|
@@ -736,13 +721,13 @@ export function generateIconColors(baseHex: string, count: number) {
|
|
|
736
721
|
|
|
737
722
|
// 智能调整饱和度和亮度
|
|
738
723
|
// 重要图标更鲜艳,次要图标更柔和
|
|
739
|
-
const saturation = Math.max(60, Math.min(90, baseHsl.s + (Math.random() * 20 - 10)
|
|
740
|
-
))
|
|
724
|
+
const saturation = Math.max(60, Math.min(90, baseHsl.s + (Math.random() * 20 - 10)))
|
|
741
725
|
|
|
742
726
|
// 创建对比度:一些更亮,一些更暗
|
|
743
|
-
const lightness =
|
|
744
|
-
|
|
745
|
-
|
|
727
|
+
const lightness =
|
|
728
|
+
i % 2 === 0
|
|
729
|
+
? Math.min(70, baseHsl.l + 15 + Math.random() * 10)
|
|
730
|
+
: Math.max(30, baseHsl.l - 10 + Math.random() * 10)
|
|
746
731
|
|
|
747
732
|
const rgb = hslToRgb(hue, saturation, lightness)
|
|
748
733
|
const hex = rgbToHex(rgb)
|
|
@@ -782,8 +767,8 @@ export function getContrastRatio(hexColor: string, backgroundColor = '#FFFFFF')
|
|
|
782
767
|
* @param {object} rgb - RGB对象
|
|
783
768
|
* @returns {number} 亮度值
|
|
784
769
|
*/
|
|
785
|
-
function getLuminance(rgb: { r: number
|
|
786
|
-
const [r, g, b] = [rgb.r, rgb.g, rgb.b].map(
|
|
770
|
+
function getLuminance(rgb: { r: number; g: number; b: number }) {
|
|
771
|
+
const [r, g, b] = [rgb.r, rgb.g, rgb.b].map(v => {
|
|
787
772
|
v /= 255
|
|
788
773
|
return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4
|
|
789
774
|
})
|
|
@@ -855,18 +840,20 @@ const COLOR_RANGES = [
|
|
|
855
840
|
{ name: '粉', hueRange: [310, 340], saturation: 70, lightness: 55 },
|
|
856
841
|
] as const
|
|
857
842
|
|
|
858
|
-
type ColorRange = typeof COLOR_RANGES[number]
|
|
843
|
+
type ColorRange = (typeof COLOR_RANGES)[number]
|
|
859
844
|
|
|
860
845
|
/**
|
|
861
846
|
* 将HSL转换为十六进制颜色
|
|
862
847
|
*/
|
|
863
848
|
function hslToHex(h: number, s: number, l: number): string {
|
|
864
849
|
l /= 100
|
|
865
|
-
const a = s * Math.min(l, 1 - l) / 100
|
|
850
|
+
const a = (s * Math.min(l, 1 - l)) / 100
|
|
866
851
|
const f = (n: number) => {
|
|
867
852
|
const k = (n + h / 30) % 12
|
|
868
853
|
const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1)
|
|
869
|
-
return Math.round(255 * color)
|
|
854
|
+
return Math.round(255 * color)
|
|
855
|
+
.toString(16)
|
|
856
|
+
.padStart(2, '0')
|
|
870
857
|
}
|
|
871
858
|
return `#${f(0)}${f(8)}${f(4)}`
|
|
872
859
|
}
|
|
@@ -962,18 +949,29 @@ export class RainbowColorGenerator {
|
|
|
962
949
|
* @returns 格式化后的手机号字符串
|
|
963
950
|
*/
|
|
964
951
|
export function formatPhone(phone: string, mask = '****') {
|
|
965
|
-
if (!phone) return ''
|
|
952
|
+
if (!phone) return ''
|
|
966
953
|
|
|
967
|
-
const cleanPhone = phone.replace(/\D/g, '')
|
|
968
|
-
const len = cleanPhone.length
|
|
954
|
+
const cleanPhone = phone.replace(/\D/g, '')
|
|
955
|
+
const len = cleanPhone.length
|
|
969
956
|
|
|
970
957
|
// 根据号码长度决定显示方式
|
|
971
958
|
if (len === 11) {
|
|
972
|
-
return cleanPhone.slice(0, 3) + mask + cleanPhone.slice(-4)
|
|
959
|
+
return cleanPhone.slice(0, 3) + mask + cleanPhone.slice(-4)
|
|
973
960
|
} else if (len === 8) {
|
|
974
961
|
// 座机号码等短号码
|
|
975
|
-
return cleanPhone.slice(0, 2) + mask + cleanPhone.slice(-2)
|
|
962
|
+
return cleanPhone.slice(0, 2) + mask + cleanPhone.slice(-2)
|
|
976
963
|
}
|
|
977
964
|
|
|
978
|
-
return phone
|
|
965
|
+
return phone
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
//获取枚举颜色 content: 406795063630012418@R@轴2
|
|
969
|
+
export const getEnumColor = (enumMap: any[] = [], content: string) => {
|
|
970
|
+
console.log(enumMap, content)
|
|
971
|
+
if (typeof content !== 'string') return null
|
|
972
|
+
let css = enumMap.find((item: any) => {
|
|
973
|
+
return item.value === content
|
|
974
|
+
})
|
|
975
|
+
|
|
976
|
+
return css?.css
|
|
979
977
|
}
|