uview-plus 3.4.4 → 3.4.5

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/changelog.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 3.4.5(2025-03-24)
2
+ feat: tag组件新增textSize/height/padding/borderRadius属性
3
+
4
+ feat: 新增genLightColor自动计算浅色方法及tag组件支持autoBgColor自动计算背景色
5
+
1
6
  ## 3.4.4(2025-03-13)
2
7
  feat: modal增加异步操作进行中点击取消弹出提示特性防止操作被中断
3
8
 
@@ -82,9 +82,30 @@ export const props = defineMixin({
82
82
  type: String,
83
83
  default: () => defProps.tag.icon,
84
84
  },
85
- iconColor: {
85
+ // 自定义尺寸字体大小
86
+ textSize: {
86
87
  type: String,
87
- default: () => defProps.tag.iconColor
88
- }
88
+ default: () => defProps.tag.textSize
89
+ },
90
+ // 自定义尺寸高度
91
+ height: {
92
+ type: String,
93
+ default: () => defProps.tag.height
94
+ },
95
+ // 自定义尺寸padding
96
+ padding: {
97
+ type: String,
98
+ default: () => defProps.tag.padding
99
+ },
100
+ // 自定义尺寸
101
+ borderRadius: {
102
+ type: String,
103
+ default: () => defProps.tag.borderRadius
104
+ },
105
+ // 自动计算背景色
106
+ autoBgColor: {
107
+ type: Number,
108
+ default: () => defProps.tag.autoBgColor
109
+ },
89
110
  }
90
111
  })
@@ -25,6 +25,11 @@ export default {
25
25
  closable: false,
26
26
  show: true,
27
27
  icon: '',
28
- iconColor: ''
28
+ iconColor: '',
29
+ textSize: '',
30
+ height: '',
31
+ padding: '',
32
+ borderRadius: '',
33
+ autoBgColor: 0
29
34
  }
30
35
  }
@@ -64,6 +64,7 @@
64
64
  import { mpMixin } from '../../libs/mixin/mpMixin';
65
65
  import { mixin } from '../../libs/mixin/mixin';
66
66
  import test from '../../libs/function/test';
67
+ import { addUnit, genLightColor } from '../../libs/function/index';
67
68
  /**
68
69
  * Tag 标签
69
70
  * @description tag组件一般用于标记和选择,我们提供了更加丰富的表现形式,能够较全面的涵盖您的使用场景
@@ -107,6 +108,19 @@
107
108
  if(this.borderColor) {
108
109
  style.borderColor = this.borderColor
109
110
  }
111
+ if (this.height) {
112
+ style.height = addUnit(this.height)
113
+ style.lineHeight = addUnit(this.height)
114
+ }
115
+ if (this.padding) {
116
+ style.padding = this.padding
117
+ }
118
+ if (this.borderRadius) {
119
+ style.borderRadius = addUnit(this.borderRadius)
120
+ }
121
+ if (this.autoBgColor > 0 && this.color) {
122
+ style.backgroundColor = this.getBagColor(this.color)
123
+ }
110
124
  return style
111
125
  },
112
126
  // nvue下,文本颜色无法继承父元素
@@ -115,6 +129,9 @@
115
129
  if (this.color) {
116
130
  style.color = this.color
117
131
  }
132
+ if (this.textSize) {
133
+ style.textSize = addUnit(this.textSize)
134
+ }
118
135
  return style
119
136
  },
120
137
  imgStyle() {
@@ -149,6 +166,10 @@
149
166
  // 点击标签
150
167
  clickHandler() {
151
168
  this.$emit('click', this.name)
169
+ },
170
+ // 根据颜色计算浅色作为背景
171
+ getBagColor(darkColor) {
172
+ return genLightColor(darkColor, this.autoBgColor)
152
173
  }
153
174
  }
154
175
  }
@@ -49,12 +49,12 @@ export function sleep(value = 30) {
49
49
  * @returns {string} 返回所在平台(小写)
50
50
  * @link 运行期判断平台 https://uniapp.dcloud.io/frame?id=判断平台
51
51
  */
52
- export function os() {
53
- // #ifdef APP || H5 || MP-WEIXIN
54
- return uni.getDeviceInfo().platform.toLowerCase()
55
- // #endif
56
- // #ifndef APP || H5 || MP-WEIXIN
57
- return uni.getSystemInfoSync().platform.toLowerCase()
52
+ export function os() {
53
+ // #ifdef APP || H5 || MP-WEIXIN
54
+ return uni.getDeviceInfo().platform.toLowerCase()
55
+ // #endif
56
+ // #ifndef APP || H5 || MP-WEIXIN
57
+ return uni.getSystemInfoSync().platform.toLowerCase()
58
58
  // #endif
59
59
  }
60
60
  /**
@@ -63,26 +63,26 @@ export function os() {
63
63
  */
64
64
  export function sys() {
65
65
  return uni.getSystemInfoSync()
66
- }
67
- export function getWindowInfo() {
68
- let ret = {}
69
- // #ifdef APP || H5 || MP-WEIXIN
70
- ret = uni.getWindowInfo()
71
- // #endif
72
- // #ifndef APP || H5 || MP-WEIXIN
73
- ret = sys()
74
- // #endif
75
- return ret
76
- }
77
- export function getDeviceInfo() {
78
- let ret = {}
79
- // #ifdef APP || H5 || MP-WEIXIN
80
- ret = uni.getDeviceInfo()
81
- // #endif
82
- // #ifndef APP || H5 || MP-WEIXIN
83
- ret = sys()
84
- // #endif
85
- return ret
66
+ }
67
+ export function getWindowInfo() {
68
+ let ret = {}
69
+ // #ifdef APP || H5 || MP-WEIXIN
70
+ ret = uni.getWindowInfo()
71
+ // #endif
72
+ // #ifndef APP || H5 || MP-WEIXIN
73
+ ret = sys()
74
+ // #endif
75
+ return ret
76
+ }
77
+ export function getDeviceInfo() {
78
+ let ret = {}
79
+ // #ifdef APP || H5 || MP-WEIXIN
80
+ ret = uni.getDeviceInfo()
81
+ // #endif
82
+ // #ifndef APP || H5 || MP-WEIXIN
83
+ ret = sys()
84
+ // #endif
85
+ return ret
86
86
  }
87
87
 
88
88
  /**
@@ -730,12 +730,99 @@ export function getValueByPath(obj, path) {
730
730
  }, obj);
731
731
  }
732
732
 
733
+ /**
734
+ * 生成同色系浅色背景色
735
+ * @param {string} textColor - 支持 #RGB、#RRGGBB、rgb()、rgba() 格式
736
+ * @param {number} [lightness=85] - 目标亮度百分比(默认85%)
737
+ * @returns {string} 十六进制颜色值
738
+ */
739
+ export function genLightColor(textColor, lightness = 95) {
740
+ // 手动解析颜色值(避免使用document)
741
+ const rgb = parseColorWithoutDOM(textColor);
742
+
743
+ // RGB转HSL色域
744
+ const hsl = rgbToHsl(rgb.r, rgb.g, rgb.b);
745
+
746
+ // 生成浅色背景
747
+ const bgHsl = {
748
+ h: hsl.h,
749
+ s: hsl.s,
750
+ l: Math.min(lightness, 95)
751
+ };
752
+
753
+ return hslToHex(bgHsl.h, bgHsl.s, bgHsl.l);
754
+ }
755
+
756
+ /* 手动解析颜色字符串(兼容uni-app环境) */
757
+ function parseColorWithoutDOM(colorStr) {
758
+ // 统一转小写处理
759
+ const str = colorStr.toLowerCase().trim();
760
+
761
+ // 处理十六进制格式
762
+ if (str.startsWith('#')) {
763
+ const hex = str.replace('#', '');
764
+ const fullHex = hex.length === 3 ?
765
+ hex.split('').map(c => c + c).join('') : hex;
766
+
767
+ return {
768
+ r: parseInt(fullHex.substring(0,2), 16),
769
+ g: parseInt(fullHex.substring(2,4), 16),
770
+ b: parseInt(fullHex.substring(4,6), 16)
771
+ };
772
+ }
773
+
774
+ // 处理rgb/rgba格式
775
+ const rgbMatch = str.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
776
+ if (rgbMatch) {
777
+ return {
778
+ r: +rgbMatch[1],
779
+ g: +rgbMatch[2],
780
+ b: +rgbMatch[3]
781
+ };
782
+ }
783
+
784
+ throw new Error('Invalid color format');
785
+ }
786
+
787
+ // 辅助函数:RGB 转 HSL(色相、饱和度、亮度)
788
+ function rgbToHsl(r, g, b) {
789
+ r /= 255, g /= 255, b /= 255;
790
+ const max = Math.max(r, g, b), min = Math.min(r, g, b);
791
+ let h, s, l = (max + min) / 2;
792
+
793
+ if (max === min) {
794
+ h = s = 0; // achromatic
795
+ } else {
796
+ const d = max - min;
797
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
798
+ switch (max) {
799
+ case r: h = (g - b) / d + (g < b ? 6 : 0); break;
800
+ case g: h = (b - r) / d + 2; break;
801
+ case b: h = (r - g) / d + 4; break;
802
+ }
803
+ h = (h * 60).toFixed(1);
804
+ }
805
+ return { h: +h, s: +(s * 100).toFixed(1), l: +(l * 100).toFixed(1) };
806
+ }
807
+
808
+ // 辅助函数:HSL 转十六进制
809
+ function hslToHex(h, s, l) {
810
+ l /= 100;
811
+ const a = s * Math.min(l, 1 - l) / 100;
812
+ const f = n => {
813
+ const k = (n + h / 30) % 12;
814
+ const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
815
+ return Math.round(255 * color).toString(16).padStart(2, '0');
816
+ };
817
+ return `#${f(0)}${f(8)}${f(4)}`;
818
+ }
819
+
733
820
  export default {
734
821
  range,
735
822
  getPx,
736
823
  sleep,
737
824
  os,
738
- sys,
825
+ sys,
739
826
  getWindowInfo,
740
827
  random,
741
828
  guid,
@@ -762,5 +849,5 @@ export default {
762
849
  page,
763
850
  pages,
764
851
  getValueByPath,
765
- // setConfig
852
+ genLightColor
766
853
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "id": "uview-plus",
3
3
  "name": "uview-plus",
4
4
  "displayName": "零云®uview-plus3.0重磅发布,全面的Vue3鸿蒙移动组件库。",
5
- "version": "3.4.4",
5
+ "version": "3.4.5",
6
6
  "description": "零云®uview-plus已兼容vue3,全面的组件和便捷的工具会让您信手拈来,如鱼得水",
7
7
  "keywords": [
8
8
  "uview",