sadais-piui 1.2.7-beta174 → 1.2.7-beta175

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.
@@ -28,7 +28,6 @@
28
28
  <script>
29
29
  import { getConfig } from '../../config'
30
30
 
31
- const TAG = 'PiBadge'
32
31
  const { badge } = getConfig()
33
32
 
34
33
  export default {
@@ -79,12 +78,32 @@ export default {
79
78
  type: [String, Number],
80
79
  // ''
81
80
  default: badge.max
81
+ },
82
+ // 徽标尺寸,可以是数字(如 12、14、16)或字符串(small、medium、large)
83
+ size: {
84
+ type: [String, Number],
85
+ // 16
86
+ default: badge.size
82
87
  }
83
88
  },
84
89
  data() {
85
90
  return {}
86
91
  },
87
92
  computed: {
93
+ // 尺寸配置
94
+ sizeConfig() {
95
+ // 将 size 转换为数字
96
+ const size = Math.max(10, Number(this.size) || 16)
97
+ const padding = Math.max(2, Math.floor(size / 5))
98
+ const fontSize = Math.max(10, Math.floor(size * 0.75))
99
+
100
+ return {
101
+ minSize: `${size}px`,
102
+ padding: `0 ${padding}px`,
103
+ fontSize: `${fontSize}px`,
104
+ borderRadius: `${size}px`
105
+ }
106
+ },
88
107
  getDotRadius() {
89
108
  return this.$pi.common.addUnit(this.dotRadius)
90
109
  },
@@ -95,13 +114,40 @@ export default {
95
114
  if (this.dot) {
96
115
  style.width = this.getDotRadius
97
116
  style.height = this.getDotRadius
117
+ } else {
118
+ // 应用尺寸配置
119
+ const content = this.getContent
120
+ const contentStr = String(content)
121
+ const contentLength = contentStr.length
122
+
123
+ // 一个字符时使用正方形(圆形),多个字符时使用椭圆形
124
+ if (contentLength === 1 && contentStr.trim()) {
125
+ style.width = this.sizeConfig.minSize
126
+ style.height = this.sizeConfig.minSize
127
+ style.padding = '0'
128
+ style.lineHeight = this.sizeConfig.minSize
129
+ } else if (contentLength > 1) {
130
+ style.minWidth = this.sizeConfig.minSize
131
+ style.padding = this.sizeConfig.padding
132
+ }
133
+
134
+ style.fontSize = this.sizeConfig.fontSize
135
+ style.borderRadius = this.sizeConfig.borderRadius
98
136
  }
99
137
  return style
100
138
  },
101
139
  getContent() {
102
140
  const max = parseInt(this.max, 10)
103
141
  const content = parseInt(this.content, 10)
104
- if (this.$pi.lang.isNumber(content) && max < content) return `${max}+`
142
+
143
+ // 更严格的数字判断
144
+ if (
145
+ this.$pi.lang.isNumber(content) &&
146
+ this.$pi.lang.isNumber(max) &&
147
+ content > max
148
+ ) {
149
+ return `${max}+`
150
+ }
105
151
  return this.content
106
152
  }
107
153
  },
@@ -120,16 +166,12 @@ export default {
120
166
 
121
167
  .badge {
122
168
  box-sizing: border-box;
123
- min-width: 16px;
124
- padding: 0 3px;
125
- font-size: 12px;
126
169
  font-weight: 500;
127
170
  line-height: 1.2;
128
171
  color: #ffffff;
129
172
  text-align: center;
130
173
  background-color: #ee0a24;
131
174
  border: 1px solid #ffffff;
132
- border-radius: 16px;
133
175
 
134
176
  &.hide-border {
135
177
  border: none;
package/config/badge.js CHANGED
@@ -5,5 +5,6 @@ export default {
5
5
  dotRadius: 16, // 小红点的半径
6
6
  content: '', // 徽标的内容
7
7
  color: '#ee0a24', // 徽标背景颜色
8
- max: 99 // 最大值,超过最大值会显示 {max}+,仅当 content 为数字时有效
8
+ max: 99, // 最大值,超过最大值会显示 {max}+,仅当 content 为数字时有效
9
+ size: 16 // 徽标尺寸,支持数字或字符串数字(如 12、'14'、16、'18')
9
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7-beta174",
3
+ "version": "1.2.7-beta175",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {