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 cc99bb22
authored
Oct 11, 2024
by
yixinjj
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
WS改设备号登录
1 parent
b3809c29
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
13 deletions
ws/Ws.js
ws/Ws.js
View file @
cc99bb2
...
@@ -16,12 +16,12 @@ export class Ws {
...
@@ -16,12 +16,12 @@ export class Ws {
this
.
wsAddress
=
`
${
config
.
PROTOCAL
}
://
${
config
.
SERVER
}
:
${
config
.
SOCKET_PORT
}
`
this
.
wsAddress
=
`
${
config
.
PROTOCAL
}
://
${
config
.
SERVER
}
:
${
config
.
SOCKET_PORT
}
`
this
.
loginAddress
=
`
${
config
.
PROTOCAL
}
://
${
config
.
SERVER
}
:
${
config
.
HTTP_PORT
}
/login`
this
.
loginAddress
=
`
${
config
.
PROTOCAL
}
://
${
config
.
SERVER
}
:
${
config
.
HTTP_PORT
}
/login`
}
}
async
connect
()
{
async
connect
()
{
const
{
code
,
data
,
...
o
}
=
await
this
.
login
()
const
{
code
,
data
,
...
o
}
=
await
this
.
login
()
if
(
code
==
200
)
{
if
(
code
==
200
)
{
this
.
deviceId
=
data
.
device_id
this
.
deviceId
=
data
.
id
this
.
token
=
data
.
token
this
.
token
=
data
.
token
this
.
ws
=
io
(
this
.
wsAddress
,
{
this
.
ws
=
io
(
this
.
wsAddress
,
{
auth
:
{
token
:
this
.
token
,
deviceId
:
this
.
deviceId
},
auth
:
{
token
:
this
.
token
,
deviceId
:
this
.
deviceId
},
transports
:
[
'websocket'
],
transports
:
[
'websocket'
],
timeout
:
5000
timeout
:
5000
...
@@ -32,18 +32,20 @@ export class Ws {
...
@@ -32,18 +32,20 @@ export class Ws {
}
}
}
}
async
login
()
{
async
login
()
{
const
userInfo
=
uni
.
$storage
.
get
(
'userInfo'
)
const
sysInfo
=
uni
.
getSystemInfoSync
()
;(
userInfo
.
name
=
'胡悦'
),
(
userInfo
.
phone
=
'18754575574'
)
// const userInfo = uni.$storage.get('userInfo')
if
(
!
userInfo
)
return
uni
.
$logger
.
local
.
error
(
'未获取到系统登录信息'
)
// ;(userInfo.name = '胡悦'), (userInfo.phone = '18754575574')
const
{
name
:
user
,
phone
:
mobile
,
merchantName
}
=
userInfo
if
(
!
sysInfo
?.
deviceId
)
return
uni
.
$logger
.
local
.
error
(
'未获取到系统设备信息'
)
uni
.
$logger
.
local
.
info
(
`========WS,用户登录
${
JSON
.
stringify
({
user
,
mobile
,
merchantName
})}
========`
)
// sysInfo.deviceId='sn123456'
// const { name: user, phone: mobile, merchantName } = userInfo
uni
.
$logger
.
local
.
info
(
`========WS,用户登录
${
JSON
.
stringify
({
deviceId
:
sysInfo
.
deviceId
})}
========`
)
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
uni
.
request
({
uni
.
request
({
url
:
this
.
loginAddress
,
url
:
this
.
loginAddress
,
data
:
{
user
,
mobile
},
data
:
{
sn
:
sysInfo
.
deviceId
},
method
:
'POST'
,
method
:
'POST'
,
dataType
:
'json'
,
dataType
:
'json'
,
success
(
response
)
{
success
(
response
)
{
resolve
(
response
.
data
)
resolve
(
response
.
data
)
},
},
fail
(
err
)
{
fail
(
err
)
{
...
@@ -56,7 +58,7 @@ export class Ws {
...
@@ -56,7 +58,7 @@ export class Ws {
this
.
ws
.
on
(
WsTyps
.
Connected
,
()
=>
{
this
.
ws
.
on
(
WsTyps
.
Connected
,
()
=>
{
uni
.
$logger
.
local
.
info
(
'========WebSocket 连接成功========'
)
uni
.
$logger
.
local
.
info
(
'========WebSocket 连接成功========'
)
})
})
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
)}
`
)
...
...
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