|
|
|
@ -1,32 +1,32 @@
|
|
|
|
|
<template>
|
|
|
|
|
|
|
|
|
|
<el-dialog v-model="props.isView" title="预览" :close-on-press-escape="false" :show-close="false">
|
|
|
|
|
<el-dialog v-model="isView" title="预览" :close-on-press-escape="false" :show-close="false">
|
|
|
|
|
<div id="printInfo" ref="printRef">
|
|
|
|
|
<div class="content" v-for=" i in pageDatas"
|
|
|
|
|
<div class="content" v-for=" pageData in pageDatas"
|
|
|
|
|
:style="{width: cmToPx(pageWidth)+'px',height: cmToPx(pageHeight)+'px',marginBottom:'4px'}">
|
|
|
|
|
<div v-for="i in nodes" class="node" :style="{left:i.position?.x+'px',top: i.position?.y+'px'}">
|
|
|
|
|
<template v-if="i.type === 'text'">
|
|
|
|
|
<TextNode v-bind="i" :isView="true" :isPrint="isPrint" :pageData="i"
|
|
|
|
|
<TextNode v-bind="i" :isView="true" :isPrint="isPrint" :pageData="pageData"
|
|
|
|
|
:pageSize="{width: cmToPx(pageWidth) ,height: cmToPx(pageHeight) }"></TextNode>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-if="i.type === 'image'">
|
|
|
|
|
<ImageNode v-bind="i" :isView="true" :isPrint="isPrint" :pageData="i"
|
|
|
|
|
<ImageNode v-bind="i" :isView="true" :isPrint="isPrint" :pageData="pageData"
|
|
|
|
|
:pageSize="{width: cmToPx(pageWidth) ,height: cmToPx(pageHeight) }"></ImageNode>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-if="i.type === 'barCode'">
|
|
|
|
|
<BarCodeNode v-bind="i" :isView="true" :isPrint="isPrint" :pageData="i"
|
|
|
|
|
<BarCodeNode v-bind="i" :isView="true" :isPrint="isPrint" :pageData="pageData"
|
|
|
|
|
:pageSize="{width: cmToPx(pageWidth) ,height: cmToPx(pageHeight) }"></BarCodeNode>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-if="i.type === 'QRCode'">
|
|
|
|
|
<QRCodeNode v-bind="i" :isView="true" :isPrint="isPrint" :pageData="i"
|
|
|
|
|
<QRCodeNode v-bind="i" :isView="true" :isPrint="isPrint" :pageData="pageData"
|
|
|
|
|
:pageSize="{width: cmToPx(pageWidth) ,height: cmToPx(pageHeight) }"></QRCodeNode>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-if="i.type === 'dateTime'">
|
|
|
|
|
<TimeNode v-bind="i" :isView="true" :isPrint="isPrint" :pageData="i"
|
|
|
|
|
<TimeNode v-bind="i" :isView="true" :isPrint="isPrint" :pageData="pageData"
|
|
|
|
|
:pageSize="{width: cmToPx(pageWidth) ,height: cmToPx(pageHeight) }"></TimeNode>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-if="i.type === 'select'">
|
|
|
|
|
<SelectNode :isView="true" :isPrint="isPrint" :pageData="i"
|
|
|
|
|
<SelectNode :isView="true" :isPrint="isPrint" :pageData="pageData"
|
|
|
|
|
:pageSize="{width: cmToPx(pageWidth) ,height: cmToPx(pageHeight) }"
|
|
|
|
|
v-bind="i"></SelectNode>
|
|
|
|
|
</template>
|
|
|
|
@ -38,7 +38,7 @@
|
|
|
|
|
<span class="dialog-footer">
|
|
|
|
|
<el-button type="primary" @click="printFun">打印</el-button>
|
|
|
|
|
<!-- <el-button type="primary" v-print="printInfoObj">打印</el-button>-->
|
|
|
|
|
<el-button @click="closeDialog ">关闭</el-button>
|
|
|
|
|
<el-button @click="closePrint">关闭</el-button>
|
|
|
|
|
</span>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dialog>
|
|
|
|
@ -56,25 +56,17 @@ import TimeNode from './nodes/timeNode.vue';
|
|
|
|
|
import SelectNode from './nodes/selectNode.vue';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
isView: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
required: false
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
const emit = defineEmits(['update:isView']);
|
|
|
|
|
|
|
|
|
|
const isView = ref(false);
|
|
|
|
|
|
|
|
|
|
const isPrint = ref(false);
|
|
|
|
|
const printRef = ref();
|
|
|
|
|
const pageWidth = ref(21);
|
|
|
|
|
const pageHeight = ref(29.7);
|
|
|
|
|
const pageDatas = ref([{}, {}, {}, {}, {}, {}]);
|
|
|
|
|
const pageDatas = ref([{}]);
|
|
|
|
|
const { cmToPx } = options;
|
|
|
|
|
const nodes = ref([]);
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
nodes.value = JSON.parse(localStorage.getItem('printNodes') || '[]');
|
|
|
|
|
console.log(nodes.value);
|
|
|
|
|
nodes.value = JSON.parse(localStorage.getItem('printNodes') || '[]');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const printInfoObj = {
|
|
|
|
@ -119,9 +111,29 @@ const printFun = () => {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
const closeDialog = () => {
|
|
|
|
|
emit('update:isView', false);
|
|
|
|
|
const closePrint = () => {
|
|
|
|
|
isView.value = false;
|
|
|
|
|
};
|
|
|
|
|
const openPrint = (pages, templateId) => {
|
|
|
|
|
isView.value = false;
|
|
|
|
|
nextTick(() => {
|
|
|
|
|
nodes.value = JSON.parse(localStorage.getItem('printNodes') || '[]');
|
|
|
|
|
isView.value = true;
|
|
|
|
|
let pageData = [];
|
|
|
|
|
if (Array.isArray(pages)) {
|
|
|
|
|
pageData = pages;
|
|
|
|
|
}
|
|
|
|
|
if (typeof pages !== 'object' || pages === null) {
|
|
|
|
|
pageData = [pages];
|
|
|
|
|
}
|
|
|
|
|
console.log(pageData);
|
|
|
|
|
pageDatas.value = pageData || [];
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
defineExpose({
|
|
|
|
|
openPrint
|
|
|
|
|
// closePrint
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
<style scoped>
|
|
|
|
|
.content {
|
|
|
|
|