Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
X
xxx_phase2_web
Project overview
Project overview
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
夏敏伟
xxx_phase2_web
Commits
dd1b105b
Commit
dd1b105b
authored
Dec 21, 2023
by
以墨为白
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sse
parent
5034cbdb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
6 deletions
+17
-6
src/util/http_util.js
src/util/http_util.js
+2
-3
src/view/home.vue
src/view/home.vue
+15
-3
No files found.
src/util/http_util.js
View file @
dd1b105b
...
...
@@ -862,7 +862,7 @@ let fetchEventSource = (url, data, options = {}) => {
}).
then
(
response
=>
{
// 检查响应是否成功
if
(
!
response
.
ok
)
{
throw
new
Error
(
'
Network response was not ok
'
);
reject
(
'
Network response was not ok
'
);
}
// 返回一个可读流
options
.
onopen
&&
options
.
onopen
();
...
...
@@ -881,7 +881,7 @@ let fetchEventSource = (url, data, options = {}) => {
}
// 处理每个数据块
// console.log('收到的数据:', value);
options
.
onmessage
&&
options
.
onmessage
(
new
TextDecoder
().
decode
(
value
));
options
.
onmessage
&&
options
.
onmessage
(
new
TextDecoder
().
decode
(
value
)
.
replace
(
/
[\t\r\f\n\s]
*/g
,
''
)
);
// 继续读取下一个数据块
return
push
();
});
...
...
@@ -889,7 +889,6 @@ let fetchEventSource = (url, data, options = {}) => {
// 开始读取数据流
return
push
();
}).
catch
(
error
=>
{
return
fetchEventSource
(
url
,
data
,
options
);
options
.
error
&&
options
.
error
(
error
);
});
});
...
...
src/view/home.vue
View file @
dd1b105b
...
...
@@ -272,7 +272,7 @@ export default {
const
weekList
=
[
'
星期日
'
,
'
星期一
'
,
'
星期二
'
,
'
星期三
'
,
'
星期四
'
,
'
星期五
'
,
'
星期六
'
];
this
.
myDate
.
week
=
weekList
[
dayjs
().
get
(
'
day
'
)]
fetchEventSource
(
"
api/api_ws/
getMsg1
"
,
{},
{
fetchEventSource
(
"
api/api_ws/
connect
"
,
{},
{
onopen
:
()
=>
{
console
.
log
(
"
打开
"
);
},
...
...
@@ -280,12 +280,24 @@ export default {
console
.
log
(
"
关闭
"
);
},
onmessage
:
(
value
)
=>
{
let
msg
=
value
.
split
(
'
\n
'
);
console
.
log
(
value
);
value
=
value
.
replace
(
"
data:
"
,
""
);
if
(
!
value
)
{
return
;
}
this
.
$notify
({
title
:
'
成功
'
,
message
:
value
,
type
:
'
success
'
});
}
}).
then
(
res
=>
{
}).
catch
(
err
=>
{
});
// httpSSERequest("api/api_ws/
stream-sse
", (data) => {
// httpSSERequest("api/api_ws/
connect
", (data) => {
// console.log(data)
// }, (err) => {
// console.log(err)
...
...
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