Commit d301e904 authored by 以墨为白's avatar 以墨为白 🎧

sse支持

parent 93b74234
......@@ -708,7 +708,7 @@ let post_machineWriting = (url, data, headers = {}) => {
body: typeof data == "object" ? JSON.stringify(data) : data,
headers:
{
'apiKey':'7838fab88cde479d84d710d3d2453276',
'apiKey': '7838fab88cde479d84d710d3d2453276',
'Content-Type': 'application/json'
}
......@@ -731,6 +731,58 @@ let post_machineWriting = (url, data, headers = {}) => {
.catch(err => reject(err));
})
}
let httpSSERequest = (url, success, error) => {
if (typeof (EventSource) !== "undefined") {
var eventSource = new EventSource(url);
eventSource.onmessage = function (event) {
success(event.data);
}
eventSource.addEventListener('error', function (event) {
error("错误:" + event);
});
eventSource.addEventListener('open', function (event) {
error("建立连接:" + event);
});
}
else {
error("抱歉,您的浏览器不支持 server-sent 事件 ...");
}
}
/**
* oss文件上传
* @param {*} url
* @param {*} file
*/
let uploadOSS = (url, file) => {
new Promise((resolve, reject) => {
fetch(url).then(res => {
if (res.status == 200) {
return res.json();
} else {
console.log(res.statusText);
reject(HTTP_STATUS);
}
}).then(res => {
if (res.code == 9000) {
return fetch(res.data, {
method: "put",
body: file
});
} else {
return Promise.reject({ err: res.message });
}
}).then(res => {
if (res.status == 200) {
resolve();
} else {
console.log(res.statusText);
reject(HTTP_STATUS);
}
}).catch(err => {
reject({ err: err });
})
})
}
export {
......@@ -771,5 +823,7 @@ export {
addParamNew,
arr_img_format,
fileUploadProgress,
post_machineWriting
post_machineWriting,
httpSSERequest,
uploadOSS
}
\ No newline at end of file
......@@ -9,8 +9,8 @@
</div>
<div class="button-list-right">
<div v-for="(item, index) in modules.rightModule"
:class="['module-info', isSelected - 3 == index ? 'selectedModule' : '']" @click="choiceModule(index + 3)"
v-text="item.name">
:class="['module-info', isSelected - 3 == index ? 'selectedModule' : '']"
@click="choiceModule(index + 3)" v-text="item.name">
</div>
</div>
<h1><span v-text="system_name"></span></h1>
......@@ -77,7 +77,7 @@
import "../assets/css/home.css";
// import jh_bg from "../assets/img/main/logo-bg.png";
// import jh from "/static/img/main/logo.png";
import { endLoading, get, post } from "../util/http_util";
import { endLoading, get, post, httpSSERequest } from "../util/http_util";
import { queryDictItem } from '../api/dictitem';
import Push from 'push.js'
import dayjs from 'dayjs';
......@@ -118,9 +118,9 @@ export default {
],
},
isSelected: 0,
myDate:{
day:null,
week:null
myDate: {
day: null,
week: null
},
system_name: SYSTEM_NAME
};
......@@ -269,8 +269,20 @@ export default {
//获取时间
this.myDate.day = dayjs().format('YYYY年MM月DD日');
const weekList = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];
const weekList = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
this.myDate.week = weekList[dayjs().get('day')]
// httpSSERequest("http://localhost:8081/api_ws/stream-sse", (data) => {
// console.log(data)
// }, (err) => {
// console.log(err)
// });
httpSSERequest("api_ws/stream-sse", (data) => {
console.log(data)
}, (err) => {
console.log(err)
});
},
computed: {
userInfo() {
......@@ -577,7 +589,8 @@ export default {
.el-dropdown-link {
cursor: pointer;
color: white;
.el-icon-more.setting_button{
.el-icon-more.setting_button {
font-size: 25px;
}
}
......@@ -864,4 +877,5 @@ export default {
transition: all 0.4s ease;
cursor: pointer;
}
}</style>
\ No newline at end of file
}
</style>
\ No newline at end of file
......@@ -106,6 +106,7 @@ module.exports = {
]
},
devServer: {
compress: false,//SSE 依赖的是换行符。gzip 会破坏这种依赖。因此需要在webpack-dev-server 配置里把 gzip 关掉devserver{compress:false}
port: 8088,
hot: true,
static: './',
......@@ -120,6 +121,12 @@ 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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment