UNPKG

tdesign-vue

Version:
183 lines (179 loc) 7.33 kB
/** * tdesign v1.12.1 * (c) 2025 tdesign * @license MIT */ import { defineComponent, toRefs, ref, computed, onMounted, watch } from '@vue/composition-api'; import { ArrowTriangleUpFilledIcon, ArrowTriangleDownFilledIcon } from 'tdesign-icons-vue'; import { isNumber, isFunction } from 'lodash-es'; import props from './props.js'; import { renderTNodeJSX } from '../utils/render-tnode.js'; import { usePrefixClass } from '../hooks/useConfig.js'; import { useGlobalIcon } from '../hooks/useGlobalIcon.js'; import { Skeleton } from '../skeleton/index.js'; import Tween from '../_common/js/statistic/tween.js'; import { COLOR_MAP, getFormatValue } from '../_common/js/statistic/utils.js'; import '@babel/runtime/helpers/defineProperty'; import '@babel/runtime/helpers/readOnlyError'; import '@babel/runtime/helpers/typeof'; import 'vue'; import '../config-provider/useConfig.js'; import '../config-provider/context.js'; import '../_common/js/global-config/default-config.js'; import '../_common/js/global-config/locale/zh_CN.js'; import '../_chunks/dep-c44a474d.js'; import '../_chunks/dep-d639fbd7.js'; import 'dayjs'; import '../_chunks/dep-3c66615e.js'; import '../config-provider/type.js'; import '../_common/js/global-config/t.js'; import '@babel/runtime/helpers/slicedToArray'; import '../skeleton/skeleton.js'; import '../skeleton/props.js'; import '../config-provider/config-receiver.js'; import '../utils/mixins.js'; import '../utils/withInstall.js'; import './style/index.js'; import '../skeleton/type.js'; import '@babel/runtime/helpers/classCallCheck'; import '@babel/runtime/helpers/createClass'; import '../_common/js/utils/helper.js'; import '@babel/runtime/helpers/toConsumableArray'; import '@babel/runtime/helpers/objectWithoutProperties'; var _Statistic = defineComponent({ name: "Statistic", props: props, setup: function setup(props2) { var _props2$animation$val, _props2$animation; var classPrefix = usePrefixClass("statistic"); var _toRefs = toRefs(props2), value = _toRefs.value, decimalPlaces = _toRefs.decimalPlaces, separator = _toRefs.separator, color = _toRefs.color; var innerValue = ref((_props2$animation$val = (_props2$animation = props2.animation) === null || _props2$animation === void 0 ? void 0 : _props2$animation.valueFrom) !== null && _props2$animation$val !== void 0 ? _props2$animation$val : props2.value); var tween = ref(null); var numberValue = computed(function () { return isNumber(props2.value) ? props2.value : 0; }); var valueStyle = computed(function () { return { color: COLOR_MAP[color.value] || color.value }; }); var innerDecimalPlaces = computed(function () { var _ref, _decimalPlaces$value, _numberValue$value$to; return (_ref = (_decimalPlaces$value = decimalPlaces.value) !== null && _decimalPlaces$value !== void 0 ? _decimalPlaces$value : (_numberValue$value$to = numberValue.value.toString().split(".")[1]) === null || _numberValue$value$to === void 0 ? void 0 : _numberValue$value$to.length) !== null && _ref !== void 0 ? _ref : 0; }); var start = function start() { var _props2$animation$val2, _props2$animation2; var from = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : (_props2$animation$val2 = (_props2$animation2 = props2.animation) === null || _props2$animation2 === void 0 ? void 0 : _props2$animation2.valueFrom) !== null && _props2$animation$val2 !== void 0 ? _props2$animation$val2 : 0; var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : numberValue.value; if (from !== to) { var _tween$value; tween.value = new Tween({ from: { value: from }, to: { value: to }, duration: props2.animation.duration, onUpdate: function onUpdate(keys) { innerValue.value = Number(keys.value.toFixed(innerDecimalPlaces.value)); }, onFinish: function onFinish() { innerValue.value = to; } }); (_tween$value = tween.value) === null || _tween$value === void 0 || _tween$value.start(); } }; var formatValue = computed(function () { if (isFunction(props2.format)) { return props2.format(innerValue.value); } return getFormatValue(innerValue.value, decimalPlaces.value, separator.value); }); onMounted(function () { return props2.animation && props2.animationStart && start(); }); watch(function () { return props2.animationStart; }, function (value2) { if (props2.animation && value2 && !tween.value) { start(); } }); watch(value, function (value2) { if (tween.value) { var _tween$value2; (_tween$value2 = tween.value) === null || _tween$value2 === void 0 || _tween$value2.stop(); tween.value = null; } innerValue.value = value2; if (props2.animationStart && props2.animation) { start(); } }); return { start: start, classPrefix: classPrefix, formatValue: formatValue, valueStyle: valueStyle }; }, render: function render() { var h = arguments[0]; var classPrefix = this.classPrefix, formatValue = this.formatValue, valueStyle = this.valueStyle, loading = this.loading, trendPlacement = this.trendPlacement, trend = this.trend; var _useGlobalIcon = useGlobalIcon({ ArrowTriangleUpFilledIcon: ArrowTriangleUpFilledIcon }), ArrowTriangleUpFilledIcon$1 = _useGlobalIcon.ArrowTriangleUpFilledIcon; var _useGlobalIcon2 = useGlobalIcon({ ArrowTriangleDownFilledIcon: ArrowTriangleDownFilledIcon }), ArrowTriangleDownFilledIcon$1 = _useGlobalIcon2.ArrowTriangleDownFilledIcon; var trendIcons = { increase: h(ArrowTriangleUpFilledIcon$1), decrease: h(ArrowTriangleDownFilledIcon$1) }; var trendIcon = trend ? trendIcons[trend] : null; var prefix = renderTNodeJSX(this, "prefix") || (trendIcon && trendPlacement !== "right" ? trendIcon : null); var suffix = renderTNodeJSX(this, "suffix") || (trendIcon && trendPlacement === "right" ? trendIcon : null); var title = renderTNodeJSX(this, "title"); var unit = renderTNodeJSX(this, "unit"); var extra = renderTNodeJSX(this, "extra"); return h("div", { "class": classPrefix }, [title && h("div", { "class": "".concat(classPrefix, "-title") }, [title]), h(Skeleton, { "attrs": { "animation": "gradient", "theme": "text", "loading": !!loading } }, [h("div", { "class": "".concat(classPrefix, "-content"), "style": valueStyle }, [prefix && h("span", { "class": "".concat(classPrefix, "-content-prefix") }, [prefix]), h("span", { "class": "".concat(classPrefix, "-content-value") }, [formatValue]), unit && h("span", { "class": "".concat(classPrefix, "-content-unit") }, [unit]), suffix && h("span", { "class": "".concat(classPrefix, "-content-suffix") }, [suffix])])]), extra && h("div", { "class": "".concat(classPrefix, "-extra") }, [extra])]); } }); export { _Statistic as default }; //# sourceMappingURL=statistic.js.map