lis8.0-vue3/src/utils/printHelper.ts
2026-01-26 17:41:14 +08:00

50 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @file printHelper.ts 检查打印服务连接状态
* @author: w
* @since: 2026-01-26
*/
import { ElMessageBox, ElMessage } from 'element-plus'
import { printcheck } from '@/api/checkCode/index'
// @ts-ignore
import Download from '@/plugins/download'
export const checkPrintService = async (): Promise<boolean> => { //连接成功返回true,失败返回false
try {
const res = await printcheck()
if (res.code == 0) {
return true
} else {
await showPrintServiceError(res.msg)
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)
}