5 changed files with 131 additions and 36 deletions
-
40src/App.vue
-
11src/components/MyModal.vue
-
46src/components/Operator.vue
-
29src/store/modules/websocket.js
-
29src/utils/MyModal.js
@ -1,7 +1,41 @@ |
|||
<script setup></script> |
|||
|
|||
<template> |
|||
<router-view></router-view> |
|||
<my-modal type="info" icon="warning" |
|||
v-model:visible="deviceAlert.visible" |
|||
:content="deviceAlert.content" |
|||
@ok="actionDeviceAlertOk" |
|||
></my-modal> |
|||
</template> |
|||
<script setup> |
|||
import { useWebSocketStore } from '@/store' |
|||
import { onMounted, ref } from 'vue'; |
|||
/** @var {webSocketStore} */ |
|||
const webSocketStore = useWebSocketStore(); |
|||
/** @var {Object} */ |
|||
const deviceAlert = ref({ |
|||
visible: false, |
|||
content: '', |
|||
key : null, |
|||
}); |
|||
// on mounted |
|||
onMounted(mounted); |
|||
|
|||
// on mounted |
|||
function mounted() { |
|||
webSocketStore.registerEventHandler('AlertEvent', handleAlertEvent); |
|||
} |
|||
|
|||
// handle alert event |
|||
async function handleAlertEvent(data) { |
|||
deviceAlert.value.visible = true; |
|||
deviceAlert.value.content = data.displayInfo; |
|||
deviceAlert.value.key = data.alertContext; |
|||
await webSocketStore.call('AlertEventFrontEndConfirm', {alertContext:data.alertContext}); |
|||
} |
|||
|
|||
// action device alert ok |
|||
async function actionDeviceAlertOk() { |
|||
await webSocketStore.call('AlertEventUsrConfirm', {alertContext:deviceAlert.value.key}); |
|||
} |
|||
|
|||
<style scoped></style> |
|||
</script> |
@ -0,0 +1,29 @@ |
|||
import { createApp, h } from 'vue'; |
|||
import MyModalComponent from 'cpns/MyModal.vue'; |
|||
export default class MyModal { |
|||
// show error message
|
|||
static error( message ) { |
|||
return new Promise( resolve => { |
|||
const modalContainer = document.createElement('div'); |
|||
document.body.appendChild(modalContainer); |
|||
const modalApp = createApp({ |
|||
render() { |
|||
return h(MyModalComponent, { |
|||
ref : 'modal', |
|||
icon : 'warning', |
|||
type : 'info', |
|||
content : message, |
|||
onOk : () => { |
|||
modalApp.unmount(); |
|||
document.body.removeChild(modalContainer); |
|||
resolve(); |
|||
} |
|||
}); |
|||
}, |
|||
}); |
|||
|
|||
const vm = modalApp.mount(modalContainer); |
|||
vm.$refs.modal.show(); |
|||
}); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue