progress2.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var index$1 = require('../../icon/index.js');
  5. var iconsVue = require('@element-plus/icons-vue');
  6. var progress = require('./progress.js');
  7. var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
  8. var index = require('../../../hooks/use-namespace/index.js');
  9. var shared = require('@vue/shared');
  10. const __default__ = vue.defineComponent({
  11. name: "ElProgress"
  12. });
  13. const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  14. ...__default__,
  15. props: progress.progressProps,
  16. setup(__props) {
  17. const props = __props;
  18. const STATUS_COLOR_MAP = {
  19. success: "#13ce66",
  20. exception: "#ff4949",
  21. warning: "#e6a23c",
  22. default: "#20a0ff"
  23. };
  24. const ns = index.useNamespace("progress");
  25. const barStyle = vue.computed(() => {
  26. const barStyle2 = {
  27. width: `${props.percentage}%`,
  28. animationDuration: `${props.duration}s`
  29. };
  30. const color = getCurrentColor(props.percentage);
  31. if (color.includes("gradient")) {
  32. barStyle2.background = color;
  33. } else {
  34. barStyle2.backgroundColor = color;
  35. }
  36. return barStyle2;
  37. });
  38. const relativeStrokeWidth = vue.computed(() => (props.strokeWidth / props.width * 100).toFixed(1));
  39. const radius = vue.computed(() => {
  40. if (["circle", "dashboard"].includes(props.type)) {
  41. return Number.parseInt(`${50 - Number.parseFloat(relativeStrokeWidth.value) / 2}`, 10);
  42. }
  43. return 0;
  44. });
  45. const trackPath = vue.computed(() => {
  46. const r = radius.value;
  47. const isDashboard = props.type === "dashboard";
  48. return `
  49. M 50 50
  50. m 0 ${isDashboard ? "" : "-"}${r}
  51. a ${r} ${r} 0 1 1 0 ${isDashboard ? "-" : ""}${r * 2}
  52. a ${r} ${r} 0 1 1 0 ${isDashboard ? "" : "-"}${r * 2}
  53. `;
  54. });
  55. const perimeter = vue.computed(() => 2 * Math.PI * radius.value);
  56. const rate = vue.computed(() => props.type === "dashboard" ? 0.75 : 1);
  57. const strokeDashoffset = vue.computed(() => {
  58. const offset = -1 * perimeter.value * (1 - rate.value) / 2;
  59. return `${offset}px`;
  60. });
  61. const trailPathStyle = vue.computed(() => ({
  62. strokeDasharray: `${perimeter.value * rate.value}px, ${perimeter.value}px`,
  63. strokeDashoffset: strokeDashoffset.value
  64. }));
  65. const circlePathStyle = vue.computed(() => ({
  66. strokeDasharray: `${perimeter.value * rate.value * (props.percentage / 100)}px, ${perimeter.value}px`,
  67. strokeDashoffset: strokeDashoffset.value,
  68. transition: "stroke-dasharray 0.6s ease 0s, stroke 0.6s ease, opacity ease 0.6s"
  69. }));
  70. const stroke = vue.computed(() => {
  71. let ret;
  72. if (props.color) {
  73. ret = getCurrentColor(props.percentage);
  74. } else {
  75. ret = STATUS_COLOR_MAP[props.status] || STATUS_COLOR_MAP.default;
  76. }
  77. return ret;
  78. });
  79. const statusIcon = vue.computed(() => {
  80. if (props.status === "warning") {
  81. return iconsVue.WarningFilled;
  82. }
  83. if (props.type === "line") {
  84. return props.status === "success" ? iconsVue.CircleCheck : iconsVue.CircleClose;
  85. } else {
  86. return props.status === "success" ? iconsVue.Check : iconsVue.Close;
  87. }
  88. });
  89. const progressTextSize = vue.computed(() => {
  90. return props.type === "line" ? 12 + props.strokeWidth * 0.4 : props.width * 0.111111 + 2;
  91. });
  92. const content = vue.computed(() => props.format(props.percentage));
  93. function getColors(color) {
  94. const span = 100 / color.length;
  95. const seriesColors = color.map((seriesColor, index) => {
  96. if (shared.isString(seriesColor)) {
  97. return {
  98. color: seriesColor,
  99. percentage: (index + 1) * span
  100. };
  101. }
  102. return seriesColor;
  103. });
  104. return seriesColors.sort((a, b) => a.percentage - b.percentage);
  105. }
  106. const getCurrentColor = (percentage) => {
  107. var _a;
  108. const { color } = props;
  109. if (shared.isFunction(color)) {
  110. return color(percentage);
  111. } else if (shared.isString(color)) {
  112. return color;
  113. } else {
  114. const colors = getColors(color);
  115. for (const color2 of colors) {
  116. if (color2.percentage > percentage)
  117. return color2.color;
  118. }
  119. return (_a = colors[colors.length - 1]) == null ? void 0 : _a.color;
  120. }
  121. };
  122. return (_ctx, _cache) => {
  123. return vue.openBlock(), vue.createElementBlock("div", {
  124. class: vue.normalizeClass([
  125. vue.unref(ns).b(),
  126. vue.unref(ns).m(_ctx.type),
  127. vue.unref(ns).is(_ctx.status),
  128. {
  129. [vue.unref(ns).m("without-text")]: !_ctx.showText,
  130. [vue.unref(ns).m("text-inside")]: _ctx.textInside
  131. }
  132. ]),
  133. role: "progressbar",
  134. "aria-valuenow": _ctx.percentage,
  135. "aria-valuemin": "0",
  136. "aria-valuemax": "100"
  137. }, [
  138. _ctx.type === "line" ? (vue.openBlock(), vue.createElementBlock("div", {
  139. key: 0,
  140. class: vue.normalizeClass(vue.unref(ns).b("bar"))
  141. }, [
  142. vue.createElementVNode("div", {
  143. class: vue.normalizeClass(vue.unref(ns).be("bar", "outer")),
  144. style: vue.normalizeStyle({ height: `${_ctx.strokeWidth}px` })
  145. }, [
  146. vue.createElementVNode("div", {
  147. class: vue.normalizeClass([
  148. vue.unref(ns).be("bar", "inner"),
  149. { [vue.unref(ns).bem("bar", "inner", "indeterminate")]: _ctx.indeterminate },
  150. { [vue.unref(ns).bem("bar", "inner", "striped")]: _ctx.striped },
  151. { [vue.unref(ns).bem("bar", "inner", "striped-flow")]: _ctx.stripedFlow }
  152. ]),
  153. style: vue.normalizeStyle(vue.unref(barStyle))
  154. }, [
  155. (_ctx.showText || _ctx.$slots.default) && _ctx.textInside ? (vue.openBlock(), vue.createElementBlock("div", {
  156. key: 0,
  157. class: vue.normalizeClass(vue.unref(ns).be("bar", "innerText"))
  158. }, [
  159. vue.renderSlot(_ctx.$slots, "default", { percentage: _ctx.percentage }, () => [
  160. vue.createElementVNode("span", null, vue.toDisplayString(vue.unref(content)), 1)
  161. ])
  162. ], 2)) : vue.createCommentVNode("v-if", true)
  163. ], 6)
  164. ], 6)
  165. ], 2)) : (vue.openBlock(), vue.createElementBlock("div", {
  166. key: 1,
  167. class: vue.normalizeClass(vue.unref(ns).b("circle")),
  168. style: vue.normalizeStyle({ height: `${_ctx.width}px`, width: `${_ctx.width}px` })
  169. }, [
  170. (vue.openBlock(), vue.createElementBlock("svg", { viewBox: "0 0 100 100" }, [
  171. vue.createElementVNode("path", {
  172. class: vue.normalizeClass(vue.unref(ns).be("circle", "track")),
  173. d: vue.unref(trackPath),
  174. stroke: `var(${vue.unref(ns).cssVarName("fill-color-light")}, #e5e9f2)`,
  175. "stroke-linecap": _ctx.strokeLinecap,
  176. "stroke-width": vue.unref(relativeStrokeWidth),
  177. fill: "none",
  178. style: vue.normalizeStyle(vue.unref(trailPathStyle))
  179. }, null, 14, ["d", "stroke", "stroke-linecap", "stroke-width"]),
  180. vue.createElementVNode("path", {
  181. class: vue.normalizeClass(vue.unref(ns).be("circle", "path")),
  182. d: vue.unref(trackPath),
  183. stroke: vue.unref(stroke),
  184. fill: "none",
  185. opacity: _ctx.percentage ? 1 : 0,
  186. "stroke-linecap": _ctx.strokeLinecap,
  187. "stroke-width": vue.unref(relativeStrokeWidth),
  188. style: vue.normalizeStyle(vue.unref(circlePathStyle))
  189. }, null, 14, ["d", "stroke", "opacity", "stroke-linecap", "stroke-width"])
  190. ]))
  191. ], 6)),
  192. (_ctx.showText || _ctx.$slots.default) && !_ctx.textInside ? (vue.openBlock(), vue.createElementBlock("div", {
  193. key: 2,
  194. class: vue.normalizeClass(vue.unref(ns).e("text")),
  195. style: vue.normalizeStyle({ fontSize: `${vue.unref(progressTextSize)}px` })
  196. }, [
  197. vue.renderSlot(_ctx.$slots, "default", { percentage: _ctx.percentage }, () => [
  198. !_ctx.status ? (vue.openBlock(), vue.createElementBlock("span", { key: 0 }, vue.toDisplayString(vue.unref(content)), 1)) : (vue.openBlock(), vue.createBlock(vue.unref(index$1.ElIcon), { key: 1 }, {
  199. default: vue.withCtx(() => [
  200. (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(vue.unref(statusIcon))))
  201. ]),
  202. _: 1
  203. }))
  204. ])
  205. ], 6)) : vue.createCommentVNode("v-if", true)
  206. ], 10, ["aria-valuenow"]);
  207. };
  208. }
  209. });
  210. var Progress = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "progress.vue"]]);
  211. exports["default"] = Progress;
  212. //# sourceMappingURL=progress2.js.map