item2.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. require('../../../hooks/index.js');
  5. var index$1 = require('../../icon/index.js');
  6. var iconsVue = require('@element-plus/icons-vue');
  7. var item = require('./item.js');
  8. var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
  9. var index = require('../../../hooks/use-namespace/index.js');
  10. const __default__ = vue.defineComponent({
  11. name: "ElStep"
  12. });
  13. const _sfc_main = vue.defineComponent({
  14. ...__default__,
  15. props: item.stepProps,
  16. setup(__props) {
  17. const props = __props;
  18. const ns = index.useNamespace("step");
  19. const index$2 = vue.ref(-1);
  20. const lineStyle = vue.ref({});
  21. const internalStatus = vue.ref("");
  22. const parent = vue.inject("ElSteps");
  23. const currentInstance = vue.getCurrentInstance();
  24. vue.onMounted(() => {
  25. vue.watch([
  26. () => parent.props.active,
  27. () => parent.props.processStatus,
  28. () => parent.props.finishStatus
  29. ], ([active]) => {
  30. updateStatus(active);
  31. }, { immediate: true });
  32. });
  33. vue.onBeforeUnmount(() => {
  34. parent.steps.value = parent.steps.value.filter((instance) => instance.uid !== (currentInstance == null ? void 0 : currentInstance.uid));
  35. });
  36. const currentStatus = vue.computed(() => {
  37. return props.status || internalStatus.value;
  38. });
  39. const prevStatus = vue.computed(() => {
  40. const prevStep = parent.steps.value[index$2.value - 1];
  41. return prevStep ? prevStep.currentStatus : "wait";
  42. });
  43. const isCenter = vue.computed(() => {
  44. return parent.props.alignCenter;
  45. });
  46. const isVertical = vue.computed(() => {
  47. return parent.props.direction === "vertical";
  48. });
  49. const isSimple = vue.computed(() => {
  50. return parent.props.simple;
  51. });
  52. const stepsCount = vue.computed(() => {
  53. return parent.steps.value.length;
  54. });
  55. const isLast = vue.computed(() => {
  56. var _a;
  57. return ((_a = parent.steps.value[stepsCount.value - 1]) == null ? void 0 : _a.uid) === (currentInstance == null ? void 0 : currentInstance.uid);
  58. });
  59. const space = vue.computed(() => {
  60. return isSimple.value ? "" : parent.props.space;
  61. });
  62. const style = vue.computed(() => {
  63. const style2 = {
  64. flexBasis: typeof space.value === "number" ? `${space.value}px` : space.value ? space.value : `${100 / (stepsCount.value - (isCenter.value ? 0 : 1))}%`
  65. };
  66. if (isVertical.value)
  67. return style2;
  68. if (isLast.value) {
  69. style2.maxWidth = `${100 / stepsCount.value}%`;
  70. }
  71. return style2;
  72. });
  73. const setIndex = (val) => {
  74. index$2.value = val;
  75. };
  76. const calcProgress = (status) => {
  77. let step = 100;
  78. const style2 = {};
  79. style2.transitionDelay = `${150 * index$2.value}ms`;
  80. if (status === parent.props.processStatus) {
  81. step = 0;
  82. } else if (status === "wait") {
  83. step = 0;
  84. style2.transitionDelay = `${-150 * index$2.value}ms`;
  85. }
  86. style2.borderWidth = step && !isSimple.value ? "1px" : 0;
  87. style2[parent.props.direction === "vertical" ? "height" : "width"] = `${step}%`;
  88. lineStyle.value = style2;
  89. };
  90. const updateStatus = (activeIndex) => {
  91. if (activeIndex > index$2.value) {
  92. internalStatus.value = parent.props.finishStatus;
  93. } else if (activeIndex === index$2.value && prevStatus.value !== "error") {
  94. internalStatus.value = parent.props.processStatus;
  95. } else {
  96. internalStatus.value = "wait";
  97. }
  98. const prevChild = parent.steps.value[index$2.value - 1];
  99. if (prevChild)
  100. prevChild.calcProgress(internalStatus.value);
  101. };
  102. const stepItemState = vue.reactive({
  103. uid: vue.computed(() => currentInstance == null ? void 0 : currentInstance.uid),
  104. currentStatus,
  105. setIndex,
  106. calcProgress
  107. });
  108. parent.steps.value = [...parent.steps.value, stepItemState];
  109. return (_ctx, _cache) => {
  110. return vue.openBlock(), vue.createElementBlock("div", {
  111. style: vue.normalizeStyle(vue.unref(style)),
  112. class: vue.normalizeClass([
  113. vue.unref(ns).b(),
  114. vue.unref(ns).is(vue.unref(isSimple) ? "simple" : vue.unref(parent).props.direction),
  115. vue.unref(ns).is("flex", vue.unref(isLast) && !vue.unref(space) && !vue.unref(isCenter)),
  116. vue.unref(ns).is("center", vue.unref(isCenter) && !vue.unref(isVertical) && !vue.unref(isSimple))
  117. ])
  118. }, [
  119. vue.createCommentVNode(" icon & line "),
  120. vue.createElementVNode("div", {
  121. class: vue.normalizeClass([vue.unref(ns).e("head"), vue.unref(ns).is(vue.unref(currentStatus))])
  122. }, [
  123. !vue.unref(isSimple) ? (vue.openBlock(), vue.createElementBlock("div", {
  124. key: 0,
  125. class: vue.normalizeClass(vue.unref(ns).e("line"))
  126. }, [
  127. vue.createElementVNode("i", {
  128. class: vue.normalizeClass(vue.unref(ns).e("line-inner")),
  129. style: vue.normalizeStyle(lineStyle.value)
  130. }, null, 6)
  131. ], 2)) : vue.createCommentVNode("v-if", true),
  132. vue.createElementVNode("div", {
  133. class: vue.normalizeClass([vue.unref(ns).e("icon"), vue.unref(ns).is(_ctx.icon || _ctx.$slots.icon ? "icon" : "text")])
  134. }, [
  135. vue.renderSlot(_ctx.$slots, "icon", {}, () => [
  136. _ctx.icon ? (vue.openBlock(), vue.createBlock(vue.unref(index$1.ElIcon), {
  137. key: 0,
  138. class: vue.normalizeClass(vue.unref(ns).e("icon-inner"))
  139. }, {
  140. default: vue.withCtx(() => [
  141. (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.icon)))
  142. ]),
  143. _: 1
  144. }, 8, ["class"])) : vue.unref(currentStatus) === "success" ? (vue.openBlock(), vue.createBlock(vue.unref(index$1.ElIcon), {
  145. key: 1,
  146. class: vue.normalizeClass([vue.unref(ns).e("icon-inner"), vue.unref(ns).is("status")])
  147. }, {
  148. default: vue.withCtx(() => [
  149. vue.createVNode(vue.unref(iconsVue.Check))
  150. ]),
  151. _: 1
  152. }, 8, ["class"])) : vue.unref(currentStatus) === "error" ? (vue.openBlock(), vue.createBlock(vue.unref(index$1.ElIcon), {
  153. key: 2,
  154. class: vue.normalizeClass([vue.unref(ns).e("icon-inner"), vue.unref(ns).is("status")])
  155. }, {
  156. default: vue.withCtx(() => [
  157. vue.createVNode(vue.unref(iconsVue.Close))
  158. ]),
  159. _: 1
  160. }, 8, ["class"])) : !vue.unref(isSimple) ? (vue.openBlock(), vue.createElementBlock("div", {
  161. key: 3,
  162. class: vue.normalizeClass(vue.unref(ns).e("icon-inner"))
  163. }, vue.toDisplayString(index$2.value + 1), 3)) : vue.createCommentVNode("v-if", true)
  164. ])
  165. ], 2)
  166. ], 2),
  167. vue.createCommentVNode(" title & description "),
  168. vue.createElementVNode("div", {
  169. class: vue.normalizeClass(vue.unref(ns).e("main"))
  170. }, [
  171. vue.createElementVNode("div", {
  172. class: vue.normalizeClass([vue.unref(ns).e("title"), vue.unref(ns).is(vue.unref(currentStatus))])
  173. }, [
  174. vue.renderSlot(_ctx.$slots, "title", {}, () => [
  175. vue.createTextVNode(vue.toDisplayString(_ctx.title), 1)
  176. ])
  177. ], 2),
  178. vue.unref(isSimple) ? (vue.openBlock(), vue.createElementBlock("div", {
  179. key: 0,
  180. class: vue.normalizeClass(vue.unref(ns).e("arrow"))
  181. }, null, 2)) : (vue.openBlock(), vue.createElementBlock("div", {
  182. key: 1,
  183. class: vue.normalizeClass([vue.unref(ns).e("description"), vue.unref(ns).is(vue.unref(currentStatus))])
  184. }, [
  185. vue.renderSlot(_ctx.$slots, "description", {}, () => [
  186. vue.createTextVNode(vue.toDisplayString(_ctx.description), 1)
  187. ])
  188. ], 2))
  189. ], 2)
  190. ], 6);
  191. };
  192. }
  193. });
  194. var Step = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "/home/runner/work/element-plus/element-plus/packages/components/steps/src/item.vue"]]);
  195. exports["default"] = Step;
  196. //# sourceMappingURL=item2.js.map