n20-common-lib 3.3.15 → 3.3.16
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/package.json
CHANGED
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
| disabled | Boolean | undefined | 是否禁用 |
|
|
32
32
|
| isClearable | Boolean | false | 是否可清空 |
|
|
33
33
|
| placeholder | String | '请输入' | 占位提示文本 |
|
|
34
|
-
| dNum | Number | undefined | 小数位数,优先级低于format;超过15
|
|
35
|
-
| format | String | undefined | 格式化字符串,如'0.00'表示保留2
|
|
34
|
+
| dNum | Number | undefined | 小数位数,优先级低于format;超过15位时以字符串保持精度;与format、rangeAuto同时使用时表示最大小数位数 |
|
|
35
|
+
| format | String | undefined | 格式化字符串,如'0.00'表示保留2位小数;与dNum、rangeAuto同时使用时表示最少展示的小数位数 |
|
|
36
36
|
| suffix | String | '%' | 后缀文本,仅在type='rate'时有效 |
|
|
37
37
|
| rangeAuto | Boolean | false | 是否自动处理范围值 |
|
|
38
38
|
| isString | Boolean | false | 是否始终以字符串回传 input/change 值;小数位超过15位时自动按 true 处理 |
|
|
@@ -63,6 +63,8 @@
|
|
|
63
63
|
|
|
64
64
|
当 `dNum` 或 `format` 设置为超过 15 位小数时,组件会强制按 `isString=true` 处理,即使未显式配置 `isString`,`input` 和 `change` 也会回传字符串,避免 JavaScript `Number` 丢失精度;失焦时会按最大位数四舍五入并移除尾部 `0`,例如 `0.200000` 会回传 `"0.2"`。设置 `isString` 为 `true` 后,无论小数位数多少,`input` 和 `change` 都回传字符串;清空时回传空字符串。
|
|
65
65
|
|
|
66
|
+
当 `rangeAuto=true` 且同时配置 `format` 和 `dNum` 时,`format` 表示最少展示的小数位数,`dNum` 表示最多保留的小数位数。例如 `format="0.000000"`、`dNum=20` 时,输入 `0.2` 显示为 `0.200000`,输入 7 至 20 位小数按实际位数显示,超过 20 位时按 20 位四舍五入。
|
|
67
|
+
|
|
66
68
|
| 事件名 | 说明 | 回调参数 |
|
|
67
69
|
| ------ | ----------- | ---- |
|
|
68
70
|
| input | 值改变时触发 | 当前值 |
|
|
@@ -170,7 +170,7 @@ export default {
|
|
|
170
170
|
this.valueStr = ''
|
|
171
171
|
return
|
|
172
172
|
}
|
|
173
|
-
const formatted = this.normalizeHighPrecisionValue(
|
|
173
|
+
const formatted = this.normalizeHighPrecisionValue(val)
|
|
174
174
|
this.valueStr = this.type === 'number' ? formatted : N.addThousands(formatted)
|
|
175
175
|
}
|
|
176
176
|
return
|
|
@@ -209,8 +209,16 @@ export default {
|
|
|
209
209
|
}
|
|
210
210
|
},
|
|
211
211
|
methods: {
|
|
212
|
+
isAdaptivePrecision() {
|
|
213
|
+
return this.rangeAuto && this.format && (this.dNum || this.dNum === 0)
|
|
214
|
+
},
|
|
215
|
+
maxDecimalPlaces() {
|
|
216
|
+
return this.isAdaptivePrecision()
|
|
217
|
+
? Math.max(this.fNum, this.dNum)
|
|
218
|
+
: this.fNum
|
|
219
|
+
},
|
|
212
220
|
isHighPrecision() {
|
|
213
|
-
return this.
|
|
221
|
+
return this.maxDecimalPlaces() > MAX_SAFE_DECIMAL_PLACES
|
|
214
222
|
},
|
|
215
223
|
// 高精度小数会强制使用字符串回传,即使 isString 未开启。
|
|
216
224
|
shouldEmitString() {
|
|
@@ -221,6 +229,20 @@ export default {
|
|
|
221
229
|
if (!normalized) return ''
|
|
222
230
|
|
|
223
231
|
const decimalPart = normalized.split('.')[1] || ''
|
|
232
|
+
if (this.isAdaptivePrecision()) {
|
|
233
|
+
const originalValue = String(value).replace(/,/g, '').trim()
|
|
234
|
+
const originalFraction = originalValue.match(/\.(\d*)$/)
|
|
235
|
+
const decimalPlaces = originalFraction
|
|
236
|
+
? originalFraction[1].length
|
|
237
|
+
: decimalPart.length
|
|
238
|
+
if (decimalPlaces < this.fNum) {
|
|
239
|
+
return decimalToFixed(normalized, this.fNum)
|
|
240
|
+
}
|
|
241
|
+
if (decimalPlaces > this.maxDecimalPlaces()) {
|
|
242
|
+
return decimalToFixed(normalized, this.maxDecimalPlaces())
|
|
243
|
+
}
|
|
244
|
+
return decimalToFixed(normalized, decimalPlaces)
|
|
245
|
+
}
|
|
224
246
|
const roundedValue = this.rangeAuto && decimalPart.length >= this.fNum
|
|
225
247
|
? normalized
|
|
226
248
|
: decimalToFixed(normalized, this.fNum)
|
|
@@ -312,7 +334,7 @@ export default {
|
|
|
312
334
|
return
|
|
313
335
|
}
|
|
314
336
|
|
|
315
|
-
let nextValue = this.normalizeHighPrecisionValue(
|
|
337
|
+
let nextValue = this.normalizeHighPrecisionValue(valStr)
|
|
316
338
|
|
|
317
339
|
if (compareDecimal(nextValue, this.min) < 0) {
|
|
318
340
|
nextValue = normalizeDecimal(this.min)
|
|
@@ -320,6 +342,8 @@ export default {
|
|
|
320
342
|
nextValue = normalizeDecimal(this.max)
|
|
321
343
|
}
|
|
322
344
|
|
|
345
|
+
nextValue = this.normalizeHighPrecisionValue(nextValue)
|
|
346
|
+
|
|
323
347
|
const formatted = this.type === 'number' ? nextValue : N.addThousands(nextValue)
|
|
324
348
|
this.valueStr = formatted
|
|
325
349
|
this.$nextTick(() => {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<div>
|
|
3
3
|
<div v-if="size !== 'mini'" class="flex-box p-t-ss p-b-ss">
|
|
4
4
|
<statisItem
|
|
5
|
-
:type="
|
|
5
|
+
:type="pageTotalLabel"
|
|
6
6
|
:list="pageList"
|
|
7
7
|
:show-w="showW"
|
|
8
8
|
:show-u="showU"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
</div>
|
|
19
19
|
<div v-else class="n20-statis p-t-ss p-b-ss">
|
|
20
20
|
<span class="m-r">
|
|
21
|
-
{{
|
|
21
|
+
{{ label + ':' }}<span class="n20-primary"> {{ pageSum }}</span> {{ '条' | $lc }}
|
|
22
22
|
</span>
|
|
23
23
|
<span class="m-r">
|
|
24
24
|
{{ '全部:' | $lc }}<span class="n20-primary"> {{ totalSun }}</span> {{ '条' | $lc }}
|
|
@@ -28,8 +28,10 @@
|
|
|
28
28
|
</template>
|
|
29
29
|
|
|
30
30
|
<script>
|
|
31
|
-
import { $lc } from '../../utils/i18n/index'
|
|
32
31
|
import statisItem from './statisItem.vue'
|
|
32
|
+
|
|
33
|
+
import { $lc } from '../../utils/i18n/index'
|
|
34
|
+
|
|
33
35
|
export default {
|
|
34
36
|
name: 'Statis',
|
|
35
37
|
components: {
|
|
@@ -70,10 +72,14 @@ export default {
|
|
|
70
72
|
},
|
|
71
73
|
label: {
|
|
72
74
|
type: String,
|
|
73
|
-
default: $lc(
|
|
75
|
+
default: $lc('已选')
|
|
74
76
|
}
|
|
75
77
|
},
|
|
76
78
|
computed: {
|
|
79
|
+
pageTotalLabel() {
|
|
80
|
+
const separator = ['zh', 'ja', 'th'].includes(this._lang || 'zh') ? '' : ' '
|
|
81
|
+
return this.label + separator + $lc('合计')
|
|
82
|
+
},
|
|
77
83
|
unitAs() {
|
|
78
84
|
if (!this.showU) {
|
|
79
85
|
return undefined
|