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

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

Loading…
Cancel
Save