Skip to content

Commit

Permalink
一条龙消息
Browse files Browse the repository at this point in the history
  • Loading branch information
tignioj committed Oct 2, 2024
1 parent cb4c14a commit 2e574a3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/page/OneDragonPage.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<script setup>
import {computed, inject, ref} from 'vue';
import {oneDragonRunURL} from "@/api.js";
import {computed, inject, onMounted, ref} from 'vue';
import {oneDragonRunURL, oneDragonStopURL, socketURL} from "@/api.js";
import {store} from "@/store.js";
import {
SOCKET_EVENT_ONE_DRAGON_END,
SOCKET_EVENT_ONE_DRAGON_EXCEPTION,
SOCKET_EVENT_ONE_DRAGON_START,
SOCKET_EVENT_ONE_DRAGON_UPDATE,
useWebSocket
} from "@/utils/websocket_listener_utils.js";
function info(msg) {
Expand All @@ -13,9 +20,9 @@ function errorMsg(msg) {
const todoList = ref([
{ name: '清单', value: 'todo' , checked: false },
{ name: '战斗委托', value: 'dailyMission' , checked: false},
{ name: '地脉', value: 'leyLine' , checked: false},
{ name: '领取奖励', value: 'claimReward' , checked: false}
{ name: '战斗委托', value: 'dailyMission' , checked: true},
{ name: '地脉', value: 'leyLine' , checked: true},
{ name: '领取奖励', value: 'claimReward' , checked: true}
]);
const dragItem = ref(null);
Expand Down Expand Up @@ -72,8 +79,23 @@ function runAll() {
});
}
function stop() {
fetch(oneDragonStopURL).then(response=> {
if (!response.ok) throw new Error('Network response was not ok ' + response.statusText);
return response.json(); // 解析响应为 JSON
}).then(data => {
if (data.success === true) { info(data.message)
} else { errorMsg(data.message) }
}).catch(error => { console.error('Error:', error)}); // 处理错误 errorMsg(error)
}
const { socket} = useWebSocket(socketURL, {});
onMounted(()=> {
socket.value.on(SOCKET_EVENT_ONE_DRAGON_START, (data)=> { info(data) })
socket.value.on(SOCKET_EVENT_ONE_DRAGON_END, (data)=> { info(data) })
socket.value.on(SOCKET_EVENT_ONE_DRAGON_UPDATE, (data)=> { info(data) })
socket.value.on(SOCKET_EVENT_ONE_DRAGON_EXCEPTION, (data)=> { errorMsg(data) })
})
</script>

<template>
Expand Down
7 changes: 7 additions & 0 deletions src/utils/websocket_listener_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export const SOCKET_EVENT_LEYLINE_OUTCROP_UPDATE = 'socket_event_leyline_outcrop
export const SOCKET_EVENT_LEYLINE_OUTCROP_END = 'socket_event_leyline_outcrop_end'
export const SOCKET_EVENT_LEYLINE_OUTCROP_EXCEPTION = 'socket_event_leyline_outcrop_exception'

// 一条龙
export const SOCKET_EVENT_ONE_DRAGON_START = 'socket_event_one_dragon_start'
export const SOCKET_EVENT_ONE_DRAGON_UPDATE = 'socket_event_one_dragon_update'
export const SOCKET_EVENT_ONE_DRAGON_END = 'socket_event_one_dragon_end'
export const SOCKET_EVENT_ONE_DRAGON_EXCEPTION = 'socket_event_one_dragon_exception'


export function useWebSocket(socketURL, {
onKeyEvent = null,
}) {
Expand Down

0 comments on commit 2e574a3

Please sign in to comment.