@seemusic/ui-components
Version:
A Vue 3 UI Library. Uses Composable.
117 lines (116 loc) • 3.15 kB
JavaScript
import { defineComponent, ref, computed, createVNode, mergeProps, isVNode, Fragment } from "vue";
import { ElDialog, ElButton } from "element-plus";
import { useLocale } from "../../composables/useLocale.mjs";
function _isSlot(s) {
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
}
const SopDialog = /* @__PURE__ */ defineComponent({
name: "SopDialog",
components: {
ElDialog,
ElButton
},
props: {
visible: {
type: Boolean,
required: true
},
width: {
type: String,
default: "45%"
},
isShowFooter: {
type: Boolean,
default: true
},
isShowDefaultFooter: {
type: Boolean,
default: false
},
isShowConfirmBtn: {
type: Boolean,
default: true
},
isShowCancelBtn: {
type: Boolean,
default: true
},
confirmBtnText: {
type: String
},
cancelBtnText: {
type: String
}
},
emits: ["update:visible", "on-ok", "on-close"],
setup(props, {
attrs,
emit,
slots
}) {
const {
t
} = useLocale();
const confirmBtnText = ref(props.confirmBtnText || t("sop.common.confirm"));
const cancelBtnText = ref(props.cancelBtnText || t("sop.common.cancel"));
const loading = ref(false);
const isShowDefaultFooter = computed(() => (props.isShowCancelBtn || props.isShowConfirmBtn) && props.isShowDefaultFooter);
function beforeClose() {
emit("on-close");
emit("update:visible", !props.visible);
}
function setLoading(status) {
loading.value = status;
}
const okEvents = {
close: beforeClose,
setLoading
};
function renderFooter(slots2) {
const slot = {
header: (val) => {
var _a;
return (_a = slots2.header) == null ? void 0 : _a.call(slots2, val);
},
default: () => {
var _a;
return (_a = slots2.default) == null ? void 0 : _a.call(slots2);
}
};
if (props.isShowFooter) {
slot["footer"] = () => {
var _a;
return isShowDefaultFooter.value ? createVNode(Fragment, null, [props.isShowCancelBtn && createVNode(ElButton, {
"onClick": beforeClose
}, {
default: () => [cancelBtnText.value]
}), props.isShowConfirmBtn && createVNode(ElButton, {
"loading": loading.value,
"type": "primary",
"onClick": () => {
emit("on-ok", okEvents);
}
}, {
default: () => [confirmBtnText.value]
})]) : (_a = slots2.footer) == null ? void 0 : _a.call(slots2);
};
}
return slot;
}
return () => {
let _slot;
return createVNode(ElDialog, mergeProps(attrs, {
"modelValue": props.visible,
"before-close": beforeClose,
"destroy-on-close": true,
"width": props.width
}), _isSlot(_slot = renderFooter(slots)) ? _slot : {
default: () => [_slot]
});
};
}
});
export {
SopDialog as default
};
//# sourceMappingURL=SopDialog.mjs.map