|
@@ -23,19 +23,22 @@
|
|
|
{{ item.title }}
|
|
|
</div>
|
|
|
</div>
|
|
|
- <router-view class="rightMain" />
|
|
|
+ <router-view :isUp="isUp" class="rightMain" />
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
// import header_local from './components/header.vue';
|
|
|
import { ref } from 'vue';
|
|
|
-import { ElMessage } from 'element-plus';
|
|
|
+import { ElNotification } from 'element-plus';
|
|
|
import { useRoute, useRouter } from 'vue-router';
|
|
|
+import config from '../../config/index';
|
|
|
|
|
|
const Router = useRouter();
|
|
|
const Route = useRoute();
|
|
|
const selectMenu = ref(Route.fullPath);
|
|
|
+const isUp = ref(0);
|
|
|
+let eventSource = null;
|
|
|
|
|
|
const menu = JSON.parse(localStorage.getItem('menu') || '[]');
|
|
|
|
|
@@ -64,32 +67,54 @@ const selectMenuFunc = item => {
|
|
|
* 3 如果用户还没有作出选择,返回值为default;
|
|
|
*/
|
|
|
function notificationFunc() {
|
|
|
- if (!Notification) return;
|
|
|
- if (Notification.permission == 'denied') return;
|
|
|
- if (Notification.permission === 'default') Notification.requestPermission();
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ if (!Notification) return resolve(false);
|
|
|
+ if (Notification.permission === 'granted') {
|
|
|
+ resolve(true);
|
|
|
+ } else {
|
|
|
+ Notification.requestPermission().then(() => {
|
|
|
+ resolve(true);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+function sse() {
|
|
|
+ eventSource = new EventSource(
|
|
|
+ config.base.videoProcessing +
|
|
|
+ '/user/sse?token=' +
|
|
|
+ localStorage.getItem('token')
|
|
|
+ );
|
|
|
+ eventSource.addEventListener('message', event => {
|
|
|
+ // 处理来自服务器的消息
|
|
|
+ const data = JSON.parse(event.data);
|
|
|
+ isUp.value += 1;
|
|
|
+ window.processing_getList && window.processing_getList();
|
|
|
+ if (Notification) {
|
|
|
+ new Notification('提示', {
|
|
|
+ body: data.msg,
|
|
|
+ icon: '' // 可选的图标路径
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ ElNotification({
|
|
|
+ title: '提示',
|
|
|
+ message: data.msg,
|
|
|
+ duration: 0
|
|
|
+ });
|
|
|
+ });
|
|
|
|
|
|
- const permission = {
|
|
|
- denied: '拒绝授权',
|
|
|
- granted: '同意授权',
|
|
|
- default: '不明授权'
|
|
|
+ eventSource.onerror = error => {
|
|
|
+ // 处理错误
|
|
|
+ console.error(error);
|
|
|
+ eventSource.close();
|
|
|
+ // sse();
|
|
|
};
|
|
|
-
|
|
|
- console.log(permission[Notification.permission]);
|
|
|
-
|
|
|
- // if (Notification.permission === 'granted') {
|
|
|
- // // 如果用户允许系统提醒,则创建一个通知
|
|
|
- // var notification = new Notification('这是一个系统提醒', {
|
|
|
- // body: '这是提醒的正文内容',
|
|
|
- // icon: 'path/to/icon.png' // 可选的图标路径
|
|
|
- // });
|
|
|
-
|
|
|
- // // 可以在通知被点击时执行一些操作
|
|
|
- // notification.onclick = function () {
|
|
|
- // console.log('用户点击了系统提醒');
|
|
|
- // };
|
|
|
- // }
|
|
|
}
|
|
|
-notificationFunc();
|
|
|
+
|
|
|
+notificationFunc().then(isTrue => {
|
|
|
+ sse();
|
|
|
+});
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|