progress.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
  3. import { createVNode as _createVNode } from "vue";
  4. import { computed, defineComponent } from 'vue';
  5. import initDefaultProps from '../_util/props-util/initDefaultProps';
  6. import CloseOutlined from "@ant-design/icons-vue/es/icons/CloseOutlined";
  7. import CheckOutlined from "@ant-design/icons-vue/es/icons/CheckOutlined";
  8. import CheckCircleFilled from "@ant-design/icons-vue/es/icons/CheckCircleFilled";
  9. import CloseCircleFilled from "@ant-design/icons-vue/es/icons/CloseCircleFilled";
  10. import Line from './Line';
  11. import Circle from './Circle';
  12. import Steps from './Steps';
  13. import { getSuccessPercent, validProgress } from './utils';
  14. import useConfigInject from '../_util/hooks/useConfigInject';
  15. import devWarning from '../vc-util/devWarning';
  16. import { progressProps, progressStatuses } from './props';
  17. export default defineComponent({
  18. compatConfig: {
  19. MODE: 3
  20. },
  21. name: 'AProgress',
  22. props: initDefaultProps(progressProps(), {
  23. type: 'line',
  24. percent: 0,
  25. showInfo: true,
  26. // null for different theme definition
  27. trailColor: null,
  28. size: 'default',
  29. strokeLinecap: 'round'
  30. }),
  31. slots: ['format'],
  32. setup: function setup(props, _ref) {
  33. var slots = _ref.slots;
  34. var _useConfigInject = useConfigInject('progress', props),
  35. prefixCls = _useConfigInject.prefixCls,
  36. direction = _useConfigInject.direction;
  37. devWarning(props.successPercent == undefined, 'Progress', '`successPercent` is deprecated. Please use `success.percent` instead.');
  38. var classString = computed(function () {
  39. var _ref2;
  40. var type = props.type,
  41. showInfo = props.showInfo,
  42. size = props.size;
  43. var pre = prefixCls.value;
  44. return _ref2 = {}, _defineProperty(_ref2, pre, true), _defineProperty(_ref2, "".concat(pre, "-").concat(type === 'dashboard' && 'circle' || type), true), _defineProperty(_ref2, "".concat(pre, "-show-info"), showInfo), _defineProperty(_ref2, "".concat(pre, "-").concat(size), size), _defineProperty(_ref2, "".concat(pre, "-rtl"), direction.value === 'rtl'), _ref2;
  45. });
  46. var percentNumber = computed(function () {
  47. var _props$percent = props.percent,
  48. percent = _props$percent === void 0 ? 0 : _props$percent;
  49. var successPercent = getSuccessPercent(props);
  50. return parseInt(successPercent !== undefined ? successPercent.toString() : percent.toString(), 10);
  51. });
  52. var progressStatus = computed(function () {
  53. var status = props.status;
  54. if (progressStatuses.indexOf(status) < 0 && percentNumber.value >= 100) {
  55. return 'success';
  56. }
  57. return status || 'normal';
  58. });
  59. var renderProcessInfo = function renderProcessInfo() {
  60. var showInfo = props.showInfo,
  61. format = props.format,
  62. type = props.type,
  63. percent = props.percent,
  64. title = props.title;
  65. var successPercent = getSuccessPercent(props);
  66. if (!showInfo) return null;
  67. var text;
  68. var textFormatter = format || (slots === null || slots === void 0 ? void 0 : slots.format) || function (val) {
  69. return "".concat(val, "%");
  70. };
  71. var isLineType = type === 'line';
  72. if (format || slots !== null && slots !== void 0 && slots.format || progressStatus.value !== 'exception' && progressStatus.value !== 'success') {
  73. text = textFormatter(validProgress(percent), validProgress(successPercent));
  74. } else if (progressStatus.value === 'exception') {
  75. text = isLineType ? _createVNode(CloseCircleFilled, null, null) : _createVNode(CloseOutlined, null, null);
  76. } else if (progressStatus.value === 'success') {
  77. text = isLineType ? _createVNode(CheckCircleFilled, null, null) : _createVNode(CheckOutlined, null, null);
  78. }
  79. return _createVNode("span", {
  80. "class": "".concat(prefixCls.value, "-text"),
  81. "title": title === undefined && typeof text === 'string' ? text : undefined
  82. }, [text]);
  83. };
  84. return function () {
  85. var type = props.type,
  86. steps = props.steps,
  87. strokeColor = props.strokeColor,
  88. title = props.title;
  89. var progressInfo = renderProcessInfo();
  90. var progress;
  91. // Render progress shape
  92. if (type === 'line') {
  93. progress = steps ? _createVNode(Steps, _objectSpread(_objectSpread({}, props), {}, {
  94. "strokeColor": typeof strokeColor === 'string' ? strokeColor : undefined,
  95. "prefixCls": prefixCls.value,
  96. "steps": steps
  97. }), {
  98. default: function _default() {
  99. return [progressInfo];
  100. }
  101. }) : _createVNode(Line, _objectSpread(_objectSpread({}, props), {}, {
  102. "prefixCls": prefixCls.value
  103. }), {
  104. default: function _default() {
  105. return [progressInfo];
  106. }
  107. });
  108. } else if (type === 'circle' || type === 'dashboard') {
  109. progress = _createVNode(Circle, _objectSpread(_objectSpread({}, props), {}, {
  110. "prefixCls": prefixCls.value
  111. }), {
  112. default: function _default() {
  113. return [progressInfo];
  114. }
  115. });
  116. }
  117. var classNames = _objectSpread(_objectSpread({}, classString.value), {}, _defineProperty({}, "".concat(prefixCls.value, "-status-").concat(progressStatus.value), true));
  118. return _createVNode("div", {
  119. "class": classNames,
  120. "title": title
  121. }, [progress]);
  122. };
  123. }
  124. });