Commit 5d22652c by liimin

修改数字的判断

1 parent b2777ea1
import { getOssToken } from '@/utils/ossUploadFile/uploadFile.js'
import Queue from '@/utils/Queue.js'
import { Command } from '../ws/constants'
import { isInteger } from '@/utils/utils.js'
export default {
onLoad() {},
data() {
......@@ -361,7 +362,7 @@ export default {
uni.$logger.local.info(`停止文件上传轮询并清除队列`)
},
setInterval(interval, isForce = false) {
if (!interval || (interval && isNaN(interval))) {
if (!isInteger(interval)) {
const error = `参数错误!interval 必需为数字! interval -> ${interval} `
uni.$logger.local.error(error)
return
......
......@@ -177,6 +177,14 @@ async function getAudioFilePath(path = '') {
export function serializeIfObject(msg) {
return typeof msg === 'object' ? JSON.stringify(msg) : msg.toString()
}
export function isInteger(value) {
if (typeof value === 'number') {
return Number.isInteger(value);
} else if (typeof value === 'string') {
return /^-?\d+$/.test(value);
}
return false;
}
export default {
compareVersions,
convertDateTimeFormat,
......
......@@ -19,10 +19,11 @@ export default class CommandFactory {
if (!Worker) {
throw new Error('未找到对应的Worker')
}
if (!this.store.has(Worker.name)) {
this.store.set(Worker.name, new Worker())
}
return this.store.get(Worker.name)
// if (!this.store.has(Worker.name)) {
// this.store.set(Worker.name, new Worker())
// }
// return this.store.get(Worker.name)
return new Worker()
}
clear() {
this.store.clear()
......
......@@ -2,7 +2,7 @@ import io from '@/uni_modules/hyoga-uni-socket_io/uni-socket.io.js'
import { WsTyps } from '../utils/common'
import CommandFactory from './CommandFactory'
import config from '@/config.js'
import { serializeIfObject } from '@/utils/utils.js'
import { serializeIfObject,deepClone } from '@/utils/utils.js'
// const WsTyps = common.constants.WsTyps
export class Ws {
......@@ -20,7 +20,7 @@ export class Ws {
const { code, data, ...o } = await this.login()
if (code == 200) {
this.deviceId = data.id
this.token = data.token
this.token = data.token
this.ws = io(this.wsAddress, {
path:'/websocket/',
auth: { token: this.token, deviceId: this.deviceId },
......@@ -37,7 +37,7 @@ export class Ws {
// const userInfo = uni.$storage.get('userInfo')
// ;(userInfo.name = '胡悦'), (userInfo.phone = '18754575574')
if (!sysInfo?.deviceId) return uni.$logger.local.error('未获取到系统设备信息')
// sysInfo.deviceId='4DF8801064461802495A2452CCD04EE4'
sysInfo.deviceId='4DF8801064461802495A2452CCD04EE4'
// const { name: user, phone: mobile, merchantName } = userInfo
uni.$logger.local.info(`========WS,用户登录 ${JSON.stringify({deviceId:sysInfo.deviceId})}========`)
console.log(this.loginAddress)
......@@ -66,9 +66,10 @@ export class Ws {
function (data) {
uni.$logger.local.info(`WebSocket 收到消息 -> ${JSON.stringify(data)}`)
if (data.errorCode && data.errorCode == 907) return this.connect()
const worker = CommandFactory.getInstance().dispatch(data.command)
worker.work(this.deviceId, data, this)
this.onMessage && this.onMessage(data)
const _data = deepClone(data)
const worker = CommandFactory.getInstance().dispatch(_data.command)
worker.work(this.deviceId, _data, this)
this.onMessage && this.onMessage(_data)
}.bind(this)
)
this.ws.on(WsTyps.MessageTypes.System, function (data) {
......@@ -84,7 +85,6 @@ export class Ws {
})
}
send(data, type = WsTyps.MessageTypes.Private) {
console.log(data)
this.ws.emit(type, { device_id: this.deviceId, ...data })
}
}
import { isInteger } from '@/utils/utils.js'
export default class RemoveLogWorker {
constructor() {}
work(deviceId, data, ws) {
//参数可以不传,默认7天
const days = data.days
if (!days || isNaN(days)) {
if (!isInteger(days) || days==0) {
const error = `RemoveLogWorker -> 删除日志: 参数错误!days 必需为数字! days -> ${days} `
ws.send({ error, data })
uni.$logger.local.error(error)
......
import { isInteger } from '@/utils/utils.js'
export default class SetPollingIntervalWorker {
constructor() {}
work(deviceId, data, ws) {
const interval = data.interval
const isForce = !!data.force
if (!interval || (interval && isNaN(interval))) {
if (!isInteger(interval)) {
const error = `SetPollingIntervalWorker -> 设置轮询时间间隔: 参数错误!interval 必需为数字! interval -> ${interval} `
ws.send({ error, data })
uni.$logger.local.error(error)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!