tdesign-vue
Version:
169 lines (165 loc) • 6.62 kB
JavaScript
/**
* tdesign v1.12.1
* (c) 2025 tdesign
* @license MIT
*/
import { h as helper } from '../_chunks/dep-323b993c.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import props from './props.js';
import _StepItem from './step-item.js';
import mixins from '../utils/mixins.js';
import getConfigReceiverMixins from '../config-provider/config-receiver.js';
import { emitEvent } from '../utils/event.js';
import 'lodash-es';
import 'tdesign-icons-vue';
import './step-item-props.js';
import '../utils/render-tnode.js';
import '@babel/runtime/helpers/readOnlyError';
import '@babel/runtime/helpers/typeof';
import 'vue';
import '@vue/composition-api';
import '../config-provider/context.js';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../_chunks/dep-c44a474d.js';
import '../_chunks/dep-d639fbd7.js';
import 'dayjs';
import '../_chunks/dep-3c66615e.js';
import '../config-provider/type.js';
import '../_common/js/global-config/t.js';
import '@babel/runtime/helpers/slicedToArray';
import '../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var _Steps = mixins(getConfigReceiverMixins("steps")).extend({
name: "TSteps",
components: {
TStepItem: _StepItem
},
props: _objectSpread({}, props),
data: function data() {
return {
indexMap: {}
};
},
provide: function provide() {
return {
steps: this
};
},
watch: {
options: {
immediate: true,
handler: function handler() {
var _this = this;
if (!this.options) return;
this.options.forEach(function (item, index) {
if (item.value !== void 0) {
_this.indexMap[item.value] = index;
}
});
}
}
},
computed: {
baseClass: function baseClass() {
return [this.componentName, "".concat(this.componentName, "--").concat(this.layout), "".concat(this.componentName, "--").concat(this.sequence), "".concat(this.componentName, "--").concat(this.handleTheme(), "-anchor"), "".concat(this.componentName, "--").concat(this.separator, "-separator")];
}
},
render: function render() {
var _this$$scopedSlots,
_this2 = this;
var h = arguments[0];
var nodes = ((_this$$scopedSlots = this.$scopedSlots) === null || _this$$scopedSlots === void 0 ? void 0 : _this$$scopedSlots["default"]) && this.$scopedSlots["default"](null);
var options = this.getOptions();
var content = options.map(function (item, index) {
var stepIndex = _this2.sequence === "reverse" ? options.length - index - 1 : index;
var propsData = _objectSpread(_objectSpread({}, item), {}, {
index: stepIndex,
status: _this2.handleStatus(item, index)
});
var stepItem = h("t-step-item", helper([{}, {
"props": _objectSpread(_objectSpread({}, item), {}, {
index: stepIndex,
status: _this2.handleStatus(item, index)
})
}, {
"key": item.value || index
}]));
if (nodes && nodes[index]) {
var vnode = nodes[index];
if (vnode.componentOptions) {
vnode.componentOptions.propsData = propsData;
return vnode;
}
return stepItem;
}
return stepItem;
});
return h("div", {
"class": this.baseClass
}, [content]);
},
methods: {
getOptions: function getOptions() {
var _this$$scopedSlots2;
var nodes = ((_this$$scopedSlots2 = this.$scopedSlots) === null || _this$$scopedSlots2 === void 0 ? void 0 : _this$$scopedSlots2["default"]) && this.$scopedSlots["default"](null);
var options;
if (this.options && this.options.length) {
options = this.sequence === "reverse" ? this.options.reverse() : this.options;
} else {
options = this.getOptionListBySlots(nodes);
}
return options;
},
getOptionListBySlots: function getOptionListBySlots(nodes) {
var _this3 = this;
var arr = [];
nodes === null || nodes === void 0 || nodes.forEach(function (node) {
var _node$componentOption;
var option = node === null || node === void 0 || (_node$componentOption = node.componentOptions) === null || _node$componentOption === void 0 ? void 0 : _node$componentOption.propsData;
if (!option) return;
_this3.sequence === "reverse" ? arr.unshift(option) : arr.push(option);
});
return arr;
},
handleTheme: function handleTheme() {
var theme = this.theme;
var options = this.getOptions();
options.forEach(function (item) {
if ((item === null || item === void 0 ? void 0 : item.icon) !== void 0) {
theme = "default";
}
});
return theme;
},
handleStatus: function handleStatus(item, index) {
if (item.status && item.status !== "default") return item.status;
if (this.current === "FINISH") return "finish";
if (item.value === void 0) {
if (this.sequence === "positive" && index < this.current) return "finish";
if (this.sequence === "reverse" && index > this.current) return "finish";
}
if (item.value !== void 0) {
var matchIndex = this.indexMap[this.current];
if (matchIndex === void 0) {
console.warn("TDesign Steps Warn: The current `value` is not exist.");
return "default";
}
if (this.sequence === "positive" && index < matchIndex) return "finish";
if (this.sequence === "reverse" && index > matchIndex) return "finish";
}
var key = item.value === void 0 ? index : item.value;
if (key === this.current) return "process";
return "default";
},
handleChange: function handleChange(cur, prev, e) {
emitEvent(this, "change", cur, prev, {
e: e
});
}
}
});
export { _Steps as default };
//# sourceMappingURL=steps.js.map