Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas_plus
/
dj-car-life-system
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit d44d19e6
authored
May 22, 2026
by
张立顺
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix websocket连接bug修复
1 parent
913954e6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
2 deletions
src/views/systemConfig/merchant/financialRules/components/financialCalculationDialog.vue
src/views/systemConfig/merchant/financialRules/utils/buildWebSocketUrl.js
tests/unit/financialRules/buildWebSocketUrl.spec.js
src/views/systemConfig/merchant/financialRules/components/financialCalculationDialog.vue
View file @
d44d19e
...
...
@@ -108,6 +108,7 @@ import {
resolveDivisionTestMerchantDivisions
,
normalizeDivisionTestPayload
}
from
'../utils/resolveDivisionTestOrderCode'
import
{
buildWebSocketUrl
}
from
'../utils/buildWebSocketUrl'
import
DivisionTestStepper
from
'./divisionTestDialog/DivisionTestStepper.vue'
import
DivisionTestStep1Pay
from
'./divisionTestDialog/DivisionTestStep1Pay.vue'
import
DivisionTestStep2Allocate
from
'./divisionTestDialog/DivisionTestStep2Allocate.vue'
...
...
@@ -386,8 +387,14 @@ export default {
},
initWs
()
{
if
(
!
this
.
wsUrl
||
this
.
socket
)
return
this
.
socket
=
new
WebSocket
(
'ws://'
+
this
.
wsUrl
)
this
.
socket
.
onmessage
=
this
.
getMessage
const
url
=
buildWebSocketUrl
(
this
.
wsUrl
)
if
(
!
url
)
return
try
{
this
.
socket
=
new
WebSocket
(
url
)
this
.
socket
.
onmessage
=
this
.
getMessage
}
catch
(
err
)
{
console
.
error
(
'[FinancialCalculationDialog] initWs'
,
err
)
}
},
teardownWs
()
{
if
(
this
.
socket
)
{
...
...
src/views/systemConfig/merchant/financialRules/utils/buildWebSocketUrl.js
0 → 100644
View file @
d44d19e
export
function
buildWebSocketUrl
(
rawUrl
,
pageProtocol
)
{
if
(
!
rawUrl
||
typeof
rawUrl
!==
"string"
)
return
""
let
url
=
rawUrl
.
trim
()
const
secure
=
pageProtocol
!=
null
?
pageProtocol
===
"https:"
:
typeof
window
!==
"undefined"
&&
window
.
location
.
protocol
===
"https:"
if
(
/^wss
?
:
\/\/
/i
.
test
(
url
))
{
if
(
secure
&&
/^ws:
\/\/
/i
.
test
(
url
))
{
return
"wss://"
+
url
.
slice
(
5
)
}
return
url
}
const
scheme
=
secure
?
"wss://"
:
"ws://"
return
scheme
+
url
.
replace
(
/^
\/\/
/
,
""
)
}
tests/unit/financialRules/buildWebSocketUrl.spec.js
0 → 100644
View file @
d44d19e
import
{
buildWebSocketUrl
}
from
"@/views/systemConfig/merchant/financialRules/utils/buildWebSocketUrl"
describe
(
"buildWebSocketUrl"
,
()
=>
{
it
(
"uses wss on https pages for host-only url"
,
()
=>
{
expect
(
buildWebSocketUrl
(
"host/path?query"
,
"https:"
)).
toBe
(
"wss://host/path?query"
)
})
it
(
"uses ws on http pages for host-only url"
,
()
=>
{
expect
(
buildWebSocketUrl
(
"host/path"
,
"http:"
)).
toBe
(
"ws://host/path"
)
})
it
(
"upgrades ws:// to wss:// on https pages"
,
()
=>
{
expect
(
buildWebSocketUrl
(
"ws://host/path"
,
"https:"
)).
toBe
(
"wss://host/path"
)
})
it
(
"keeps wss:// on https pages"
,
()
=>
{
expect
(
buildWebSocketUrl
(
"wss://host/path"
,
"https:"
)).
toBe
(
"wss://host/path"
)
})
it
(
"returns empty string for invalid input"
,
()
=>
{
expect
(
buildWebSocketUrl
(
""
,
"https:"
)).
toBe
(
""
)
expect
(
buildWebSocketUrl
(
null
,
"https:"
)).
toBe
(
""
)
})
it
(
"strips leading // before adding scheme"
,
()
=>
{
expect
(
buildWebSocketUrl
(
"//host/path"
,
"http:"
)).
toBe
(
"ws://host/path"
)
})
})
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