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 3ab5a6dd
authored
Sep 26, 2024
by
yixinjj
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
添加登录和jwt认证
1 parent
1e838929
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
110 additions
and
53 deletions
App.vue
utils/logger/LogCat.js
utils/logger/index.js
utils/utils.js
ws/CommandFactory.js
ws/WorkerFactory.js
ws/Ws.js
ws/workers/CommonWorker.js
ws/workers/GetLogListWorker.js
ws/workers/LogsWorker.js
ws/workers/MessageWorker.js
ws/workers/RemoveLogWorker.js
ws/workers/RemoveRecordWorker.js
ws/workers/StartPollingWorker.js
ws/workers/StopPollingWorker.js
ws/workers/StorageWorker.js
App.vue
View file @
3ab5a6d
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* @Author: 前端 qianduan01@didihu.com.cn
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-04-07 17:09:53
* @Date: 2024-04-07 17:09:53
* @LastEditors: limin
* @LastEditors: limin
* @LastEditTime: 2024-09-2
5 23:50:3
7
* @LastEditTime: 2024-09-2
6 18:22:5
7
* @FilePath: \gl_tape\App.vue
* @FilePath: \gl_tape\App.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
-->
...
@@ -11,12 +11,13 @@ var wv
...
@@ -11,12 +11,13 @@ var wv
import
{
mapState
}
from
'vuex'
import
{
mapState
}
from
'vuex'
import
{
Ws
}
from
'@/ws/Ws.js'
import
{
Ws
}
from
'@/ws/Ws.js'
import
config
from
'@/config.js'
export
default
{
export
default
{
computed
:
{
computed
:
{
...
mapState
(
'audio'
,
[
'isEnd'
,
'isStart'
])
...
mapState
(
'audio'
,
[
'isEnd'
,
'isStart'
])
},
},
onLoad
()
{},
onLoad
()
{
},
onLaunch
:
async
function
()
{
onLaunch
:
async
function
()
{
this
.
setAPPVersion
()
this
.
setAPPVersion
()
setTimeout
(()
=>
{
setTimeout
(()
=>
{
...
@@ -26,7 +27,7 @@ export default {
...
@@ -26,7 +27,7 @@ export default {
uni
.
setKeepScreenOn
({
uni
.
setKeepScreenOn
({
keepScreenOn
:
true
keepScreenOn
:
true
})
})
const
ws
=
new
Ws
({
url
:
`
${
config
.
PROTOCAL
}
://
${
config
.
SERVER
}
:
${
config
.
SOCKET_PORT
}
`
,
token
:
123456
,
deviceId
:
1000000
,
onMessage
:
()
=>
{}
}
)
new
Ws
().
connect
(
)
},
},
methods
:
{
methods
:
{
setAPPVersion
()
{
setAPPVersion
()
{
...
@@ -57,7 +58,7 @@ export default {
...
@@ -57,7 +58,7 @@ export default {
try
{
try
{
uni
.
$logger
?.
error
({
msg
:
e
.
message
||
'捕获全局异常'
,
extra
:
{
error
:
typeof
e
==
'string'
?
e
:
JSON
.
stringify
(
e
)
}
})
uni
.
$logger
?.
error
({
msg
:
e
.
message
||
'捕获全局异常'
,
extra
:
{
error
:
typeof
e
==
'string'
?
e
:
JSON
.
stringify
(
e
)
}
})
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
)
;
console
.
log
(
error
)
}
}
}
}
}
}
...
...
utils/logger/LogCat.js
View file @
3ab5a6d
import
{
getTime
}
from
'./util'
import
{
getTime
}
from
'./util'
import
{
serializeIfObject
}
from
'@/utils/utils.js'
class
LogCat
{
class
LogCat
{
main
=
plus
.
android
.
runtimeMainActivity
()
main
=
plus
.
android
.
runtimeMainActivity
()
File
=
plus
.
android
.
importClass
(
'java.io.File'
)
File
=
plus
.
android
.
importClass
(
'java.io.File'
)
...
@@ -22,11 +23,10 @@ class LogCat {
...
@@ -22,11 +23,10 @@ class LogCat {
writeLog
(
tag
,
msg
)
{
writeLog
(
tag
,
msg
)
{
let
date
=
getTime
(
'YYYY-MM-DD'
)
let
date
=
getTime
(
'YYYY-MM-DD'
)
let
datetime
=
getTime
()
let
datetime
=
getTime
()
msg
=
typeof
msg
!==
'string'
?
JSON
.
stringify
(
msg
)
:
msg
//文件名
//文件名
let
fileName
=
this
.
LogPath
+
'/'
+
date
+
'.txt'
let
fileName
=
this
.
LogPath
+
'/'
+
date
+
'.txt'
//写入的内容
//写入的内容
let
content
=
`
${
datetime
}
[
${
tag
}
] :
${
msg
}
\n`
let
content
=
`
${
datetime
}
[
${
tag
}
] :
${
serializeIfObject
(
msg
)
}
\n`
console
.
log
(
content
.
replace
(
/
\n
/g
,
''
))
console
.
log
(
content
.
replace
(
/
\n
/g
,
''
))
let
path
=
new
this
.
File
(
this
.
LogPath
)
let
path
=
new
this
.
File
(
this
.
LogPath
)
if
(
!
path
.
exists
())
{
if
(
!
path
.
exists
())
{
...
...
utils/logger/index.js
View file @
3ab5a6d
...
@@ -31,7 +31,7 @@ class Logger {
...
@@ -31,7 +31,7 @@ class Logger {
}
}
write
(
level
,
info
)
{
write
(
level
,
info
)
{
this
.
remote
[
level
](
info
)
this
.
remote
[
level
](
info
)
this
.
local
[
level
](
JSON
.
stringify
(
info
)
)
this
.
local
[
level
](
info
)
}
}
getUserInfo
()
{
getUserInfo
()
{
const
userInfo
=
storageApi
.
getUserInfo
()
const
userInfo
=
storageApi
.
getUserInfo
()
...
...
utils/utils.js
View file @
3ab5a6d
...
@@ -153,6 +153,9 @@ async function getFileSaveFolderOnClient() {
...
@@ -153,6 +153,9 @@ async function getFileSaveFolderOnClient() {
const
rootPath
=
await
getFilePath
();
const
rootPath
=
await
getFilePath
();
return
`file://
${
rootPath
}
uniapp_save/`
;
return
`file://
${
rootPath
}
uniapp_save/`
;
}
}
export
function
serializeIfObject
(
msg
)
{
return
typeof
msg
===
'object'
?
JSON
.
stringify
(
msg
)
:
msg
.
toString
()
}
export
default
{
export
default
{
convertDateTimeFormat
,
convertDateTimeFormat
,
deepClone
,
deepClone
,
...
@@ -163,4 +166,5 @@ export default {
...
@@ -163,4 +166,5 @@ export default {
uuid
,
uuid
,
getFilePath
,
getFilePath
,
getFileSaveFolderOnClient
,
getFileSaveFolderOnClient
,
serializeIfObject
};
};
ws/CommandFactory.js
View file @
3ab5a6d
...
@@ -22,9 +22,9 @@ export default class CommandFactory {
...
@@ -22,9 +22,9 @@ export default class CommandFactory {
if
(
!
this
.
store
.
has
(
Worker
.
name
))
{
if
(
!
this
.
store
.
has
(
Worker
.
name
))
{
this
.
store
.
set
(
Worker
.
name
,
new
Worker
())
this
.
store
.
set
(
Worker
.
name
,
new
Worker
())
}
}
return
this
.
store
.
get
(
Worker
.
name
)
return
this
.
store
.
get
(
Worker
.
name
)
}
}
clear
()
{
clear
()
{
this
.
store
.
clear
()
this
.
store
.
clear
()
this
.
instance
=
null
this
.
instance
=
null
}
}
...
...
ws/WorkerFactory.js
View file @
3ab5a6d
...
@@ -2,22 +2,22 @@ import LogsWorker from './workers/LogsWorker'
...
@@ -2,22 +2,22 @@ import LogsWorker from './workers/LogsWorker'
import
CommonWorker
from
'./workers/CommonWorker'
import
CommonWorker
from
'./workers/CommonWorker'
import
MessageWorker
from
'./workers/MessageWorker'
import
MessageWorker
from
'./workers/MessageWorker'
import
StorageWorker
from
'./workers/StorageWorker'
import
StorageWorker
from
'./workers/StorageWorker'
import
GetLogListWorker
from
'./workers/GetLogListWorker'
import
RemoveLogWorker
from
'./workers/RemoveLogWorker'
import
RemoveLogWorker
from
'./workers/RemoveLogWorker'
import
GetLogListWorker
from
'./workers/GetLogListWorker'
import
StopPollingWorker
from
'./workers/StopPollingWorker'
import
RemoveRecordWorker
from
'./workers/RemoveRecordWorker'
import
RemoveRecordWorker
from
'./workers/RemoveRecordWorker'
import
StartPollingWorker
from
'./workers/StartPollingWorker'
import
StartPollingWorker
from
'./workers/StartPollingWorker'
import
StopPollingWorker
from
'./workers/StopPollingWorker'
import
SetPollingIntervalWorker
from
'./workers/SetPollingIntervalWorker'
import
SetPollingIntervalWorker
from
'./workers/SetPollingIntervalWorker'
import
{
Command
}
from
'./constants'
import
{
Command
}
from
'./constants'
const
Workers
=
{
const
Workers
=
{
[
Command
.
GetLog
]:
LogsWorker
,
[
Command
.
GetLog
]:
LogsWorker
,
[
Command
.
Message
]:
MessageWorker
,
[
Command
.
Message
]:
MessageWorker
,
[
Command
.
RemoveLog
]:
RemoveLogWorker
,
[
Command
.
GetStorage
]:
StorageWorker
,
[
Command
.
GetStorage
]:
StorageWorker
,
[
Command
.
GetLogList
]:
GetLogListWorker
,
[
Command
.
GetLogList
]:
GetLogListWorker
,
[
Command
.
RemoveLog
]:
RemoveLo
gWorker
,
[
Command
.
StopPolling
]:
StopPollin
gWorker
,
[
Command
.
RemoveRecord
]:
RemoveRecordWorker
,
[
Command
.
RemoveRecord
]:
RemoveRecordWorker
,
[
Command
.
StartPolling
]:
StartPollingWorker
,
[
Command
.
StartPolling
]:
StartPollingWorker
,
[
Command
.
StopPolling
]:
StopPollingWorker
,
[
Command
.
SetPollingInterval
]:
SetPollingIntervalWorker
[
Command
.
SetPollingInterval
]:
SetPollingIntervalWorker
}
}
export
default
{
export
default
{
...
...
ws/Ws.js
View file @
3ab5a6d
import
io
from
'@/uni_modules/hyoga-uni-socket_io/uni-socket.io.js'
import
io
from
'@/uni_modules/hyoga-uni-socket_io/uni-socket.io.js'
import
{
WsTyps
}
from
'../utils/common'
import
{
WsTyps
}
from
'../utils/common'
import
CommandFactory
from
'./CommandFactory'
import
CommandFactory
from
'./CommandFactory'
import
config
from
'@/config.js'
import
{
serializeIfObject
}
from
'@/utils/utils.js'
// const WsTyps = common.constants.WsTyps
// const WsTyps = common.constants.WsTyps
export
class
Ws
{
export
class
Ws
{
url
wsAddress
loginAddress
token
token
deviceId
deviceId
onMessage
onMessage
ws
ws
constructor
({
url
,
token
,
deviceId
,
onMessage
})
{
constructor
()
{
this
.
url
=
url
this
.
wsAddress
=
`
${
config
.
PROTOCAL
}
://
${
config
.
SERVER
}
:
${
config
.
SOCKET_PORT
}
`
this
.
token
=
token
this
.
loginAddress
=
`
${
config
.
PROTOCAL
}
://
${
config
.
SERVER
}
:
${
config
.
HTTP_PORT
}
/login`
this
.
deviceId
=
deviceId
this
.
onMessage
=
onMessage
this
.
connect
()
}
}
connect
()
{
async
connect
()
{
const
{
token
,
deviceId
,
url
}
=
this
const
{
code
,
data
,
...
o
}
=
await
this
.
login
()
this
.
ws
=
io
(
url
,
{
if
(
code
==
200
)
{
auth
:
{
token
,
deviceId
},
this
.
deviceId
=
data
.
device_id
transports
:
[
'websocket'
],
this
.
token
=
data
.
token
timeout
:
5000
this
.
ws
=
io
(
this
.
wsAddress
,
{
auth
:
{
token
:
this
.
token
,
deviceId
:
this
.
deviceId
},
transports
:
[
'websocket'
],
timeout
:
5000
})
this
.
subscribe
()
}
else
{
uni
.
$logger
.
local
.
error
(
`登录失败 ->
${
serializeIfObject
({
code
,
data
,
o
})}
`
)
}
}
async
login
()
{
const
userInfo
=
uni
.
$storage
.
get
(
'userInfo'
)
userInfo
.
name
=
'庞丽丽'
,
userInfo
.
phone
=
'15598191116'
if
(
!
userInfo
)
return
uni
.
$logger
.
local
.
error
(
'未获取到系统登录信息'
)
uni
.
$logger
.
local
.
info
(
`========WS,用户登录
${
JSON
.
stringify
(
userInfo
)}
========`
)
const
{
name
:
user
,
phone
:
mobile
}
=
userInfo
return
new
Promise
((
resolve
,
reject
)
=>
{
uni
.
request
({
url
:
this
.
loginAddress
,
data
:
{
user
,
mobile
},
method
:
'POST'
,
dataType
:
'json'
,
success
(
response
)
{
resolve
(
response
.
data
)
},
fail
(
err
)
{
uni
.
$logger
.
local
.
error
(
`登录失败, 请检查网络或联系管理员! err->
${
serializeIfObject
(
err
)}
`
)
}
})
})
})
this
.
subscribe
()
}
}
subscribe
()
{
subscribe
()
{
this
.
ws
.
on
(
WsTyps
.
Connected
,
()
=>
{
this
.
ws
.
on
(
WsTyps
.
Connected
,
()
=>
{
...
@@ -31,25 +60,26 @@ export class Ws {
...
@@ -31,25 +60,26 @@ export class Ws {
this
.
ws
.
on
(
this
.
ws
.
on
(
WsTyps
.
MessageTypes
.
Private
,
WsTyps
.
MessageTypes
.
Private
,
function
(
data
)
{
function
(
data
)
{
uni
.
$logger
.
local
.
info
(
`WebSocket 收到指令 ->
${
JSON
.
stringify
(
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
)
const
worker
=
CommandFactory
.
getInstance
().
dispatch
(
data
.
command
)
worker
.
work
(
this
.
deviceId
,
data
,
this
.
ws
)
worker
.
work
(
this
.
deviceId
,
data
,
this
.
ws
)
this
.
onMessage
&&
this
.
onMessage
(
data
)
this
.
onMessage
&&
this
.
onMessage
(
data
)
}.
bind
(
this
)
}.
bind
(
this
)
)
)
this
.
ws
.
on
(
WsTyps
.
MessageTypes
.
System
,
function
(
data
)
{
this
.
ws
.
on
(
WsTyps
.
MessageTypes
.
System
,
function
(
data
)
{
uni
.
$logger
.
local
.
info
(
`========WebSocket 收到系统消息
${
typeof
data
==
'object'
?
JSON
.
stringify
(
msg
)
:
data
}
========`
)
uni
.
$logger
.
local
.
info
(
`========WebSocket 收到系统消息
${
serializeIfObject
(
data
)
}
========`
)
})
})
this
.
ws
.
on
(
WsTyps
.
Disconnected
,
function
()
{
this
.
ws
.
on
(
WsTyps
.
Disconnected
,
()
=>
{
CommandFactory
.
clear
()
CommandFactory
.
getInstance
().
clear
()
uni
.
$logger
.
local
.
info
(
`========WebSocket 断开连接 device_id->
${
this
.
deviceId
}
========`
)
uni
.
$logger
.
local
.
info
(
`========WebSocket 断开连接 device_id->
${
this
.
deviceId
}
========`
)
})
})
this
.
ws
.
on
(
WsTyps
.
Eroor
,
msg
=>
{
this
.
ws
.
on
(
WsTyps
.
Eroor
,
msg
=>
{
CommandFactory
.
clear
()
CommandFactory
.
getInstance
().
clear
()
uni
.
$logger
.
error
(
`========WebSocket 异常 device_id->
${
this
.
deviceId
}
msg ->
${
typeof
msg
==
'object'
?
JSON
.
stringify
(
msg
)
:
msg
}
========`
)
uni
.
$logger
.
error
(
`========WebSocket 异常 device_id->
${
this
.
deviceId
}
msg ->
${
serializeIfObject
(
msg
)
}
========`
)
})
})
}
}
send
(
data
,
type
=
WsTyps
.
MessageTypes
.
Private
)
{
send
(
data
,
type
=
WsTyps
.
MessageTypes
.
Private
)
{
this
.
ws
.
emit
(
type
,
{
device_id
:
this
.
deviceId
,
...
data
})
//
this.ws.emit(type, { device_id: this.deviceId, ...data })
}
}
}
}
ws/workers/CommonWorker.js
View file @
3ab5a6d
import
{
serializeIfObject
}
from
'@/utils/utils.js'
export
default
class
CommonWorker
{
export
default
class
CommonWorker
{
constructor
()
{}
constructor
()
{}
work
(
deviceId
,
data
)
{
work
(
deviceId
,
data
)
{
uni
.
$logger
.
local
.
info
(
`收到WebSocket 消息: deviceId->
${
deviceId
}
, data->
${
typeof
data
===
'object'
?
JSON
.
stringify
(
data
):
data
}
`
)
uni
.
$logger
.
local
.
info
(
`收到WebSocket 消息: deviceId->
${
deviceId
}
, data->
${
serializeIfObject
(
data
)
}
`
)
// console.log(`收到WebSocket 消息: deviceId->${deviceId}, data->${typeof data ==='[object Object]'?JSON.stringify(data):data}`)
// console.log(`收到WebSocket 消息: deviceId->${deviceId}, data->${typeof data ==='[object Object]'?JSON.stringify(data):data}`)
}
}
}
}
ws/workers/GetLogListWorker.js
View file @
3ab5a6d
export
default
class
GetLogListWorker
{
export
default
class
GetLogListWorker
{
constructor
()
{}
constructor
()
{}
work
(
deviceId
,
data
,
ws
)
{
work
(
deviceId
,
data
,
ws
)
{
const
beginDate
=
data
.
beginDate
try
{
const
endDate
=
data
.
endDate
const
beginDate
=
data
.
beginDate
const
LogList
=
uni
.
$logger
.
local
.
getFiles
(
beginDate
,
endDate
)
const
endDate
=
data
.
endDate
ws
.
send
({
LogList
})
const
LogList
=
uni
.
$logger
.
local
.
getFiles
(
beginDate
,
endDate
)
uni
.
$logger
.
local
.
info
(
`获取日志列表成功! beginDate ->
${
beginDate
}
endDate->
${
endDate
}
res->
${
serializeIfObject
(
LogList
)}
`
)
ws
.
send
({
LogList
})
}
catch
(
error
)
{
uni
.
$logger
.
local
.
error
(
`获取日志列表失败! beginDate ->
${
beginDate
}
endDate->
${
endDate
}
error->
${
serializeIfObject
(
error
)}
`
)
}
}
}
}
}
ws/workers/LogsWorker.js
View file @
3ab5a6d
import
config
from
'@/config.js'
import
config
from
'@/config.js'
import
{
serializeIfObject
}
from
'@/utils/utils.js'
export
default
class
LogsWorker
{
export
default
class
LogsWorker
{
logFile
=
null
logFile
=
null
constructor
()
{
constructor
()
{
...
@@ -27,13 +28,10 @@ export default class LogsWorker {
...
@@ -27,13 +28,10 @@ export default class LogsWorker {
type
:
'log'
type
:
'log'
},
},
success
:
res
=>
{
success
:
res
=>
{
console
.
log
(
res
)
uni
.
$logger
.
local
.
info
(
`文件上传成功! res->
${
serializeIfObject
(
res
)}
`
)
},
},
fail
:
res
=>
{
fail
:
res
=>
{
console
.
log
(
res
)
uni
.
$logger
.
local
.
error
(
`文件上传失败! res->
${
serializeIfObject
(
res
)}
`
)
},
complete
:
res
=>
{
// console.log(res)
}
}
})
})
}
}
...
...
ws/workers/MessageWorker.js
View file @
3ab5a6d
import
{
serializeIfObject
}
from
'@/utils/utils.js'
export
default
class
MessageWorker
{
export
default
class
MessageWorker
{
constructor
()
{}
constructor
()
{}
work
(
deviceId
,
data
)
{
work
(
deviceId
,
data
)
{
uni
.
$logger
.
local
.
info
(
`收到WebSocket 消息: deviceId->
${
deviceId
}
, data->
${
typeof
data
===
'object'
?
JSON
.
stringify
(
data
):
data
}
`
)
uni
.
$logger
.
local
.
info
(
`收到WebSocket 消息: deviceId->
${
deviceId
}
, data->
${
serializeIfObject
(
data
)
}
`
)
// console.log(`收到WebSocket 消息: deviceId->${deviceId}, data->${typeof data ==='[object Object]'?JSON.stringify(data):data}`)
// console.log(`收到WebSocket 消息: deviceId->${deviceId}, data->${typeof data ==='[object Object]'?JSON.stringify(data):data}`)
}
}
}
}
ws/workers/RemoveLogWorker.js
View file @
3ab5a6d
...
@@ -10,6 +10,8 @@ export default class RemoveLogWorker {
...
@@ -10,6 +10,8 @@ export default class RemoveLogWorker {
return
return
}
}
uni
.
$logger
.
local
.
removeOverDays
(
days
)
uni
.
$logger
.
local
.
removeOverDays
(
days
)
ws
.
send
({
code
:
200
,
msg
:
`删除
${
days
}
天前的日志成功!`
,
data
})
const
msg
=
`删除
${
days
}
天前的日志成功!`
uni
.
$logger
.
local
.
info
(
msg
)
ws
.
send
({
code
:
200
,
msg
:
msg
,
data
})
}
}
}
}
ws/workers/RemoveRecordWorker.js
View file @
3ab5a6d
import
{
serializeIfObject
}
from
'@/utils/utils.js'
export
default
class
RemoveRecordWorker
{
export
default
class
RemoveRecordWorker
{
constructor
()
{}
constructor
()
{}
async
work
(
deviceId
,
data
,
ws
)
{
async
work
(
deviceId
,
data
,
ws
)
{
const
recordId
=
data
.
id
const
recordId
=
data
.
id
if
(
!
recordId
)
{
if
(
!
recordId
)
{
ws
.
send
({
error
:
'删除接待记录,缺少记录id'
})
const
msg
=
`删除接待记录,缺少记录id`
uni
.
$logger
.
local
.
info
(
msg
)
ws
.
send
({
error
:
msg
})
return
return
}
}
const
unlock
=
await
uni
.
$recordManager
.
lock
()
const
unlock
=
await
uni
.
$recordManager
.
lock
()
...
@@ -11,12 +14,19 @@ export default class RemoveRecordWorker {
...
@@ -11,12 +14,19 @@ export default class RemoveRecordWorker {
const
records
=
uni
.
$recordManager
.
getRecords
()
const
records
=
uni
.
$recordManager
.
getRecords
()
const
record
=
records
.
find
(
item
=>
item
.
id
===
recordId
)
const
record
=
records
.
find
(
item
=>
item
.
id
===
recordId
)
if
(
!
record
)
{
if
(
!
record
)
{
ws
.
send
({
error
:
`记录不存在 id ->
${
recordId
}
`
})
const
msg
=
`记录不存在 id ->
${
recordId
}
`
uni
.
$logger
.
local
.
info
(
msg
)
ws
.
send
({
error
:
msg
})
return
return
}
}
uni
.
$recordManager
.
removeRecord
(
recordId
)
uni
.
$recordManager
.
removeRecord
(
recordId
)
ws
.
send
({
code
:
200
,
msg
:
`记录删除成功 id ->
${
recordId
}
`
})
const
msg
=
`记录删除成功 id ->
${
recordId
}
`
uni
.
$logger
.
local
.
info
(
msg
)
ws
.
send
({
code
:
200
,
msg
})
}
catch
(
error
)
{
}
catch
(
error
)
{
const
msg
=
`记录删除异常 id ->
${
recordId
}
error ->
${
serializeIfObject
(
error
)}
`
uni
.
$logger
.
local
.
error
(
msg
)
ws
.
send
({
error
:
error
,
recordId
})
}
finally
{
}
finally
{
unlock
()
unlock
()
}
}
...
...
ws/workers/StartPollingWorker.js
View file @
3ab5a6d
...
@@ -3,6 +3,7 @@ export default class StartPollingWorker {
...
@@ -3,6 +3,7 @@ export default class StartPollingWorker {
work
(
deviceId
,
data
,
ws
)
{
work
(
deviceId
,
data
,
ws
)
{
const
isForce
=
!!
data
.
force
const
isForce
=
!!
data
.
force
uni
.
$emit
(
data
.
command
,
isForce
)
uni
.
$emit
(
data
.
command
,
isForce
)
ws
.
send
({
code
:
200
,
msg
:
`启动轮询指令下发并执行成功!`
,
data
})
const
msg
=
`启动轮询指令下发并执行成功!`
ws
.
send
({
code
:
200
,
msg
,
data
})
}
}
}
}
ws/workers/StopPollingWorker.js
View file @
3ab5a6d
...
@@ -2,6 +2,7 @@ export default class StopPollingWorker {
...
@@ -2,6 +2,7 @@ export default class StopPollingWorker {
constructor
()
{}
constructor
()
{}
work
(
deviceId
,
data
,
ws
)
{
work
(
deviceId
,
data
,
ws
)
{
uni
.
$emit
(
data
.
command
)
uni
.
$emit
(
data
.
command
)
ws
.
send
({
code
:
200
,
msg
:
`终止轮询指令下发并执行成功!`
,
data
})
const
msg
=
`终止轮询指令下发并执行成功!`
ws
.
send
({
code
:
200
,
msg
,
data
})
}
}
}
}
ws/workers/StorageWorker.js
View file @
3ab5a6d
import
{
constData
}
from
'../../utils/cache'
import
{
constData
}
from
'../../utils/cache'
import
{
serializeIfObject
}
from
'@/utils/utils.js'
export
default
class
StorageWorker
{
export
default
class
StorageWorker
{
constructor
()
{}
constructor
()
{}
work
(
deviceId
,
data
,
ws
)
{
work
(
deviceId
,
data
,
ws
)
{
let
key
=
data
.
key
let
key
=
data
.
key
if
(
!
constData
.
STORAGE_OBJECTKEY
[
key
])
{
if
(
!
constData
.
STORAGE_OBJECTKEY
[
key
])
{
uni
.
$logger
.
local
.
error
(
`不存在的 Storage Key->
${
key
}
. data->
${
typeof
data
===
'object'
?
JSON
.
stringify
(
data
)
:
data
}
`
)
uni
.
$logger
.
local
.
error
(
`不存在的 Storage Key->
${
key
}
. data->
${
serializeIfObject
(
data
)
}
`
)
console
.
log
(
`不存在的 Storage Key->
${
key
}
.`
)
console
.
log
(
`不存在的 Storage Key->
${
key
}
.`
)
return
return
}
}
const
value
=
uni
.
$storage
.
get
(
key
)
const
value
=
uni
.
$storage
.
get
(
key
)
const
msg
=
`获取本地缓存! key->
${
key
}
value->
${
serializeIfObject
(
value
)}
`
uni
.
$logger
.
local
.
info
(
msg
)
ws
.
send
({
[
key
]:
value
})
ws
.
send
({
[
key
]:
value
})
}
}
}
}
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