You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
7.6 KiB

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