2020-06-22 14:21:40 +08:00
|
|
|
import { inject } from 'vue';
|
2020-03-31 00:02:28 +08:00
|
|
|
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
|
|
|
|
import CheckOutlined from '@ant-design/icons-vue/CheckOutlined';
|
2020-10-11 21:31:57 +08:00
|
|
|
import PropTypes, { withUndefined } from '../_util/vue-types';
|
2020-06-22 16:26:10 +08:00
|
|
|
import { initDefaultProps, getOptionProps, getComponent, getSlot } from '../_util/props-util';
|
2019-01-12 11:33:27 +08:00
|
|
|
import VcSteps from '../vc-steps';
|
2020-09-30 10:47:18 +08:00
|
|
|
import { defaultConfigProvider } from '../config-provider';
|
2018-03-09 18:52:31 +08:00
|
|
|
|
|
|
|
const getStepsProps = (defaultProps = {}) => {
|
|
|
|
const props = {
|
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
iconPrefix: PropTypes.string,
|
|
|
|
current: PropTypes.number,
|
2018-11-30 10:50:26 +08:00
|
|
|
initial: PropTypes.number,
|
2018-12-10 13:42:19 +08:00
|
|
|
labelPlacement: PropTypes.oneOf(['horizontal', 'vertical']).def('horizontal'),
|
2018-03-09 18:52:31 +08:00
|
|
|
status: PropTypes.oneOf(['wait', 'process', 'finish', 'error']),
|
|
|
|
size: PropTypes.oneOf(['default', 'small']),
|
|
|
|
direction: PropTypes.oneOf(['horizontal', 'vertical']),
|
2020-10-11 21:31:57 +08:00
|
|
|
progressDot: withUndefined(PropTypes.oneOfType([PropTypes.looseBool, PropTypes.func])),
|
2020-03-07 19:45:13 +08:00
|
|
|
type: PropTypes.oneOf(['default', 'navigation']),
|
2020-09-07 17:18:50 +08:00
|
|
|
onChange: PropTypes.func,
|
|
|
|
'onUpdate:current': PropTypes.func,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
|
|
|
return initDefaultProps(props, defaultProps);
|
|
|
|
};
|
2018-03-09 18:52:31 +08:00
|
|
|
|
2018-09-19 13:21:57 +08:00
|
|
|
const Steps = {
|
2018-04-08 21:17:20 +08:00
|
|
|
name: 'ASteps',
|
2020-09-07 17:18:50 +08:00
|
|
|
inheritAttrs: false,
|
2018-03-09 18:52:31 +08:00
|
|
|
props: getStepsProps({
|
|
|
|
current: 0,
|
|
|
|
}),
|
2020-06-22 14:21:40 +08:00
|
|
|
setup() {
|
|
|
|
return {
|
2020-09-30 10:47:18 +08:00
|
|
|
configProvider: inject('configProvider', defaultConfigProvider),
|
2020-06-22 14:21:40 +08:00
|
|
|
};
|
2020-03-07 19:45:13 +08:00
|
|
|
},
|
2018-04-08 21:17:20 +08:00
|
|
|
Step: { ...VcSteps.Step, name: 'AStep' },
|
2020-09-07 17:18:50 +08:00
|
|
|
methods: {
|
|
|
|
handleChange(current) {
|
|
|
|
this.$emit('update:current', current);
|
|
|
|
this.$emit('change', current);
|
|
|
|
},
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
2020-09-07 17:18:50 +08:00
|
|
|
const props = { ...getOptionProps(this), ...this.$attrs };
|
2019-03-18 20:35:24 +08:00
|
|
|
const { prefixCls: customizePrefixCls, iconPrefix: customizeIconPrefixCls } = props;
|
2019-09-11 22:35:25 +08:00
|
|
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
2019-03-18 20:35:24 +08:00
|
|
|
const prefixCls = getPrefixCls('steps', customizePrefixCls);
|
|
|
|
const iconPrefix = getPrefixCls('', customizeIconPrefixCls);
|
2020-06-22 14:21:40 +08:00
|
|
|
const progressDot = getComponent(this, 'progressDot', this, false);
|
2019-03-18 20:35:24 +08:00
|
|
|
|
2018-11-30 10:50:26 +08:00
|
|
|
const icons = {
|
2020-03-31 00:02:28 +08:00
|
|
|
finish: <CheckOutlined class={`${prefixCls}-finish-icon`} />,
|
|
|
|
error: <CloseOutlined class={`${prefixCls}-error-icon`} />,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-03-09 18:52:31 +08:00
|
|
|
const stepsProps = {
|
2020-06-22 14:21:40 +08:00
|
|
|
icons,
|
|
|
|
iconPrefix,
|
|
|
|
prefixCls,
|
|
|
|
progressDot,
|
|
|
|
...props,
|
2020-09-07 17:18:50 +08:00
|
|
|
canClick: !!(this.onChange || this['onUpdate:current']),
|
|
|
|
onChange: this.handleChange,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2020-06-22 16:26:10 +08:00
|
|
|
return <VcSteps {...stepsProps}>{getSlot(this)}</VcSteps>;
|
2018-03-09 18:52:31 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-03-19 10:16:27 +08:00
|
|
|
|
2018-09-19 13:21:57 +08:00
|
|
|
/* istanbul ignore next */
|
2020-06-22 14:21:40 +08:00
|
|
|
Steps.install = function(app) {
|
|
|
|
app.component(Steps.name, Steps);
|
|
|
|
app.component(Steps.Step.name, Steps.Step);
|
2020-10-13 19:14:56 +08:00
|
|
|
return app;
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-09-19 13:21:57 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
export default Steps;
|