19 changed files with 267 additions and 96 deletions
Binary file not shown.
@ -1,31 +0,0 @@ |
|||||||
import request from '@/utils/request' |
|
||||||
|
|
||||||
// 通知设置列表
|
|
||||||
export function noticeLists(params: any) { |
|
||||||
return request.get({ url: '/setting/notice/list', params }) |
|
||||||
} |
|
||||||
|
|
||||||
// 通知设置详情
|
|
||||||
export function noticeDetail(params: any) { |
|
||||||
return request.get({ url: '/setting/notice/detail', params }) |
|
||||||
} |
|
||||||
|
|
||||||
// 通知设置保存
|
|
||||||
export function setNoticeConfig(params: any) { |
|
||||||
return request.post({ url: '/setting/notice/save', params }) |
|
||||||
} |
|
||||||
|
|
||||||
// 短信设置列表
|
|
||||||
export function smsLists() { |
|
||||||
return request.get({ url: '/setting/sms/list' }) |
|
||||||
} |
|
||||||
|
|
||||||
// 短信设置详情
|
|
||||||
export function smsDetail(params: any) { |
|
||||||
return request.get({ url: '/setting/sms/detail', params }) |
|
||||||
} |
|
||||||
|
|
||||||
// 短信设置保存
|
|
||||||
export function setSmsConfig(params: any) { |
|
||||||
return request.post({ url: '/setting/sms/save', params }) |
|
||||||
} |
|
||||||
@ -0,0 +1,5 @@ |
|||||||
|
import request from '@/utils/request' |
||||||
|
|
||||||
|
export function noticeTotal() { |
||||||
|
return request.get({ url: '/notice/total' }) |
||||||
|
} |
||||||
@ -0,0 +1,5 @@ |
|||||||
|
import mitt from "mitt"; |
||||||
|
|
||||||
|
const emitter = mitt(); |
||||||
|
|
||||||
|
export default emitter; |
||||||
@ -0,0 +1,85 @@ |
|||||||
|
//引入使用SockJS
|
||||||
|
import SockJS from "sockjs-client/dist/sockjs" |
||||||
|
import Stomp from "stompjs"; |
||||||
|
import useUserStore from "@/stores/modules/user"; |
||||||
|
import emitter from "./bus"; |
||||||
|
|
||||||
|
//请求地址
|
||||||
|
const baseUrl = "/lan-api/web-terminal"; |
||||||
|
//请求头
|
||||||
|
const header = {}; |
||||||
|
//stomp客户端
|
||||||
|
let stompClient: Stomp.Client; |
||||||
|
//连接状态
|
||||||
|
let connetStatus = false; |
||||||
|
/** |
||||||
|
* 初始化连接 |
||||||
|
*/ |
||||||
|
export const initSocket = () => { |
||||||
|
con(); |
||||||
|
// setInterval(() => {
|
||||||
|
// //根据连接状态
|
||||||
|
// if (connetStatus) {
|
||||||
|
// try {
|
||||||
|
// //发送请求
|
||||||
|
// stompClient.send(
|
||||||
|
// "/xterm/con",
|
||||||
|
// header,
|
||||||
|
// JSON.stringify({ name: "test" })
|
||||||
|
// );
|
||||||
|
// } catch (error) {
|
||||||
|
// con();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }, 10000);
|
||||||
|
}; |
||||||
|
/** |
||||||
|
* 连接 |
||||||
|
*/ |
||||||
|
export const con = () => { |
||||||
|
|
||||||
|
let socket = new SockJS(baseUrl); |
||||||
|
|
||||||
|
stompClient = Stomp.over(socket); |
||||||
|
|
||||||
|
let header = {}; |
||||||
|
stompClient.connect( |
||||||
|
header, |
||||||
|
() => { |
||||||
|
const userStore = useUserStore(); |
||||||
|
console.log('userStore', userStore.userInfo) |
||||||
|
let topic = "/topic"; |
||||||
|
if (userStore.userInfo.roleId === 1 || userStore.userInfo.roleId === 2 || userStore.userInfo.roleId === 3) { |
||||||
|
topic += `/role/${userStore.userInfo.roleId}/${userStore.userInfo.dataDeptId}`
|
||||||
|
} else { |
||||||
|
topic += `/user/${userStore.userInfo.empNo}` |
||||||
|
} |
||||||
|
console.log("topic", topic); |
||||||
|
connetStatus = true; |
||||||
|
// 设置订阅
|
||||||
|
stompClient.subscribe(topic, |
||||||
|
(res: any) => { |
||||||
|
console.log('topic', res); |
||||||
|
emitter.emit("notice"); |
||||||
|
}, |
||||||
|
header |
||||||
|
); |
||||||
|
}, |
||||||
|
(err: any) => { |
||||||
|
console.log("error"); |
||||||
|
console.log(err); |
||||||
|
} |
||||||
|
); |
||||||
|
}; |
||||||
|
|
||||||
|
/** |
||||||
|
* 断开 |
||||||
|
*/ |
||||||
|
export const close = () => { |
||||||
|
if (stompClient) { |
||||||
|
stompClient.disconnect(() => { |
||||||
|
console.log("============connect release============"); |
||||||
|
connetStatus = false; |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue