拼板印
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

52 lines
1.1 KiB

import { makeSocket } from '@/utils/index'
import eventBus from '@/utils/eventBus'
import { getActivePage } from '@/utils/hook'
let socket = null
export function initSocket() {
if (socket) {
return socket
}
makeSocket({ pageInfo: 'all', retry: true }).then((res) => {
destroySocket()
socket = res
socket.onMessage(handleMessage)
socket.onError(handleError)
socket.onRetry = () => {
handleRetry()
}
})
}
export function destroySocket() {
if (socket) {
socket.close()
socket = null
}
}
function handleError(error) {
console.log('error', error)
destroySocket()
}
function handleRetry() {
socket.onMessage(handleMessage)
socket.onError(handleError)
}
function handleMessage(data) {
if (data.type === 'fnFileAnalysisInform') {
eventBus.emit('singleFileAnalysis', data)
}
if (data.type === 'allFileAnalysisSuccess') {
let page = getActivePage()
if (!page || page.route != 'pages/print/index') {
uni.showToast({
title: '文件全部解析完成,可以下单',
icon: 'none',
duration: 2000
})
}
destroySocket()
}
}