tdesign-vue
Version:
217 lines (211 loc) • 9.15 kB
JavaScript
/**
* tdesign v1.15.0
* (c) 2026 tdesign
* @license MIT
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var VueCompositionAPI = require('@vue/composition-api');
var tdesignIconsVue = require('tdesign-icons-vue');
var statistic_props = require('./props.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var hooks_useGlobalIcon = require('../hooks/useGlobalIcon.js');
var skeleton_index = require('../skeleton/index.js');
var _common_js_statistic_tween = require('../_common/js/statistic/tween.js');
var _common_js_statistic_utils = require('../_common/js/statistic/utils.js');
var isNumber = require('../_chunks/dep-268c68b1.js');
var isFunction = require('../_chunks/dep-8d206316.js');
require('@babel/runtime/helpers/defineProperty');
require('@babel/runtime/helpers/readOnlyError');
require('@babel/runtime/helpers/typeof');
require('vue');
require('../_chunks/dep-9c5b91d3.js');
require('../_chunks/dep-9a74c2be.js');
require('../_chunks/dep-689d381f.js');
require('../_chunks/dep-3b2292ce.js');
require('../_chunks/dep-10fcb46d.js');
require('../_chunks/dep-803744d9.js');
require('../_chunks/dep-ba7f5924.js');
require('../_chunks/dep-84027b7f.js');
require('../_chunks/dep-49400b00.js');
require('../_chunks/dep-f1081d8e.js');
require('../_chunks/dep-2c592e99.js');
require('../config-provider/useConfig.js');
require('../_chunks/dep-8eddb350.js');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-0c37520c.js');
require('../_chunks/dep-c13dcbfd.js');
require('dayjs');
require('../_chunks/dep-6f4e680e.js');
require('../_chunks/dep-bb0ececf.js');
require('../_chunks/dep-6eba4d23.js');
require('../_chunks/dep-010db548.js');
require('../_chunks/dep-f77d6ad5.js');
require('../_chunks/dep-9dae8101.js');
require('../_chunks/dep-7c84d9a0.js');
require('../_chunks/dep-733a2279.js');
require('../_chunks/dep-2bc87cc8.js');
require('../_chunks/dep-d844c9ed.js');
require('../_chunks/dep-c05a9033.js');
require('../_chunks/dep-efe55b82.js');
require('../_chunks/dep-7da70ee1.js');
require('../_chunks/dep-124386d4.js');
require('../_chunks/dep-f5b14344.js');
require('../_chunks/dep-36c2788b.js');
require('../_chunks/dep-fa353fbb.js');
require('../_chunks/dep-d66ab3a4.js');
require('../_chunks/dep-d4d8c513.js');
require('../_common/js/global-config/t.js');
require('@babel/runtime/helpers/slicedToArray');
require('../_chunks/dep-a2217d56.js');
require('../skeleton/skeleton.js');
require('../skeleton/props.js');
require('../config-provider/config-receiver.js');
require('../utils/mixins.js');
require('../utils/withInstall.js');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/objectWithoutProperties');
require('../_chunks/dep-721fcdf6.js');
require('../_chunks/dep-591b87f1.js');
var _Statistic = VueCompositionAPI.defineComponent({
name: "Statistic",
props: statistic_props["default"],
setup: function setup(props2) {
var _props2$animation$val, _props2$animation;
var classPrefix = hooks_useConfig.usePrefixClass("statistic");
var _toRefs = VueCompositionAPI.toRefs(props2),
value = _toRefs.value,
decimalPlaces = _toRefs.decimalPlaces,
separator = _toRefs.separator,
color = _toRefs.color;
var innerValue = VueCompositionAPI.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 = VueCompositionAPI.ref(null);
var numberValue = VueCompositionAPI.computed(function () {
return isNumber.isNumber(props2.value) ? props2.value : 0;
});
var valueStyle = VueCompositionAPI.computed(function () {
return {
color: _common_js_statistic_utils.COLOR_MAP[color.value] || color.value
};
});
var innerDecimalPlaces = VueCompositionAPI.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 _common_js_statistic_tween["default"]({
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 = VueCompositionAPI.computed(function () {
if (isFunction.isFunction(props2.format)) {
return props2.format(innerValue.value);
}
return _common_js_statistic_utils.getFormatValue(innerValue.value, decimalPlaces.value, separator.value);
});
VueCompositionAPI.onMounted(function () {
return props2.animation && props2.animationStart && start();
});
VueCompositionAPI.watch(function () {
return props2.animationStart;
}, function (value2) {
if (props2.animation && value2 && !tween.value) {
start();
}
});
VueCompositionAPI.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 = hooks_useGlobalIcon.useGlobalIcon({
ArrowTriangleUpFilledIcon: tdesignIconsVue.ArrowTriangleUpFilledIcon
}),
ArrowTriangleUpFilledIcon = _useGlobalIcon.ArrowTriangleUpFilledIcon;
var _useGlobalIcon2 = hooks_useGlobalIcon.useGlobalIcon({
ArrowTriangleDownFilledIcon: tdesignIconsVue.ArrowTriangleDownFilledIcon
}),
ArrowTriangleDownFilledIcon = _useGlobalIcon2.ArrowTriangleDownFilledIcon;
var trendIcons = {
increase: h(ArrowTriangleUpFilledIcon),
decrease: h(ArrowTriangleDownFilledIcon)
};
var trendIcon = trend ? trendIcons[trend] : null;
var prefix = utils_renderTnode.renderTNodeJSX(this, "prefix") || (trendIcon && trendPlacement !== "right" ? trendIcon : null);
var suffix = utils_renderTnode.renderTNodeJSX(this, "suffix") || (trendIcon && trendPlacement === "right" ? trendIcon : null);
var title = utils_renderTnode.renderTNodeJSX(this, "title");
var unit = utils_renderTnode.renderTNodeJSX(this, "unit");
var extra = utils_renderTnode.renderTNodeJSX(this, "extra");
return h("div", {
"class": classPrefix
}, [title && h("div", {
"class": "".concat(classPrefix, "-title")
}, [title]), h(skeleton_index.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])]);
}
});
exports["default"] = _Statistic;
//# sourceMappingURL=statistic.js.map