Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
glsx
/
gl_tape
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
3
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 5d22652c
authored
Nov 07, 2024
by
liimin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修改数字的判断
1 parent
b2777ea1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
26 additions
and
14 deletions
mixin/uploader.js
utils/utils.js
ws/CommandFactory.js
ws/Ws.js
ws/workers/RemoveLogWorker.js
ws/workers/SetPollingIntervalWorker.js
mixin/uploader.js
View file @
5d22652
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
(
!
i
nterval
||
(
interval
&&
isNaN
(
interval
)
))
{
if
(
!
i
sInteger
(
interval
))
{
const
error
=
`参数错误!interval 必需为数字! interval ->
${
interval
}
`
uni
.
$logger
.
local
.
error
(
error
)
return
...
...
utils/utils.js
View file @
5d22652
...
...
@@ -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
,
...
...
ws/CommandFactory.js
View file @
5d22652
...
...
@@ -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
()
...
...
ws/Ws.js
View file @
5d22652
...
...
@@ -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
})
}
}
ws/workers/RemoveLogWorker.js
View file @
5d22652
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
)
...
...
ws/workers/SetPollingIntervalWorker.js
View file @
5d22652
import
{
isInteger
}
from
'@/utils/utils.js'
export
default
class
SetPollingIntervalWorker
{
constructor
()
{}
work
(
deviceId
,
data
,
ws
)
{
const
interval
=
data
.
interval
const
isForce
=
!!
data
.
force
if
(
!
i
nterval
||
(
interval
&&
isNaN
(
interval
)
))
{
if
(
!
i
sInteger
(
interval
))
{
const
error
=
`SetPollingIntervalWorker -> 设置轮询时间间隔: 参数错误!interval 必需为数字! interval ->
${
interval
}
`
ws
.
send
({
error
,
data
})
uni
.
$logger
.
local
.
error
(
error
)
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment