|
|
|
|
@ -75,20 +75,28 @@
|
|
|
|
|
<!-- <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.systemPrinterName')" align="center" prop="systemPrinterName" />
|
|
|
|
|
<el-table-column :label="t('TemplateManagement.PrintConfig.defaultStatus')" align="center" prop="isDefault" />
|
|
|
|
|
<el-table-column :label="t('TemplateManagement.PrintConfig.isEnable')" align="center" prop="isEnabled" />
|
|
|
|
|
<el-table-column :label="t('TemplateManagement.PrintConfig.defaultStatus')" align="center" prop="isDefault" >
|
|
|
|
|
<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.createTime')"
|
|
|
|
|
align="center"
|
|
|
|
|
prop="createdAt"
|
|
|
|
|
prop="createTime"
|
|
|
|
|
:formatter="dateFormatter"
|
|
|
|
|
width="180px"
|
|
|
|
|
/>
|
|
|
|
|
<el-table-column
|
|
|
|
|
:label="t('TemplateManagement.PrintConfig.updateTime')"
|
|
|
|
|
align="center"
|
|
|
|
|
prop="updatedAt"
|
|
|
|
|
prop="updateTime"
|
|
|
|
|
:formatter="dateFormatter"
|
|
|
|
|
width="180px"
|
|
|
|
|
/>
|
|
|
|
|
@ -110,6 +118,15 @@
|
|
|
|
|
>
|
|
|
|
|
{{ t('action.del') }}
|
|
|
|
|
</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>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
@ -132,7 +149,7 @@ import { dateFormatter } from '@/utils/formatTime'
|
|
|
|
|
import download from '@/utils/download'
|
|
|
|
|
import { ConfigApi, ConfigVO } from '@/api/mes/printconfig'
|
|
|
|
|
import ConfigForm from './ConfigForm.vue'
|
|
|
|
|
|
|
|
|
|
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
|
|
|
|
|
/** 打印机配置 列表 */
|
|
|
|
|
defineOptions({ name: 'PrinterConfig' })
|
|
|
|
|
|
|
|
|
|
@ -166,6 +183,7 @@ const queryParams = reactive<QueryParams>({
|
|
|
|
|
const queryFormRef = ref() // 搜索的表单
|
|
|
|
|
const exportLoading = ref(false) // 导出的加载中
|
|
|
|
|
const clientHostStorageKey = 'hiprint-client-host'
|
|
|
|
|
const hostNameStorageKey = 'hiprint-connected-hostname'
|
|
|
|
|
const defaultClientHost = 'http://127.0.0.1:17521'
|
|
|
|
|
let hiprintInited = false
|
|
|
|
|
|
|
|
|
|
@ -334,7 +352,12 @@ const resolveCurrentHostName = async () => {
|
|
|
|
|
}
|
|
|
|
|
settled = true
|
|
|
|
|
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)
|
|
|
|
|
@ -383,15 +406,20 @@ const resolveCurrentHostName = async () => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const initCurrentHostName = async () => {
|
|
|
|
|
// 先从缓存读取,立即显示
|
|
|
|
|
const cachedHostName = localStorage.getItem(hostNameStorageKey)
|
|
|
|
|
if (cachedHostName) {
|
|
|
|
|
currentHostName.value = cachedHostName
|
|
|
|
|
queryParams.hostName = cachedHostName
|
|
|
|
|
}
|
|
|
|
|
// 再通过 WebSocket 刷新获取最新主机名
|
|
|
|
|
const hostName = await resolveCurrentHostName()
|
|
|
|
|
if (hostName) {
|
|
|
|
|
if (hostName && hostName !== cachedHostName) {
|
|
|
|
|
currentHostName.value = hostName
|
|
|
|
|
queryParams.hostName = hostName
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 查询列表 */
|
|
|
|
|
const getList = async () => {
|
|
|
|
|
loading.value = true
|
|
|
|
|
try {
|
|
|
|
|
@ -422,11 +450,67 @@ const resetQuery = () => {
|
|
|
|
|
/** 添加/修改操作 */
|
|
|
|
|
const formRef = ref()
|
|
|
|
|
const openForm = (type: string, id?: number) => {
|
|
|
|
|
let host = normalizeClientHost();
|
|
|
|
|
let host = currentHostName.value;
|
|
|
|
|
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) => {
|
|
|
|
|
try {
|
|
|
|
|
// 删除的二次确认
|
|
|
|
|
|