song-ui-u
Version:
vue3 + js的PC前端组件库
127 lines (109 loc) • 4.06 kB
JavaScript
import { useNamespace } from '../../../hook/use-namespace/index.mjs';
import { computed, ref, watch, openBlock, createElementBlock, normalizeClass, createCommentVNode, createElementVNode, normalizeStyle, renderSlot, toDisplayString } from 'vue';
import { useStyle } from '../../../hook/use-style/index.mjs';
import '../../../hook/use-zindex/index.mjs';
import _export_sfc from '../../../_virtual/_plugin-vue_export-helper.mjs';
const _sfc_main = /*#__PURE__*/Object.assign({
name: "x-progress",
}, {
__name: 'index',
props: {
// 当前进度 (0 - 100)
value: {
type: [Number, String],
default: 0,
},
// 状态
status: {
type: String,
default: "",
},
// 自定义文本
format: {
type: Boolean,
default: false,
},
color: {
type: String,
default: "",
},
type: {
type: String,
default: "",
},
// 进度条高度
height: {
type: [Number, String],
default: 20,
},
},
setup(__props, { expose: __expose }) {
__expose();
// 定义 props
const props = __props;
const { bgColor, color, borderColor, height } = useStyle();
const styleBgColor = computed(() => bgColor(props.color));
const styleTextColor = computed(() => color(props.color));
const styleBorderColor = computed(() => borderColor(props.color));
const styleHeight = computed(() => height(props.height));
// 定义内部状态
const progress = ref(0);
// 监听传入的 value 值变化
watch(
() => props.value,
(newValue) => {
if (newValue >= 0 && newValue <= 100) {
progress.value = newValue;
} else {
console.warn("进度值应在 0 到 100 之间");
}
},
{ immediate: true } // 立即执行一次
);
const ns = useNamespace("progress");
const __returned__ = { props, bgColor, color, borderColor, height, styleBgColor, styleTextColor, styleBorderColor, styleHeight, progress, ns, get useNamespace() { return useNamespace }, get useStyle() { return useStyle }, ref, watch, computed };
Object.defineProperty(__returned__, '__isScriptSetup', { enumerable: false, value: true });
return __returned__
}
});
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return (openBlock(), createElementBlock("div", {
class: normalizeClass([$setup.ns.b(), $setup.ns.m($props.status)])
}, [
createCommentVNode(" 外层容器 "),
createElementVNode("div", {
class: normalizeClass($setup.ns.e('bar')),
style: normalizeStyle({ ...$setup.styleBorderColor, ...$setup.styleHeight })
}, [
createCommentVNode(" 内部填充部分,表示进度 "),
createElementVNode("div", {
class: normalizeClass([$setup.ns.e('inner')]),
style: normalizeStyle({ width: $setup.progress + '%', ...$setup.styleBgColor })
}, [
(_ctx.$slots.default)
? (openBlock(), createElementBlock("div", {
key: 0,
class: normalizeClass($setup.ns.e('inner-content'))
}, [
renderSlot(_ctx.$slots, "default")
], 2 /* CLASS */))
: createCommentVNode("v-if", true)
], 6 /* CLASS, STYLE */)
], 6 /* CLASS, STYLE */),
createCommentVNode(" 显示进度百分比 "),
(!$props.format)
? (openBlock(), createElementBlock("span", {
key: 0,
class: normalizeClass([$setup.ns.e('text')]),
style: normalizeStyle($setup.styleTextColor)
}, toDisplayString($setup.progress) + "%", 7 /* TEXT, CLASS, STYLE */))
: (openBlock(), createElementBlock("span", {
key: 1,
class: normalizeClass([$setup.ns.e('text')]),
style: normalizeStyle($setup.styleTextColor)
}, toDisplayString($props.format), 7 /* TEXT, CLASS, STYLE */))
], 2 /* CLASS */))
}
var progress = /*#__PURE__*/_export_sfc(_sfc_main, [['render',_sfc_render],['__file',"E:\\code\\my-code\\song-ui-ultra\\packages\\components\\progress\\src\\index.vue"]]);
export { progress as default };
//# sourceMappingURL=index.vue.mjs.map