Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BCDH-APP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
首开风险隐患双控平台
BCDH-APP
Commits
15797eb3
Commit
15797eb3
authored
Apr 01, 2026
by
baoxiaode
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
个推
parent
7a09fd1f
Pipeline
#11064
passed with stage
Changes
9
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
494 additions
and
111 deletions
+494
-111
.eslintrc.js
.eslintrc.js
+2
-2
src/router/index.js
src/router/index.js
+1
-1
src/service/table.js
src/service/table.js
+3
-3
src/service/workbench.js
src/service/workbench.js
+1
-1
src/utils/push.js
src/utils/push.js
+249
-70
src/utils/websocket.js
src/utils/websocket.js
+176
-0
src/views/Login2.vue
src/views/Login2.vue
+18
-20
src/views/danger/dangerPatrol/recordPatrolTime/index.vue
src/views/danger/dangerPatrol/recordPatrolTime/index.vue
+14
-3
vue.config.js
vue.config.js
+30
-11
No files found.
.eslintrc.js
View file @
15797eb3
...
...
@@ -7,8 +7,8 @@ module.exports = {
'
plugin:vue/essential
'
],
rules
:
{
'
no-console
'
:
process
.
env
.
NODE_ENV
===
'
production
'
?
'
error
'
:
'
off
'
,
'
no-debugger
'
:
process
.
env
.
NODE_ENV
===
'
production
'
?
'
error
'
:
'
off
'
'
no-console
'
:
'
off
'
,
'
no-debugger
'
:
'
off
'
},
parserOptions
:
{
parser
:
'
babel-eslint
'
...
...
src/router/index.js
View file @
15797eb3
...
...
@@ -875,7 +875,7 @@ const routes = [{
const
router
=
new
VueRouter
({
mode
:
'
history
'
,
base
:
process
.
env
.
BASE_URL
,
base
:
'
/wys/
'
,
routes
})
...
...
src/service/table.js
View file @
15797eb3
...
...
@@ -3,7 +3,7 @@ import request from '@/utils/axios'
/*get请求*/
export
function
getFun
(
url
,
params
)
{
return
request
({
url
:
'
/hse/app-api/
'
+
url
,
url
:
'
/hse/
wys/
app-api/
'
+
url
,
method
:
'
get
'
,
params
})
...
...
@@ -11,7 +11,7 @@ export function getFun(url,params) {
/* post请求 */
export
function
postFun
(
url
,
data
)
{
return
request
({
url
:
'
/hse/app-api/
'
+
url
,
url
:
'
/hse/
wys/
app-api/
'
+
url
,
method
:
'
post
'
,
data
})
...
...
@@ -43,7 +43,7 @@ export function putFunTwo(url,data) {
/* put请求 */
export
function
putFun
(
url
,
data
)
{
return
request
({
url
:
'
/hse/app-api/
'
+
url
,
url
:
'
/hse/
wys/
app-api/
'
+
url
,
method
:
'
put
'
,
data
})
...
...
src/service/workbench.js
View file @
15797eb3
...
...
@@ -11,7 +11,7 @@ export function getFun(url,params) {
/* post请求 */
export
function
postWork
(
url
,
data
)
{
return
request
({
url
:
'
/hse/app-api/
'
+
url
,
url
:
'
/hse/
wys/
app-api/
'
+
url
,
method
:
'
post
'
,
data
})
...
...
src/utils/push.js
View file @
15797eb3
This diff is collapsed.
Click to expand it.
src/utils/websocket.js
0 → 100644
View file @
15797eb3
import
pushInstance
from
'
./push
'
import
{
getToken
}
from
'
./auth
'
let
socket
=
null
let
reconnectTimer
=
null
let
lockReconnect
=
false
let
currentUserId
=
null
// 存储 userId
const
RECONNECT_INTERVAL
=
5000
// 监听应用前后台切换
// 当应用切回前台时,如果 WebSocket 断开,则尝试重连
if
(
document
)
{
document
.
addEventListener
(
'
visibilitychange
'
,
()
=>
{
if
(
document
.
visibilityState
===
'
visible
'
)
{
console
.
log
(
'
App returned to foreground, checking WebSocket status...
'
)
if
(
!
socket
||
socket
.
readyState
===
WebSocket
.
CLOSED
||
socket
.
readyState
===
WebSocket
.
CLOSING
)
{
console
.
log
(
'
WebSocket disconnected, attempting to reconnect...
'
)
if
(
lastUrl
)
{
// 需要保存最近一次连接的 URL
initWebSocket
(
lastUrl
,
currentUserId
)
}
}
}
})
}
let
lastUrl
=
null
// 保存最近一次连接的 URL
export
const
initWebSocket
=
(
url
,
userId
)
=>
{
if
(
!
url
)
{
console
.
warn
(
'
WebSocket URL is missing
'
)
return
}
lastUrl
=
url
// 保存 URL 供重连使用
// 更新 currentUserId
if
(
userId
)
{
currentUserId
=
userId
}
// 如果已存在连接,且状态为 OPEN 或 CONNECTING,则复用现有连接
if
(
socket
&&
(
socket
.
readyState
===
WebSocket
.
OPEN
||
socket
.
readyState
===
WebSocket
.
CONNECTING
))
{
console
.
log
(
'
WebSocket connection already exists
'
)
// 如果传入了新的 userId,尝试重新发送认证消息
if
(
userId
&&
currentUserId
===
userId
&&
socket
.
readyState
===
WebSocket
.
OPEN
)
{
console
.
log
(
'
Resending userId to existing WebSocket:
'
,
currentUserId
)
sendWebSocketMessage
({
type
:
'
auth
'
,
userId
:
currentUserId
})
}
return
}
// 如果已存在关闭或正在关闭的连接,先清理
// 注意:如果是异常关闭(如网络中断),socket可能处于CLOSED状态,此时也需要清理
if
(
socket
)
{
try
{
// 移除所有监听器,防止内存泄漏或旧连接回调触发
socket
.
onopen
=
null
socket
.
onmessage
=
null
socket
.
onclose
=
null
socket
.
onerror
=
null
// 只有在未关闭的情况下才尝试关闭
if
(
socket
.
readyState
!==
WebSocket
.
CLOSED
&&
socket
.
readyState
!==
WebSocket
.
CLOSING
)
{
socket
.
close
()
}
}
catch
(
e
)
{
console
.
warn
(
'
Error closing existing socket:
'
,
e
)
}
socket
=
null
}
try
{
socket
=
new
WebSocket
(
url
)
initEventHandle
(
url
)
}
catch
(
e
)
{
console
.
error
(
'
WebSocket connection failed:
'
,
e
)
reconnect
(
url
)
}
}
const
initEventHandle
=
(
url
)
=>
{
socket
.
onopen
=
()
=>
{
console
.
log
(
'
WebSocket connected
'
)
// 重置重连状态
lockReconnect
=
false
// 连接成功后发送 userId
if
(
currentUserId
)
{
console
.
log
(
'
Sending userId to WebSocket:
'
,
currentUserId
)
sendWebSocketMessage
({
type
:
'
auth
'
,
userId
:
currentUserId
})
}
}
socket
.
onmessage
=
(
event
)
=>
{
console
.
log
(
'
WebSocket received:
'
,
event
.
data
)
try
{
const
message
=
event
.
data
// 尝试解析消息
let
payload
=
{}
try
{
payload
=
JSON
.
parse
(
message
)
}
catch
(
e
)
{
// 如果不是JSON,则作为纯文本内容
payload
=
{
content
:
message
}
}
// 构造符合 handle5PlusPushMessage 预期的对象
// handle5PlusPushMessage 会调用 parse5PlusPushData,它期望 message.payload 或 message 本身
const
pushMessage
=
{
payload
:
payload
,
content
:
payload
.
content
||
message
,
title
:
payload
.
title
||
'
新消息
'
}
pushInstance
.
handle5PlusPushMessage
(
pushMessage
)
}
catch
(
e
)
{
console
.
error
(
'
WebSocket message handling error:
'
,
e
)
}
}
socket
.
onclose
=
(
event
)
=>
{
console
.
log
(
'
WebSocket closed:
'
,
event
.
code
,
event
.
reason
)
// 只有非正常关闭才重连(例如网络中断或服务器断开)
// 正常关闭 (1000) 或页面卸载时不应重连
if
(
event
.
code
!==
1000
)
{
reconnect
(
url
)
}
}
socket
.
onerror
=
(
error
)
=>
{
console
.
error
(
'
WebSocket error:
'
,
error
)
reconnect
(
url
)
}
}
const
reconnect
=
(
url
)
=>
{
if
(
lockReconnect
)
return
lockReconnect
=
true
if
(
reconnectTimer
)
{
clearTimeout
(
reconnectTimer
)
}
console
.
log
(
`Attempting to reconnect in
${
RECONNECT_INTERVAL
}
ms...`
)
reconnectTimer
=
setTimeout
(()
=>
{
// 重连时使用保存的 currentUserId
initWebSocket
(
url
,
currentUserId
)
lockReconnect
=
false
},
RECONNECT_INTERVAL
)
}
export
const
closeWebSocket
=
()
=>
{
if
(
reconnectTimer
)
clearTimeout
(
reconnectTimer
)
lockReconnect
=
true
// 防止触发重连
if
(
socket
)
{
socket
.
onclose
=
null
socket
.
close
()
socket
=
null
}
}
// 发送消息方法
export
const
sendWebSocketMessage
=
(
data
)
=>
{
if
(
socket
&&
socket
.
readyState
===
WebSocket
.
OPEN
)
{
socket
.
send
(
typeof
data
===
'
string
'
?
data
:
JSON
.
stringify
(
data
))
}
else
{
console
.
error
(
'
WebSocket is not connected
'
)
}
}
src/views/Login2.vue
View file @
15797eb3
...
...
@@ -40,11 +40,13 @@
<
script
>
import
{
getFun
,
postFun
}
from
'
@/service/table
'
import
pushInstance
from
'
@/utils/push
'
import
{
setToken
}
from
'
@/utils/auth
'
import
{
encrypt
,
decrypt
}
from
'
@/utils/jsencrypt
'
import
{
crypto
}
from
'
@/utils/crypto
'
import
{
setUserInfo
,
getUserInfo
}
from
'
@/utils/userInfo
'
import
pushInstance
from
'
@/utils/push
'
import
{
setUserInfo
,
getUserInfo
}
from
'
@/utils/userInfo
'
import
{
initWebSocket
}
from
'
@/utils/websocket
'
export
default
{
data
()
{
return
{
...
...
@@ -56,23 +58,10 @@ export default {
clientId
:
null
};
},
mounted
()
{
if
(
localStorage
.
getItem
(
'
pwd
'
))
{
this
.
password
=
decrypt
(
localStorage
.
getItem
(
'
pwd
'
))
this
.
username
=
localStorage
.
getItem
(
'
username
'
)
}
if
(
pushInstance
.
clientId
)
{
this
.
clientId
=
pushInstance
.
clientId
;
uni
.
showModal
({
title
:
'
客户端ID:
'
+
this
.
clientId
,
success
(
res
)
{
if
(
res
.
confirm
)
{
console
.
log
(
'
用户点击确定
'
)
}
else
if
(
res
.
cancel
)
{
console
.
log
(
'
用户点击取消
'
)
}
}
})
async
mounted
()
{
if
(
localStorage
.
getItem
(
'
pwd
'
)){
this
.
password
=
decrypt
(
localStorage
.
getItem
(
'
pwd
'
))
this
.
username
=
localStorage
.
getItem
(
'
username
'
)
}
},
created
()
{
...
...
@@ -95,7 +84,6 @@ export default {
position
:
'
static
'
,
});
plus
.
webview
.
currentWebview
().
append
(
barcode
);
//barcode.start();开始扫码识别(我们把这句代码注释了,因为我们不需要扫描任何东西)
},
...
...
@@ -103,6 +91,7 @@ export default {
var
obj
=
{
username
:
this
.
username
,
password
:
this
.
password
,
deviceId
:
this
.
clientId
||
this
.
deviceId
||
''
}
this
.
$toast
.
loading
({
message
:
'
登录中...
'
,
...
...
@@ -128,6 +117,15 @@ export default {
setUserInfo
(
userInfo
)
localStorage
.
setItem
(
'
pwd
'
,
encrypt
(
this
.
password
))
localStorage
.
setItem
(
'
username
'
,
this
.
username
)
// 初始化 WebSocket 连接
// 后端端口: 8099, Context Path: /hse/wy, Endpoint: /wfWarnSocket
// const wsUrl = 'ws://192.168.4.246:8099/hse/wy/wfWarnSocket';
// const wsUrl = 'ws://localhost:8099/hse/wy/wfWarnSocket';
const
wsUrl
=
'
wss://skpt.bcdh.com.cn:8099/ws
'
;
console
.
log
(
'
正在连接 WebSocket:
'
,
wsUrl
)
initWebSocket
(
wsUrl
,
userInfo
.
userId
)
if
(
!
Response2
.
data
.
initializePassword
)
{
this
.
$router
.
push
(
'
/save-workbench
'
)
}
else
{
...
...
src/views/danger/dangerPatrol/recordPatrolTime/index.vue
View file @
15797eb3
<
template
>
<div>
<LHeader
:text=
"text"
></LHeader>
<!-- 内容列表 -->
<div
class=
"title"
>
2022年4月26日
</div>
<!-- 内容列表 改为获取当前时间-->
<div
class=
"title"
>
{{
currentDate
}}
</div>
<!--
<p
class=
"title-text"
>
巡查发起人:
{{
assignName
}}
</p>
-->
<p
class=
"title-text"
>
系统提示:请按时完成巡查工作。
</p>
<div
class=
"con-list"
>
...
...
@@ -47,6 +46,7 @@ export default {
value
:
''
,
text
:
"
巡查记录
"
,
assignName
:
''
,
currentDate
:
''
,
// 初始化currentDate
contentList
:
[
],
...
...
@@ -90,9 +90,20 @@ export default {
};
},
mounted
()
{
this
.
initCurrentDate
()
this
.
loading
()
},
methods
:
{
initCurrentDate
()
{
const
now
=
new
Date
();
const
year
=
now
.
getFullYear
();
const
month
=
String
(
now
.
getMonth
()
+
1
).
padStart
(
2
,
'
0
'
);
const
day
=
String
(
now
.
getDate
()).
padStart
(
2
,
'
0
'
);
const
hours
=
String
(
now
.
getHours
()).
padStart
(
2
,
'
0
'
);
const
minutes
=
String
(
now
.
getMinutes
()).
padStart
(
2
,
'
0
'
);
const
seconds
=
String
(
now
.
getSeconds
()).
padStart
(
2
,
'
0
'
);
this
.
currentDate
=
`
${
year
}
年
${
month
}
月
${
day
}
日
${
hours
}
:
${
minutes
}
:
${
seconds
}
`
;
},
loading
(){
getFun
(
"
patrol/cycle/list
"
).
then
((
res
)
=>
{
...
...
vue.config.js
View file @
15797eb3
module
.
exports
=
{
devServer
:
{
open
:
false
,
// 跨域
proxy
:
{
'
/app-api
'
:
{
target
:
'
http://192.168.4.157:8096
'
,
// target: 'http://192.168.15.146:8096',
// changeOrigin: true,
// logLevel:'debug',
}
publicPath
:
'
/wys/
'
,
devServer
:
{
open
:
false
,
port
:
8080
,
// 前端服务端口(与你的请求地址一致)
https
:
false
,
proxy
:
{
// 匹配前端请求的 /hse 前缀
'
/hse/wys
'
:
{
target
:
'
http://192.168.4.232:8099
'
,
changeOrigin
:
true
,
logLevel
:
'
debug
'
},
'
/hse
'
:
{
ws
:
true
,
target
:
'
http://192.168.4.232:8099
'
,
// 尝试统一到 232
changeOrigin
:
true
,
logLevel
:
'
debug
'
,
pathRewrite
:
{
'
^/hse/app-api
'
:
'
/hse/wy/app-api
'
},
https
:
true
// 修正后端返回的 Cookie 路径(确保前端能正常携带)
onProxyRes
:
function
(
proxyRes
,
req
,
res
)
{
if
(
proxyRes
.
headers
[
'
set-cookie
'
])
{
proxyRes
.
headers
[
'
set-cookie
'
]
=
proxyRes
.
headers
[
'
set-cookie
'
].
map
(
cookie
=>
{
// 后端返回的 Cookie Path 是 /hse/wy,改为前端的 /hse
return
cookie
.
replace
(
/Path=
\/
hse
\/
wy/
,
'
Path=/hse
'
);
});
}
}
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment