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