xianniu-ui 2.0.4 → 2.0.6
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/lib/style/card.css +1 -1
- package/lib/style/index.css +1 -1
- package/lib/xianniu-ui.common.js +140 -31
- package/lib/xianniu-ui.umd.js +140 -31
- package/lib/xianniu-ui.umd.min.js +2 -2
- package/package.json +1 -1
- package/packages/amount/main.vue +87 -6
- package/packages/style/src/card.scss +1 -1
package/package.json
CHANGED
package/packages/amount/main.vue
CHANGED
|
@@ -8,11 +8,15 @@
|
|
|
8
8
|
>
|
|
9
9
|
<slot name="prefix">{{ prefix }}</slot>
|
|
10
10
|
</i><!--
|
|
11
|
-
--><
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
--><template v-if="$slots.default">
|
|
12
|
+
<template v-if="slotTextContent !== null && !isNaN(Number(slotTextContent))">
|
|
13
|
+
{{ formatUserValue(Number(slotTextContent)) }}
|
|
14
|
+
</template>
|
|
15
|
+
<slot v-else></slot>
|
|
16
|
+
</template>
|
|
17
|
+
<template v-else>
|
|
18
|
+
{{ formattedValue }}
|
|
19
|
+
</template><!--
|
|
16
20
|
--><i
|
|
17
21
|
class="xn-amount-suffix"
|
|
18
22
|
:style="suffixStyle"
|
|
@@ -114,6 +118,11 @@ export default {
|
|
|
114
118
|
},
|
|
115
119
|
// 处理格式
|
|
116
120
|
doFormat(value, hasSeparator, separator) {
|
|
121
|
+
// 如果值为空或者是非数字字符串(如空值显示),直接返回
|
|
122
|
+
if (!value || isNaN(parseFloat(value))) {
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
|
|
117
126
|
if (!hasSeparator) {
|
|
118
127
|
return value;
|
|
119
128
|
}
|
|
@@ -167,10 +176,52 @@ export default {
|
|
|
167
176
|
legalPrecision() {
|
|
168
177
|
return this.precision > 0 ? this.precision : 0;
|
|
169
178
|
},
|
|
179
|
+
// 计算格式化后的值
|
|
180
|
+
formattedValue() {
|
|
181
|
+
// 如果有默认插槽内容,则不对插槽内容进行格式化
|
|
182
|
+
if (this.$slots.default) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// 应用精度和分隔符格式化
|
|
187
|
+
const value = this.formatValue;
|
|
188
|
+
const precisionValue = this.$options.filters.doPrecision(
|
|
189
|
+
value,
|
|
190
|
+
this.legalPrecision,
|
|
191
|
+
this.isRoundUp,
|
|
192
|
+
this.emptyValue
|
|
193
|
+
);
|
|
194
|
+
return this.$options.filters.doFormat(
|
|
195
|
+
precisionValue,
|
|
196
|
+
this.hasSeparator,
|
|
197
|
+
this.separator
|
|
198
|
+
);
|
|
199
|
+
},
|
|
200
|
+
// 获取默认插槽的文本内容
|
|
201
|
+
slotTextContent() {
|
|
202
|
+
if (!this.$slots.default || !this.$slots.default.length) {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// 获取插槽内容
|
|
207
|
+
const slot = this.$slots.default[0];
|
|
208
|
+
|
|
209
|
+
// 如果是文本节点
|
|
210
|
+
if (slot.text) {
|
|
211
|
+
return slot.text.trim();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// 如果是简单的VNode且包含文本
|
|
215
|
+
if (slot.children && slot.children.length > 0 && slot.children[0].text) {
|
|
216
|
+
return slot.children[0].text.trim();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return null;
|
|
220
|
+
},
|
|
170
221
|
},
|
|
171
222
|
data() {
|
|
172
223
|
return {
|
|
173
|
-
formatValue:
|
|
224
|
+
formatValue: null,
|
|
174
225
|
isMounted: false,
|
|
175
226
|
};
|
|
176
227
|
},
|
|
@@ -180,6 +231,17 @@ export default {
|
|
|
180
231
|
methods: {
|
|
181
232
|
// 动画显示数值变化
|
|
182
233
|
$_doAnimateDisplay(fromValue = 0, toValue = 0) {
|
|
234
|
+
// 如果目标值为null,直接设置为null
|
|
235
|
+
if (toValue == null) {
|
|
236
|
+
this.formatValue = null;
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// 如果起始值为null,设置为0
|
|
241
|
+
if (fromValue == null) {
|
|
242
|
+
fromValue = 0;
|
|
243
|
+
}
|
|
244
|
+
|
|
183
245
|
/* istanbul ignore next */
|
|
184
246
|
const step = (percent) => {
|
|
185
247
|
if (percent === 1) {
|
|
@@ -193,6 +255,25 @@ export default {
|
|
|
193
255
|
const verify = (id) => id;
|
|
194
256
|
Animate.start(step, verify, noop, this.duration);
|
|
195
257
|
},
|
|
258
|
+
// 格式化用户提供的值
|
|
259
|
+
formatUserValue(value) {
|
|
260
|
+
if (value == null || isNaN(value)) {
|
|
261
|
+
return this.emptyValue;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// 应用精度和分隔符格式化
|
|
265
|
+
const precisionValue = this.$options.filters.doPrecision(
|
|
266
|
+
value,
|
|
267
|
+
this.legalPrecision,
|
|
268
|
+
this.isRoundUp,
|
|
269
|
+
this.emptyValue
|
|
270
|
+
);
|
|
271
|
+
return this.$options.filters.doFormat(
|
|
272
|
+
precisionValue,
|
|
273
|
+
this.hasSeparator,
|
|
274
|
+
this.separator
|
|
275
|
+
);
|
|
276
|
+
},
|
|
196
277
|
},
|
|
197
278
|
};
|
|
198
279
|
</script>
|