tdesign-vue
Version:
249 lines (245 loc) • 9.8 kB
JavaScript
/**
* tdesign v1.14.1
* (c) 2025 tdesign
* @license MIT
*/
import _typeof from '@babel/runtime/helpers/typeof';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { CloseCircleFilledIcon, CheckCircleFilledIcon, ErrorCircleFilledIcon, CloseIcon, CheckIcon, ErrorIcon } from 'tdesign-icons-vue';
import { getBackgroundColor } from '../utils/helper.js';
import { STATUS_ICON, CIRCLE_SIZE_PX, PRO_THEME, CIRCLE_FONT_SIZE_RATIO, CIRCLE_SIZE } from './constants.js';
import props from './props.js';
import { renderTNodeJSX } from '../utils/render-tnode.js';
import { getClassPrefixMixins, getGlobalIconMixins } from '../config-provider/config-receiver.js';
import mixins from '../utils/mixins.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash-es';
import '@babel/runtime/helpers/readOnlyError';
import 'vue';
import '@vue/composition-api';
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-ba613a02.js';
import '../_chunks/dep-fdb1b253.js';
import 'dayjs';
import '../_common/js/global-config/t.js';
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var classPrefixMixins = getClassPrefixMixins("progress");
var _Progress = mixins(classPrefixMixins, getGlobalIconMixins()).extend({
name: "TProgress",
props: _objectSpread({}, props),
computed: {
statusStyle: function statusStyle() {
if (!this.status && this.percentage >= 100) {
return "success";
}
return this.status;
},
themeClass: function themeClass() {
var Line = PRO_THEME.LINE;
if (this.theme === Line) {
return "thin";
}
return this.theme;
},
trackBgStyle: function trackBgStyle() {
var strokeWidth = this.strokeWidth;
var height = typeof strokeWidth === "string" ? strokeWidth : "".concat(strokeWidth, "px");
var Plump = PRO_THEME.PLUMP;
if (this.theme === Plump) {
height = "";
}
return {
height: height,
backgroundColor: this.trackColor,
borderRadius: height
};
},
circleStrokeStyle: function circleStrokeStyle() {
return {
stroke: this.trackColor
};
},
barStyle: function barStyle() {
return {
width: "".concat(this.percentage, "%"),
background: this.color && getBackgroundColor(this.color)
};
},
circlePathStyle: function circlePathStyle() {
var strokeColor = _typeof(this.color) === "object" ? "" : this.color;
return {
stroke: strokeColor
};
},
isShowIcon: function isShowIcon() {
return STATUS_ICON.includes(this.status) && typeof this.label === "boolean";
},
diameter: function diameter() {
var diameter = CIRCLE_SIZE_PX.MEDIUM;
if (!this.size) {
return diameter;
}
var SMALL = CIRCLE_SIZE.SMALL,
LARGE = CIRCLE_SIZE.LARGE,
MEDIUM = CIRCLE_SIZE.MEDIUM;
switch (this.size) {
case SMALL:
diameter = CIRCLE_SIZE_PX.SMALL;
break;
case MEDIUM:
diameter = CIRCLE_SIZE_PX.MEDIUM;
break;
case LARGE:
diameter = CIRCLE_SIZE_PX.LARGE;
break;
default:
diameter = Number(this.size);
break;
}
return diameter;
},
rPoints: function rPoints() {
return this.diameter / 2;
},
radius: function radius() {
return this.rPoints - this.circleStrokeWidth / 2;
},
circleStyle: function circleStyle() {
if (this.theme !== PRO_THEME.CIRCLE) {
return {};
}
var fontSize = this.diameter * CIRCLE_FONT_SIZE_RATIO.MEDIUM;
if (this.diameter <= CIRCLE_SIZE_PX.SMALL) {
fontSize = this.diameter * CIRCLE_FONT_SIZE_RATIO.SMALL;
} else if (this.diameter >= CIRCLE_SIZE_PX.LARGE) {
fontSize = this.diameter * CIRCLE_FONT_SIZE_RATIO.LARGE;
}
return {
width: "".concat(this.diameter, "px"),
height: "".concat(this.diameter, "px"),
fontSize: "".concat(fontSize, "px")
};
},
circleStrokeWidth: function circleStrokeWidth() {
var defaultWidth = this.size === CIRCLE_SIZE.SMALL ? 4 : 6;
return this.strokeWidth ? Number(this.strokeWidth) : defaultWidth;
},
strokeDashArr: function strokeDashArr() {
var radius = (this.diameter - this.circleStrokeWidth) / 2;
var perimeter = Math.PI * 2 * radius;
var percent = this.percentage / 100;
return "".concat(perimeter * percent, " ").concat(perimeter * (1 - percent));
},
plumpStyles: function plumpStyles() {
return {};
}
},
methods: {
getIconMap: function getIconMap() {
var _this$useGlobalIcon = this.useGlobalIcon({
CloseCircleFilledIcon: CloseCircleFilledIcon,
CheckCircleFilledIcon: CheckCircleFilledIcon,
ErrorCircleFilledIcon: ErrorCircleFilledIcon,
CloseIcon: CloseIcon,
CheckIcon: CheckIcon,
ErrorIcon: ErrorIcon
}),
CloseCircleFilledIcon$1 = _this$useGlobalIcon.CloseCircleFilledIcon,
CheckCircleFilledIcon$1 = _this$useGlobalIcon.CheckCircleFilledIcon,
ErrorCircleFilledIcon$1 = _this$useGlobalIcon.ErrorCircleFilledIcon,
CloseIcon$1 = _this$useGlobalIcon.CloseIcon,
CheckIcon$1 = _this$useGlobalIcon.CheckIcon,
ErrorIcon$1 = _this$useGlobalIcon.ErrorIcon;
var CIRCLE_ICONS = {
success: CheckIcon$1,
warning: ErrorIcon$1,
error: CloseIcon$1
};
var NORMAL_ICONS = {
success: CheckCircleFilledIcon$1,
warning: ErrorCircleFilledIcon$1,
error: CloseCircleFilledIcon$1
};
return this.theme === PRO_THEME.CIRCLE ? CIRCLE_ICONS : NORMAL_ICONS;
},
getLabelContent: function getLabelContent() {
var h = this.$createElement;
var labelContent = "".concat(this.percentage, "%");
var status = this.status || "";
if (STATUS_ICON.includes(status) && this.theme !== PRO_THEME.PLUMP) {
var components = this.getIconMap();
var component = components[status];
if (component) {
labelContent = h(component, {
"class": ["".concat(this.componentName, "__icon")]
});
}
}
return labelContent;
}
},
render: function render() {
var h = arguments[0];
var labelContent = h("div", {
"class": "".concat(this.componentName, "__info")
}, [renderTNodeJSX(this, "label", this.getLabelContent())]);
var PLUMP_SEPARATE = 10;
var separateClasses = this.percentage > PLUMP_SEPARATE ? "".concat(this.componentName, "--over-ten") : "".concat(this.componentName, "--under-ten");
return h("div", {
"class": this.componentName
}, [this.theme === PRO_THEME.LINE && h("div", {
"class": "".concat(this.componentName, "--thin ").concat(this.componentName, "--status--").concat(this.statusStyle)
}, [h("div", {
"class": "".concat(this.componentName, "__bar"),
"style": this.trackBgStyle
}, [h("div", {
"class": "".concat(this.componentName, "__inner"),
"style": this.barStyle
})]), labelContent]), this.theme === PRO_THEME.PLUMP && h("div", {
"class": ["".concat(this.componentName, "__bar ").concat(this.componentName, "--plump ").concat(separateClasses), _defineProperty({}, "".concat(this.componentName, "--status--").concat(this.statusStyle), this.statusStyle)],
"style": this.trackBgStyle
}, [h("div", {
"class": "".concat(this.componentName, "__inner"),
"style": this.barStyle
}, [this.percentage > PLUMP_SEPARATE && labelContent]), this.percentage <= PLUMP_SEPARATE && labelContent]), this.theme === PRO_THEME.CIRCLE && h("div", {
"class": "".concat(this.componentName, "--circle ").concat(this.componentName, "--status--").concat(this.statusStyle),
"style": this.circleStyle
}, [labelContent, h("svg", {
"attrs": {
"width": this.diameter,
"height": this.diameter,
"viewBox": "0 0 ".concat(this.diameter, " ").concat(this.diameter)
}
}, [h("circle", {
"attrs": {
"cx": this.rPoints,
"cy": this.rPoints,
"r": this.radius,
"stroke-width": this.circleStrokeWidth,
"stroke": this.trackColor,
"fill": "none"
},
"class": "".concat(this.componentName, "__circle-outer"),
"style": this.circleStrokeStyle
}), this.percentage > 0 && h("circle", {
"attrs": {
"cx": this.rPoints,
"cy": this.rPoints,
"r": this.radius,
"stroke-width": this.circleStrokeWidth,
"fill": "none",
"stroke-linecap": "round",
"transform": "matrix(0,-1,1,0,0,".concat(this.diameter, ")"),
"stroke-dasharray": this.strokeDashArr
},
"class": "".concat(this.componentName, "__circle-inner"),
"style": this.circlePathStyle
})])])]);
}
});
export { _Progress as default };
//# sourceMappingURL=progress.js.map