main
liutao 1 month ago
parent 025b619a35
commit 93c272565b

@ -3332,7 +3332,7 @@ export default {
hostName: 'Host Name', hostName: 'Host Name',
systemPrinterName: 'Printer Name', systemPrinterName: 'Printer Name',
defaultStatus: 'Is Default', defaultStatus: 'Is Default',
isEnable: 'Is Enabled', isEnabled: 'Is Enabled',
remark: 'remark', remark: 'remark',
createTime: 'Create Time', createTime: 'Create Time',
updateTime: 'Update Time', updateTime: 'Update Time',

@ -2818,7 +2818,7 @@ export default {
hostName: '主机名', hostName: '主机名',
systemPrinterName: '打印机名称', systemPrinterName: '打印机名称',
defaultStatus: '是否默认', defaultStatus: '是否默认',
isEnable: '是否启用', isEnabled: '是否启用',
remark: '备注', remark: '备注',
createTime: '创建时间', createTime: '创建时间',
updateTime: '更新时间', updateTime: '更新时间',

@ -297,5 +297,9 @@ export enum DICT_TYPE {
IOT_DEVICE_ATTRIBUTE_UNIT = "iot_device_attribute_unit", IOT_DEVICE_ATTRIBUTE_UNIT = "iot_device_attribute_unit",
IOT_ALARM_REGISTRATION = "alarm_registration", IOT_ALARM_REGISTRATION = "alarm_registration",
PRIMARY_FLAG = "primary_flag" PRIMARY_FLAG = "primary_flag",
IS_DEFAULT = 'is_default', // 是否默认
IS_ENABLED = 'is_enabled', // 是否启用
} }

@ -30,8 +30,8 @@
<el-form-item :label="t('TemplateManagement.PrintConfig.defaultStatus')" prop="isDefault"> <el-form-item :label="t('TemplateManagement.PrintConfig.defaultStatus')" prop="isDefault">
<el-switch v-model="formData.isDefault" /> <el-switch v-model="formData.isDefault" />
</el-form-item> </el-form-item>
<el-form-item :label="t('TemplateManagement.PrintConfig.isEnable')" prop="isEnabled"> <el-form-item :label="t('TemplateManagement.PrintConfig.isEnabled')" prop="isEnabled">
<el-switch v-model="formData.isEnable" /> <el-switch v-model="formData.isEnabled" />
</el-form-item> </el-form-item>
<el-form-item :label="t('TemplateManagement.PrintConfig.remark')" prop="remark"> <el-form-item :label="t('TemplateManagement.PrintConfig.remark')" prop="remark">
<el-input v-model="formData.remark" :placeholder="t('TemplateManagement.PrintConfig.placeholderRemark')" /> <el-input v-model="formData.remark" :placeholder="t('TemplateManagement.PrintConfig.placeholderRemark')" />
@ -66,8 +66,8 @@ const formData = ref({
id: undefined, id: undefined,
hostName: undefined, hostName: undefined,
systemPrinterName: undefined, systemPrinterName: undefined,
isDefault: undefined, isDefault: false,
isEnabled: undefined, isEnabled: true,
remark: undefined, remark: undefined,
createdAt: undefined, createdAt: undefined,
updatedAt: undefined, updatedAt: undefined,
@ -156,9 +156,11 @@ const printData = ref({
address: '北京市朝阳区测试街道123号' address: '北京市朝阳区测试街道123号'
}); });
const handleClientPrint = () => { const handleClientPrint = async () => {
//
await formRef.value.validate()
if (!hiprintTemplate) { if (!hiprintTemplate) {
return buildTestPrintTemplate()
} }
syncClientState() syncClientState()
if (!clientConnected.value) { if (!clientConnected.value) {
@ -169,7 +171,7 @@ const handleClientPrint = () => {
clientPrinting.value = true clientPrinting.value = true
try { try {
hiprintTemplate.print2(printData.value, { hiprintTemplate.print2(printData.value, {
printer: selectedPrinter.value, printer: formData.value.systemPrinterName,
title: dialogTitle.value title: dialogTitle.value
}) })
} catch (error: any) { } catch (error: any) {
@ -177,6 +179,49 @@ const handleClientPrint = () => {
message.error(error?.message || '本地客户端打印失败') message.error(error?.message || '本地客户端打印失败')
} }
} }
const buildTestPrintTemplate = () => {
if (hiprintTemplate) {
return
}
const printElements = [
{
options: { left: 60, top: 10, height: 10, width: 200, title: '订单号', field: 'orderNo', testData: 'TEST-20231125-001', fontSize: 22, textAlign: 'center' },
printElementType: { title: '文本', type: 'text' }
},
{
options: { left: 60, top: 68, height: 10, width: 200, title: '客户名', field: 'customerName', testData: '测试客户', fontSize: 22, textAlign: 'center' },
printElementType: { title: '文本', type: 'text' }
}
]
const templateJson = {
panels: [{
index: 0,
height: 100,
width: 220,
paperHeader: 5,
paperFooter: 5,
printElements
}]
}
hiprintTemplate = new hiprint.PrintTemplate({ template: templateJson })
printEventBound = false
bindPrintEvents()
}
const bindPrintEvents = () => {
if (!hiprintTemplate || printEventBound) {
return
}
hiprintTemplate.on('printSuccess', () => {
clientPrinting.value = false
message.success('本地客户端打印已发送')
})
hiprintTemplate.on('printError', (data: any) => {
clientPrinting.value = false
message.error(data?.msg || data?.message || '本地客户端打印失败')
})
printEventBound = true
}
const applyClientHost = () => { const applyClientHost = () => {
const socket = getHiwebSocket() const socket = getHiwebSocket()
let host = normalizeClientHost() let host = normalizeClientHost()
@ -254,8 +299,8 @@ const resetForm = () => {
id: undefined, id: undefined,
hostName: undefined, hostName: undefined,
systemPrinterName: undefined, systemPrinterName: undefined,
isDefault: undefined, isDefault: false,
isEnabled: undefined, isEnabled: true,
remark: undefined, remark: undefined,
createdAt: undefined, createdAt: undefined,
updatedAt: undefined, updatedAt: undefined,

@ -75,20 +75,28 @@
<!-- <el-table-column type="selection" width="55" fixed="left" reserve-selection />--> <!-- <el-table-column type="selection" width="55" fixed="left" reserve-selection />-->
<el-table-column :label="t('TemplateManagement.PrintConfig.hostName')" align="center" prop="hostName" /> <el-table-column :label="t('TemplateManagement.PrintConfig.hostName')" align="center" prop="hostName" />
<el-table-column :label="t('TemplateManagement.PrintConfig.systemPrinterName')" align="center" prop="systemPrinterName" /> <el-table-column :label="t('TemplateManagement.PrintConfig.systemPrinterName')" align="center" prop="systemPrinterName" />
<el-table-column :label="t('TemplateManagement.PrintConfig.defaultStatus')" align="center" prop="isDefault" /> <el-table-column :label="t('TemplateManagement.PrintConfig.defaultStatus')" align="center" prop="isDefault" >
<el-table-column :label="t('TemplateManagement.PrintConfig.isEnable')" align="center" prop="isEnabled" /> <template #default="scope">
<dict-tag :type="DICT_TYPE.IS_DEFAULT" :value="scope.row.isDefault" />
</template>
</el-table-column>
<el-table-column :label="t('TemplateManagement.PrintConfig.isEnabled')" align="center" prop="isEnabled" >
<template #default="scope">
<dict-tag :type="DICT_TYPE.IS_ENABLED" :value="scope.row.isEnabled" />
</template>
</el-table-column>
<el-table-column :label="t('TemplateManagement.PrintConfig.remark')" align="center" prop="remark" /> <el-table-column :label="t('TemplateManagement.PrintConfig.remark')" align="center" prop="remark" />
<el-table-column <el-table-column
:label="t('TemplateManagement.PrintConfig.createTime')" :label="t('TemplateManagement.PrintConfig.createTime')"
align="center" align="center"
prop="createdAt" prop="createTime"
:formatter="dateFormatter" :formatter="dateFormatter"
width="180px" width="180px"
/> />
<el-table-column <el-table-column
:label="t('TemplateManagement.PrintConfig.updateTime')" :label="t('TemplateManagement.PrintConfig.updateTime')"
align="center" align="center"
prop="updatedAt" prop="updateTime"
:formatter="dateFormatter" :formatter="dateFormatter"
width="180px" width="180px"
/> />
@ -110,6 +118,15 @@
> >
{{ t('action.del') }} {{ t('action.del') }}
</el-button> </el-button>
<el-button
link
type="success"
@click="handleTestPrint(scope.row)"
v-hasPermi="['printer:config:update']"
>
<Icon icon="ep:printer" class="mr-2px" />
{{ t('TemplateManagement.PrintConfig.testPrint') }}
</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -132,7 +149,7 @@ import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download' import download from '@/utils/download'
import { ConfigApi, ConfigVO } from '@/api/mes/printconfig' import { ConfigApi, ConfigVO } from '@/api/mes/printconfig'
import ConfigForm from './ConfigForm.vue' import ConfigForm from './ConfigForm.vue'
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
/** 打印机配置 列表 */ /** 打印机配置 列表 */
defineOptions({ name: 'PrinterConfig' }) defineOptions({ name: 'PrinterConfig' })
@ -166,6 +183,7 @@ const queryParams = reactive<QueryParams>({
const queryFormRef = ref() // const queryFormRef = ref() //
const exportLoading = ref(false) // const exportLoading = ref(false) //
const clientHostStorageKey = 'hiprint-client-host' const clientHostStorageKey = 'hiprint-client-host'
const hostNameStorageKey = 'hiprint-connected-hostname'
const defaultClientHost = 'http://127.0.0.1:17521' const defaultClientHost = 'http://127.0.0.1:17521'
let hiprintInited = false let hiprintInited = false
@ -334,7 +352,12 @@ const resolveCurrentHostName = async () => {
} }
settled = true settled = true
window.clearTimeout(timer) window.clearTimeout(timer)
resolve(hostName || getSocketHostName()) // localStorage
const result = hostName || getSocketHostName()
if (result) {
localStorage.setItem(hostNameStorageKey, result)
}
resolve(result)
} }
const timer = window.setTimeout(() => finish(), 3000) const timer = window.setTimeout(() => finish(), 3000)
@ -383,15 +406,20 @@ const resolveCurrentHostName = async () => {
} }
const initCurrentHostName = async () => { const initCurrentHostName = async () => {
//
const cachedHostName = localStorage.getItem(hostNameStorageKey)
if (cachedHostName) {
currentHostName.value = cachedHostName
queryParams.hostName = cachedHostName
}
// WebSocket
const hostName = await resolveCurrentHostName() const hostName = await resolveCurrentHostName()
if (hostName) { if (hostName && hostName !== cachedHostName) {
currentHostName.value = hostName currentHostName.value = hostName
queryParams.hostName = hostName queryParams.hostName = hostName
} }
} }
/** 查询列表 */
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
try { try {
@ -422,11 +450,67 @@ const resetQuery = () => {
/** 添加/修改操作 */ /** 添加/修改操作 */
const formRef = ref() const formRef = ref()
const openForm = (type: string, id?: number) => { const openForm = (type: string, id?: number) => {
let host = normalizeClientHost(); let host = currentHostName.value;
formRef.value.open(type,host, id) formRef.value.open(type,host, id)
} }
/** 测试打印按钮操作 */
const handleTestPrint = async (row: any) => {
const printerName = row.systemPrinterName
if (!printerName) {
message.warning('该配置未选择打印机,无法测试打印')
return
}
ensureHiprintInit()
const testData = {
orderNo: 'TEST-' + Date.now(),
customerName: '测试客户',
amount: 199.99,
address: '北京市朝阳区测试街道123号'
}
const printElements = [
{ options: { left: 10, top: 10, height: 10, width: 200, title: '订单号', field: 'orderNo', testData: testData.orderNo, fontSize: 14, textAlign: 'center' }, printElementType: { title: '文本', type: 'text' } },
{ options: { left: 10, top: 28, height: 10, width: 200, title: '客户名', field: 'customerName', testData: testData.customerName, fontSize: 14, textAlign: 'center' }, printElementType: { title: '文本', type: 'text' } },
{ options: { left: 10, top: 46, height: 14, width: 200, title: '金额', field: 'amount', testData: '199.99', fontSize: 18, textAlign: 'center', fontWeight: 'bold' }, printElementType: { title: '文本', type: 'text' } },
{ options: { left: 10, top: 68, height: 10, width: 200, title: '地址', field: 'address', testData: testData.address, fontSize: 12, textAlign: 'center' }, printElementType: { title: '文本', type: 'text' } }
]
const templateJson = { panels: [{ index: 0, height: 100, width: 220, paperHeader: 5, paperFooter: 5, printElements }] }
applyClientHost()
const socket = getHiwebSocket()
if (!socket) {
message.warning('打印客户端未初始化')
return
}
if (socket.opened) {
doTestPrint(socket, printerName, testData, templateJson)
return
}
socket.stop()
socket.start((status: boolean) => {
if (!status) {
message.warning('未连接到本地打印客户端,请先确认 electron-hiprint 已启动')
return
}
doTestPrint(socket, printerName, testData, templateJson)
})
}
/** 删除按钮操作 */ /** 删除按钮操作 */
const doTestPrint = (socket: any, printerName: string, testData: any, templateJson: any) => {
const printTemplate = new hiprint.PrintTemplate({ template: templateJson })
printTemplate.on('printSuccess', () => {
message.success('测试打印已发送到: ' + printerName)
})
printTemplate.on('printError', (data: any) => {
message.error(data?.msg || data?.message || '测试打印失败')
})
try {
printTemplate.print2(testData, { printer: printerName, title: '测试打印' })
} catch (error: any) {
message.error(error?.message || '测试打印失败')
}
}
const handleDelete = async (id: number) => { const handleDelete = async (id: number) => {
try { try {
// //

Loading…
Cancel
Save