master
吴普建 11 months ago
parent 622f68e4da
commit b7a243e1df

@ -1,16 +1,16 @@
<template> <template>
<n-config-provider <n-config-provider
:theme="theme.naiveTheme" :theme="theme.naiveTheme"
:theme-overrides="theme.naiveThemeOverrides" :theme-overrides="theme.naiveThemeOverrides"
:locale="zhCN" :locale="zhCN"
:date-locale="dateZhCN" :date-locale="dateZhCN"
class="h-full" class="h-full"
> >
<naive-provider> <naive-provider>
<router-view /> <router-view />
</naive-provider> </naive-provider>
</n-config-provider> </n-config-provider>
<loadingAwait v-show="app.isLoading" /> <loadingAwait v-show="app.isLoading" />
</template> </template>
<script setup> <script setup>
@ -35,86 +35,109 @@ const hiprintTemplate = ref(null);
const livePrint = ref(null); const livePrint = ref(null);
function print(printData, title) { function print(printData, title) {
if (window.hiwebSocket.opened && window.hiwebSocket.printerList.length) { if (window.hiwebSocket.opened && window.hiwebSocket.printerList.length) {
hiprintTemplate.value.print2(printData, { printer: livePrint.value, title }); let mylivePrint = null;
// hiprintTemplate.value.on('printSuccess', function (e) { let printerList = window.hiwebSocket.printerList.map(item => {
// console.log('printSuccess'); return {
label: item.name,
// }) value: item.name
// // };
// hiprintTemplate.value.on('printError', function (e) { });
// console.log('printError'); console.log("printerList", printerList)
// }) if (printerList && printerList.length) {
} mylivePrint = printerList.find(item => item.label.indexOf("ZDesigner ZD888-203dpi ZPL") > -1).value;
console.log("livePrint2==>",mylivePrint);
}
if(!livePrint){
mylivePrint = "ZDesigner ZD888-203dpi ZPL (副本 2)";
}
if(mylivePrint){
hiprintTemplate.value.print2(printData, { printer: mylivePrint, title });
}else{
hiprintTemplate.value.print2(printData, { printer: livePrint.value, title });
}
// hiprintTemplate.value.print2(printData, { printer: livePrint.value, title });
hiprintTemplate.value.on('printSuccess', function (e) {
console.log('printSuccess');
})
// //
hiprintTemplate.value.on('printError', function (e) {
console.log('printError');
})
}
} }
function isValidJSON(data) { function isValidJSON(data) {
try { try {
JSON.parse(data); JSON.parse(data);
return true; return true;
} catch (e) { } catch (e) {
return false; return false;
} }
} }
watch( watch(
() => socketStore.msg, () => socketStore.msg,
async newValue => { async newValue => {
// console.log('newValue ==> ', newValue); // console.log('newValue ==> ', newValue);
// console.log('JSON.parse(newValue) ==> ', JSON.parse(newValue)); // console.log('JSON.parse(newValue) ==> ', JSON.parse(newValue));
if (!window.hiwebSocket.opened && !window.hiwebSocket.printerList?.length) { if (!window.hiwebSocket.opened && !window.hiwebSocket.printerList?.length) {
window.$message?.error('打印失败,请连接打印机'); window.$message?.error('打印失败,请连接打印机');
return; return;
} }
if (!newValue) return; if (!newValue) return;
if (isValidJSON(newValue)) { if (isValidJSON(newValue)) {
// const msgData = JSON.parse(JSON.parse(newValue)); // const msgData = JSON.parse(JSON.parse(newValue));
const msgData = JSON.parse(newValue); const msgData = JSON.parse(newValue);
const data = JSON.parse(JSON.stringify(msgData)); const data = JSON.parse(JSON.stringify(msgData));
console.log('data ==>', data); console.log('data ==>', data);
socketStore.setMsg(null); socketStore.setMsg(null);
getPrintTemplateList({ templateCode: data.templateType }).then(async res => { getPrintTemplateList({ templateCode: data.templateType }).then(async res => {
if (res.code === 200) { if (res.code === 200) {
if (!res.rows[0].content) return; if (!res.rows[0].content) return;
temp.value = JSON.parse(res.rows[0].content); temp.value = JSON.parse(res.rows[0].content);
// hiprint.PrintElementTypeManager.buildByHtml($('.ep-draggable-item')); // hiprint.PrintElementTypeManager.buildByHtml($('.ep-draggable-item'));
// $('#hiprint-printTemplate').empty(); // $('#hiprint-printTemplate').empty();
hiprintTemplate.value = await new hiprint.PrintTemplate({ hiprintTemplate.value = await new hiprint.PrintTemplate({
template: temp.value template: temp.value
}); });
livePrint.value = temp.value.panels[0].livePrint; livePrint.value = temp.value.panels[0].livePrint;
data.printValue.forEach(item => { console.log("livePrint.value", livePrint.value)
//
if (data.templateType.includes('enamelCoverReport')) { data.printValue.forEach(item => {
item.machineBatchNumber = `${item.qbPrintValue}/${item.alexLot}`; //
if (item.createTime) { if (data.templateType.includes('enamelCoverReport')) {
item.createTime = formatDate(new Date(item.createTime), 'yyyy-MM-dd'); item.machineBatchNumber = `${item.qbPrintValue}/${item.alexLot}`;
} if (item.createTime) {
item.groupStartName = `${item.workgroupValue} ${item.standardName}`; item.createTime = formatDate(new Date(item.createTime), 'yyyy-MM-dd');
} }
// item.groupStartName = `${item.workgroupValue} ${item.standardName}`;
if (data.reprintData) { }
addReprintRecord(data.reprintData); //
} if (data.reprintData) {
addReprintRecord(data.reprintData);
print(item, '测试打印'); }
});
} print(item, '测试打印');
}); });
} }
} });
}
}
); );
onMounted(() => { onMounted(() => {
const socket = localStorage.getItem('socket'); const socket = localStorage.getItem('socket');
if (socket) { if (socket) {
socketStore.setOpenSocket(socket); socketStore.setOpenSocket(socket);
} }
}); });
</script> </script>
<style> <style>

Loading…
Cancel
Save