|
|
@@ -1,38 +1,25 @@
|
|
|
-<template>
|
|
|
- <view :class="classes">
|
|
|
- <slot></slot>
|
|
|
- </view>
|
|
|
-</template>
|
|
|
-
|
|
|
<script lang="ts">
|
|
|
import {
|
|
|
provide,
|
|
|
computed,
|
|
|
- onMounted,
|
|
|
reactive,
|
|
|
- watch,
|
|
|
- onBeforeMount
|
|
|
+ h,
|
|
|
+ ComponentInternalInstance
|
|
|
} from 'vue';
|
|
|
-import step from '@/packages/step/index.vue';
|
|
|
+import Step from '@/packages/step/index.vue';
|
|
|
import { createComponent } from '@/utils/create';
|
|
|
const { create, componentName } = createComponent('steps');
|
|
|
|
|
|
export default create({
|
|
|
- children: [step],
|
|
|
+ children: [Step],
|
|
|
props: {
|
|
|
direction: {
|
|
|
type: String,
|
|
|
default: 'horizontal'
|
|
|
},
|
|
|
current: {
|
|
|
- type: String,
|
|
|
- default: 'false'
|
|
|
- },
|
|
|
- status: {
|
|
|
- validator(value) {
|
|
|
- return ['wait', 'process', 'finish', 'error'].includes(value);
|
|
|
- },
|
|
|
- default: 'process'
|
|
|
+ type: [String, Number],
|
|
|
+ default: '0'
|
|
|
},
|
|
|
progressDot: {
|
|
|
type: Boolean,
|
|
|
@@ -41,87 +28,37 @@ export default create({
|
|
|
},
|
|
|
setup(props, { emit, slots }) {
|
|
|
const state = reactive({
|
|
|
- steps: {},
|
|
|
- children: []
|
|
|
+ children: [] as ComponentInternalInstance[]
|
|
|
});
|
|
|
+
|
|
|
const classes = computed(() => {
|
|
|
const prefixCls = componentName;
|
|
|
return {
|
|
|
[prefixCls]: true,
|
|
|
- ['nut-steps-' + props.direction]: true,
|
|
|
- [props.progressDot ? 'nut-steps-dot' : '']: true
|
|
|
+ [`${prefixCls}-${props.direction}`]: true,
|
|
|
+ [`${prefixCls}-dot`]: !!props.progressDot
|
|
|
};
|
|
|
});
|
|
|
- onBeforeMount(() => {
|
|
|
- console.log('onBeforeMount');
|
|
|
- init();
|
|
|
- });
|
|
|
- onMounted(() => {
|
|
|
- console.log('onMounted');
|
|
|
- // init();
|
|
|
- });
|
|
|
- // watch(
|
|
|
- // () => props.current,
|
|
|
- // val => {
|
|
|
- // console.log()
|
|
|
- // states();
|
|
|
- // }
|
|
|
- // );
|
|
|
- // watch(
|
|
|
- // () => props.source,
|
|
|
- // val => {
|
|
|
- // init();
|
|
|
- // }
|
|
|
- // )
|
|
|
- const init = () => {
|
|
|
- state.steps = (slots as any)?.default();
|
|
|
- stepStates();
|
|
|
- };
|
|
|
- const stepStates = () => {
|
|
|
- if (props.progressDot) {
|
|
|
- console.log('state.steps', state.steps);
|
|
|
- state.steps.dot = true;
|
|
|
- }
|
|
|
- const total = state.steps.length;
|
|
|
- state.steps.forEach((child, index) => {
|
|
|
- child.stepNumber = index + 1;
|
|
|
-
|
|
|
- state.children = index;
|
|
|
- // console.log('data', state.children)
|
|
|
|
|
|
- if (props.direction === 'horizontal') {
|
|
|
- child.total = total;
|
|
|
- }
|
|
|
- // console.log('父', child);
|
|
|
- if (!child.currentStatus) {
|
|
|
- if (index == props.current - 1) {
|
|
|
- if (props.status != 'error') {
|
|
|
- child.currentStatus = 'nut-step-process';
|
|
|
- } else {
|
|
|
- child.currentStatus = 'error';
|
|
|
- }
|
|
|
- } else if (index < props.current) {
|
|
|
- child.currentStatus = 'nut-step-finish';
|
|
|
- } else {
|
|
|
- child.currentStatus = 'nut-step-wait';
|
|
|
- }
|
|
|
- }
|
|
|
- if (index + 1 === total) {
|
|
|
- child.currentStatus += ' nut-step-last';
|
|
|
- }
|
|
|
- });
|
|
|
+ const relation = (child: ComponentInternalInstance) => {
|
|
|
+ child && state.children.push(child);
|
|
|
};
|
|
|
- // provide('parent', {
|
|
|
- // slots
|
|
|
- // });
|
|
|
- provide('stepsParent', {
|
|
|
- props,
|
|
|
- state
|
|
|
+
|
|
|
+ provide('parent', {
|
|
|
+ relation,
|
|
|
+ state,
|
|
|
+ props
|
|
|
});
|
|
|
- return {
|
|
|
- classes,
|
|
|
- stepStates
|
|
|
- };
|
|
|
+
|
|
|
+ return () => {
|
|
|
+ return h(
|
|
|
+ 'view',
|
|
|
+ {
|
|
|
+ class: classes.value
|
|
|
+ },
|
|
|
+ slots.default?.()
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
</script>
|