49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
/**
|
||
* @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'
|
||
import { getWebSocketState } from '@/utils/webSocket';
|
||
|
||
export const checkPrintService = async (): Promise<boolean> => { //连接成功返回true,失败返回false
|
||
try {
|
||
if (getWebSocketState() == 1) { // 1表示WebSocket已连接
|
||
return true
|
||
} else {
|
||
await showPrintServiceError('打印服务未连接')
|
||
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)
|
||
Download.name('Gprinter_12.4.0.exe', false)
|
||
}
|
||
}
|
||
|
||
await ElMessageBox.alert(
|
||
`${msg}!<br>请确保目标服务器已<a style="color: #1f79db" onclick="downExe()">下载安装</a> 并运行打印服务!`,
|
||
"客户端未连接",
|
||
{
|
||
dangerouslyUseHTMLString: true,
|
||
}
|
||
)
|
||
}
|
||
|
||
//触发打印服务安装包下载
|
||
export const downloadPrintSetup = () => {
|
||
Download.name('lisprintsetup.exe', false)
|
||
} |