UNPKG

tdesign-vue

Version:
216 lines (210 loc) 9.11 kB
/** * tdesign v1.12.1 * (c) 2025 tdesign * @license MIT */ 'use strict'; 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-2edcfe51.js'); var isFunction = require('../_chunks/dep-411a10dd.js'); require('@babel/runtime/helpers/defineProperty'); require('@babel/runtime/helpers/readOnlyError'); require('@babel/runtime/helpers/typeof'); require('vue'); require('../_chunks/dep-bf70543d.js'); require('../_chunks/dep-f895c884.js'); require('../_chunks/dep-e1cc6f64.js'); require('../_chunks/dep-5ea2b00f.js'); require('../_chunks/dep-9b72cbc5.js'); require('../_chunks/dep-7b78e8c3.js'); require('../_chunks/dep-d7270eaf.js'); require('../_chunks/dep-68f48b50.js'); require('../_chunks/dep-051ce30d.js'); require('../_chunks/dep-4b30bfe2.js'); require('../_chunks/dep-727a349e.js'); require('../config-provider/useConfig.js'); require('../_chunks/dep-6247fdbf.js'); require('../_common/js/global-config/default-config.js'); require('../_common/js/global-config/locale/zh_CN.js'); require('../_chunks/dep-3ed0c42e.js'); require('../_chunks/dep-53935099.js'); require('dayjs'); require('../_chunks/dep-403352a7.js'); require('../_chunks/dep-cca66fee.js'); require('../_chunks/dep-4361b357.js'); require('../_chunks/dep-887c649b.js'); require('../_chunks/dep-51fe98f1.js'); require('../_chunks/dep-3d682642.js'); require('../_chunks/dep-dea23841.js'); require('../_chunks/dep-4aa08166.js'); require('../_chunks/dep-ddc1429e.js'); require('../_chunks/dep-65896ff9.js'); require('../_chunks/dep-b65b2f55.js'); require('../_chunks/dep-6e7b8cda.js'); require('../_chunks/dep-98f48ff2.js'); require('../_chunks/dep-80e3757f.js'); require('../_chunks/dep-08d7842c.js'); require('../_chunks/dep-1ca3138c.js'); require('../_chunks/dep-e6ed4b1f.js'); require('../_chunks/dep-c44b2462.js'); require('../_common/js/global-config/t.js'); require('@babel/runtime/helpers/slicedToArray'); require('../_chunks/dep-6b60413b.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-5a0b1276.js'); require('../_chunks/dep-2d34b118.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