| | |
| | | <template> |
| | | <div> |
| | | <template> |
| | | <div |
| | | v-loading.fullscreen.lock="startActionLoading" |
| | | element-loading-text="正在启动实例,请稍候..." |
| | | > |
| | | <div class="page-header"> |
| | | <div class="header-left"> |
| | | <h2> |
| | | <el-icon :size="24"><Cpu /></el-icon> |
| | | S7 PLC 仿真器实例 |
| | | S7 PLC 模拟器实例 |
| | | </h2> |
| | | <p class="text-muted">管理和监控 S7 PLC 仿真器实例</p> |
| | | <p class="text-muted">管理和监控 S7 PLC 模拟器实例</p> |
| | | </div> |
| | | <div class="header-right"> |
| | | <div class="stats"> |
| | |
| | | </template> |
| | | |
| | | <script setup lang="ts"> |
| | | import { onMounted, onUnmounted } from 'vue' |
| | | import { onMounted, onUnmounted, ref } from 'vue' |
| | | import { storeToRefs } from 'pinia' |
| | | import { useInstancesStore } from '../stores/instances' |
| | | import { ElMessage, ElMessageBox } from 'element-plus' |
| | |
| | | |
| | | const store = useInstancesStore() |
| | | const { instances, loading, runningCount, stoppedCount, errorCount } = storeToRefs(store) |
| | | const startActionLoading = ref(false) |
| | | |
| | | onMounted(() => { |
| | | store.loadInstances() |
| | |
| | | store.stopAutoRefresh() |
| | | }) |
| | | |
| | | function handleStart(id: string) { |
| | | ElMessageBox.confirm(`确定要启动实例 "${id}" 吗?`, '确认', { |
| | | async function handleStart(id: string) { |
| | | try { |
| | | await ElMessageBox.confirm(`确定要启动实例 "${id}" 吗?`, '确认', { |
| | | confirmButtonText: '确定', |
| | | cancelButtonText: '取消', |
| | | type: 'info' |
| | | }).then(() => { |
| | | store.startInstance(id).then(() => { |
| | | }) |
| | | |
| | | startActionLoading.value = true |
| | | await store.startInstance(id) |
| | | ElMessage.success('启动命令已发送') |
| | | }).catch(() => { |
| | | } catch (err) { |
| | | if (err !== 'cancel') { |
| | | ElMessage.error('启动失败,请查看控制台') |
| | | }) |
| | | }) |
| | | } |
| | | } finally { |
| | | startActionLoading.value = false |
| | | } |
| | | } |
| | | |
| | | function handleStop(id: string) { |
| | | ElMessageBox.confirm(`确定要停止实例 "${id}" 吗?`, '确认', { |
| | | ElMessageBox.confirm(`确定要停止实例 "${id}" 吗?`, '确认', { |
| | | confirmButtonText: '确定', |
| | | cancelButtonText: '取消', |
| | | type: 'warning' |
| | |
| | | } |
| | | |
| | | function handleDelete(id: string) { |
| | | ElMessageBox.confirm(`确定要删除实例 "${id}" 吗?此操作不可撤销!`, '警告', { |
| | | ElMessageBox.confirm(`确定要删除实例 "${id}" 吗?此操作不可撤销!`, '警告', { |
| | | confirmButtonText: '确定', |
| | | cancelButtonText: '取消', |
| | | type: 'error' |
| | |
| | | return map[status] || '' |
| | | } |
| | | |
| | | function getStatusTagType(status: string): 'success' | 'info' | 'warning' | 'danger' | 'info' { |
| | | function getStatusTagType(status: string): 'success' | 'info' | 'warning' | 'danger' { |
| | | const map: Record<string, 'success' | 'info' | 'warning' | 'danger'> = { |
| | | 'Stopped': 'info', |
| | | 'Starting': 'info', |
| | |
| | | margin-top: 8px; |
| | | } |
| | | </style> |
| | | |
| | | |