yuang-framework-ui-pc
Version:
yuang-framework-ui-pc Library
125 lines (124 loc) • 3.95 kB
JavaScript
import { defineComponent, ref, shallowRef, computed, watch, onMounted, nextTick, resolveComponent, createBlock, openBlock, Teleport, createElementVNode, normalizeClass, createElementBlock, createCommentVNode, normalizeStyle, renderSlot, createVNode, withCtx } from "vue";
import ReceiverView from "../ele-config-provider/components/receiver-view";
import { usePrinter, getPrintContainer, mergeOptions } from "./util";
import { printerEmits, printerProps } from "./props";
const _sfc_main = defineComponent({
name: "ElePrinter",
components: { ReceiverView },
props: printerProps,
emits: printerEmits,
setup(props, { emit }) {
const doPrint = usePrinter(() => {
visible.value = false;
updateModelValue(false);
handleDone();
});
const container = shallowRef(getPrintContainer());
const visible = ref(false);
const isStatic = computed(() => props.static);
const print = (options) => {
if (visible.value) {
return;
}
visible.value = true;
nextTick(() => {
const option = {
title: props.title,
margin: props.margin,
direction: props.direction,
orientation: props.orientation,
options: mergeOptions(props.options, options)
};
doPrint(option, props.target);
});
};
const handleDone = () => {
emit("done");
};
const updateModelValue = (value) => {
emit("update:modelValue", value);
};
watch(
() => props.modelValue,
(modelValue) => {
if (modelValue) {
print();
}
}
);
onMounted(() => {
if (props.modelValue) {
print();
}
});
return { container, visible, isStatic, print };
}
});
const _export_sfc = (sfc, props) => {
const target = sfc.__vccOpts || sfc;
for (const [key, val] of props) {
target[key] = val;
}
return target;
};
const _hoisted_1 = { key: 0 };
const _hoisted_2 = { key: 1 };
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const _component_ReceiverView = resolveComponent("ReceiverView");
return openBlock(), createBlock(Teleport, {
to: _ctx.container,
disabled: _ctx.isStatic && !_ctx.visible
}, [
createElementVNode("table", {
class: normalizeClass([
"ele-printer",
{ "is-open": _ctx.visible },
{ "is-static": _ctx.isStatic }
])
}, [
_ctx.$slots.header ? (openBlock(), createElementBlock("thead", _hoisted_1, [
createElementVNode("tr", null, [
createElementVNode("td", null, [
createElementVNode("div", {
class: "ele-printer-header",
style: normalizeStyle(_ctx.headerStyle)
}, [
renderSlot(_ctx.$slots, "header")
], 4)
])
])
])) : createCommentVNode("", true),
createElementVNode("tbody", null, [
createElementVNode("tr", null, [
createElementVNode("td", null, [
createVNode(_component_ReceiverView, {
class: "ele-printer-body",
style: normalizeStyle(_ctx.bodyStyle)
}, {
default: withCtx(() => [
renderSlot(_ctx.$slots, "default")
]),
_: 3
}, 8, ["style"])
])
])
]),
_ctx.$slots.footer ? (openBlock(), createElementBlock("tfoot", _hoisted_2, [
createElementVNode("tr", null, [
createElementVNode("td", null, [
createElementVNode("div", {
class: "ele-printer-footer",
style: normalizeStyle(_ctx.footerStyle)
}, [
renderSlot(_ctx.$slots, "footer")
], 4)
])
])
])) : createCommentVNode("", true)
], 2)
], 8, ["to", "disabled"]);
}
const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export {
index as default
};