2026-03-09 18:04:16 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @file printHelper.ts 检查打印服务连接状态
|
|
|
|
|
|
* @author: w
|
|
|
|
|
|
* @since: 2026-01-26
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import { ElMessageBox, ElMessage } from 'element-plus'
|
|
|
|
|
|
import { printcheck } from '@/api/checkCode/index'
|
|
|
|
|
|
import Download from '@/plugins/download'
|
2026-04-02 18:01:47 +08:00
|
|
|
|
import { getWebSocketState } from '@/utils/webSocket';
|
2026-03-09 18:04:16 +08:00
|
|
|
|
|
|
|
|
|
|
export const checkPrintService = async (): Promise<boolean> => { //连接成功返回true,失败返回false
|
|
|
|
|
|
try {
|
2026-04-02 18:01:47 +08:00
|
|
|
|
if (getWebSocketState() == 1) { // 1表示WebSocket已连接
|
2026-03-09 18:04:16 +08:00
|
|
|
|
return true
|
|
|
|
|
|
} else {
|
2026-04-02 18:01:47 +08:00
|
|
|
|
await showPrintServiceError('打印服务未连接')
|
2026-03-09 18:04:16 +08:00
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('打印服务检查失败:', error)
|
|
|
|
|
|
await showPrintServiceError('打印服务连接异常')
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const showPrintServiceError = async (msg: string) => {
|
|
|
|
|
|
// 挂载downExe方法到window,供提示框内的onclick调用
|
|
|
|
|
|
if (!(window as any).downExe) {
|
|
|
|
|
|
(window as any).downExe = () => {
|
|
|
|
|
|
Download.name('lisprintsetup.exe', false)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await ElMessageBox.alert(
|
|
|
|
|
|
`${msg}!<br>请确保目标服务器已<a style="color: #1f79db" onclick="downExe()">下载安装</a> 并运行打印服务!`,
|
|
|
|
|
|
"客户端未连接",
|
|
|
|
|
|
{
|
|
|
|
|
|
dangerouslyUseHTMLString: true,
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//触发打印服务安装包下载
|
|
|
|
|
|
export const downloadPrintSetup = () => {
|
|
|
|
|
|
Download.name('lisprintsetup.exe', false)
|
|
|
|
|
|
}
|