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
5034cbdb
Commit
5034cbdb
authored
Dec 21, 2023
by
以墨为白
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
fe07b0eb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
47 deletions
+43
-47
src/util/http_util.js
src/util/http_util.js
+40
-38
src/view/home.vue
src/view/home.vue
+2
-2
webpack.config.js
webpack.config.js
+1
-7
No files found.
src/util/http_util.js
View file @
5034cbdb
...
...
@@ -852,44 +852,46 @@ let httpSSERequest = (url, success, error) => {
*/
let
fetchEventSource
=
(
url
,
data
,
options
=
{})
=>
{
// 发送 POST 请求
fetch
(
url
,
{
method
:
"
get
"
,
// body: typeof data == "object" ? JSON.stringify(data) : data,
timeout
:
0
,
dataType
:
"
text/event-stream
"
,
headers
:
new
Headers
(
addHeaders
(
headers
))
}).
then
(
response
=>
{
// 检查响应是否成功
if
(
!
response
.
ok
)
{
throw
new
Error
(
'
Network response was not ok
'
);
}
// 返回一个可读流
options
.
onopen
&&
options
.
onopen
();
return
response
.
body
;
}).
then
(
body
=>
{
// disableLoading();
const
reader
=
body
.
getReader
();
// 读取数据流
const
push
=
()
=>
{
return
reader
.
read
().
then
(({
done
,
value
})
=>
{
// 检查是否读取完毕
if
(
done
)
{
console
.
log
(
'
已传输完毕
'
);
options
.
onclose
&&
options
.
onclose
();
return
;
}
// 处理每个数据块
// console.log('收到的数据:', value);
options
.
onmessage
&&
options
.
onmessage
(
new
TextDecoder
().
decode
(
value
));
// 继续读取下一个数据块
return
push
();
});
}
// 开始读取数据流
return
push
();
}).
catch
(
error
=>
{
console
.
error
(
'
Fetch error:
'
,
error
);
options
.
error
&&
options
.
error
(
error
);
return
new
Promise
((
resolve
,
reject
)
=>
{
fetch
(
url
,
{
method
:
"
get
"
,
// body: typeof data == "object" ? JSON.stringify(data) : data,
timeout
:
0
,
dataType
:
"
text/event-stream
"
,
headers
:
new
Headers
(
addHeaders
({}))
}).
then
(
response
=>
{
// 检查响应是否成功
if
(
!
response
.
ok
)
{
throw
new
Error
(
'
Network response was not ok
'
);
}
// 返回一个可读流
options
.
onopen
&&
options
.
onopen
();
return
response
.
body
;
}).
then
(
body
=>
{
// disableLoading();
const
reader
=
body
.
getReader
();
// 读取数据流
const
push
=
()
=>
{
return
reader
.
read
().
then
(({
done
,
value
})
=>
{
// 检查是否读取完毕
if
(
done
)
{
console
.
log
(
'
已传输完毕
'
);
options
.
onclose
&&
options
.
onclose
();
return
;
}
// 处理每个数据块
// console.log('收到的数据:', value);
options
.
onmessage
&&
options
.
onmessage
(
new
TextDecoder
().
decode
(
value
));
// 继续读取下一个数据块
return
push
();
});
}
// 开始读取数据流
return
push
();
}).
catch
(
error
=>
{
return
fetchEventSource
(
url
,
data
,
options
);
options
.
error
&&
options
.
error
(
error
);
});
});
}
//#endregion
...
...
src/view/home.vue
View file @
5034cbdb
...
...
@@ -272,7 +272,7 @@ export default {
const
weekList
=
[
'
星期日
'
,
'
星期一
'
,
'
星期二
'
,
'
星期三
'
,
'
星期四
'
,
'
星期五
'
,
'
星期六
'
];
this
.
myDate
.
week
=
weekList
[
dayjs
().
get
(
'
day
'
)]
fetchEventSource
(
"
api
_ws/stream-sse
"
,
{},
{
fetchEventSource
(
"
api
/api_ws/getMsg1
"
,
{},
{
onopen
:
()
=>
{
console
.
log
(
"
打开
"
);
},
...
...
@@ -285,7 +285,7 @@ export default {
}
});
// httpSSERequest("api_ws/stream-sse", (data) => {
// httpSSERequest("api
/api
_ws/stream-sse", (data) => {
// console.log(data)
// }, (err) => {
// console.log(err)
...
...
webpack.config.js
View file @
5034cbdb
...
...
@@ -113,7 +113,7 @@ module.exports = {
//后台代理
proxy
:
{
'
/api/
'
:
{
target
:
'
http://
192.168.168.213
:8081
'
,
target
:
'
http://
localhost
:8081
'
,
ws
:
true
,
secure
:
false
,
changeOrigin
:
true
,
...
...
@@ -121,12 +121,6 @@ module.exports = {
'
^/api/
'
:
'
/
'
}
},
'
/api_ws/**
'
:
{
target
:
'
http://localhost:8081
'
,
ws
:
true
,
secure
:
false
,
changeOrigin
:
true
,
},
'
/websocket/**
'
:
{
target
:
'
ws://192.168.168.213:8081
'
,
ws
:
true
,
...
...
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