<template>
  <d2-container><template #header><el-form :inline="true" size="mini"><el-form-item :label="$t(key('server_name'))"><el-input v-model="search.server_name" clearable style="width:200px" /></el-form-item><el-form-item :label="$t(key('device_name'))"><el-input v-model="search.device_name" clearable style="width:200px" /></el-form-item><el-form-item :label="$t(key('command'))"><el-select v-model="search.command" clearable style="width:180px"><el-option v-for="item in commandOptions" :key="item.value" :label="$t(item.label)" :value="item.value" /></el-select></el-form-item><el-form-item><el-button type="primary" icon="el-icon-search" @click="onSearch">{{ $t(key('query')) }}</el-button><el-button icon="el-icon-refresh" @click="onReset">{{ $t(key('reset')) }}</el-button></el-form-item></el-form></template><page-table :columns="columns" :data="tableData" :loading="loading" :pagination="pagination" auto-height @page-change="onPageChange"><template #col-command="{ row }">{{ commandText(row.command) }}</template><template #col-success="{ row }"><el-tag :type="row.success === 't' ? 'success' : 'danger'">{{ row.success === 't' ? $t(key('success')) : $t(key('danger')) }}</el-tag></template></page-table></d2-container>
</template><script>
import { useTableColumns } from '@/composables/useTableColumns'
import { i18nMixin } from '@/composables/useI18n'
import PageTable from '@/components/page-table'
import { getExecLog } from '@/api/scada-manage/edge-manager'
export default { name: 'scada-edgeserver-log', components: { PageTable }, mixins: [i18nMixin('page.scada_manage.basic_configuration.edgeserver_log')], data () { return { loading: false, tableData: [], search: { server_name: '', device_name: '', command: '' }, pagination: { current: 1, size: 10, total: 0 }, commandOptions: ['server_restart', 'server_close', 'device_stop', 'device_continue', 'stop_device', 'warning_device'].map(v => ({ label: this.key(v), value: v })), columns: [] } }, created () { this.columns = useTableColumns([{ prop: 'server_name', label: this.key('server_name'), minWidth: 160 }, { prop: 'device_name', label: this.key('device_name'), minWidth: 160 }, { prop: 'command', label: this.key('command'), minWidth: 160, slot: 'command' }, { prop: 'success', label: this.key('status'), width: 100, slot: 'success' }, { prop: 'create_date', label: this.key('create_date'), minWidth: 160 }], { selectionWidth: 0 }); this.fetchData() }, methods: { commandText (command) { const item = this.commandOptions.find(i => i.value === command); return item ? this.$t(item.label) : command }, async fetchData () { this.loading = true; try { const res = await getExecLog({ ...this.search, page_no: this.pagination.current, page_size: this.pagination.size }); this.tableData = Array.isArray(res) ? res : (res.data || []); this.pagination.total = Array.isArray(res) ? res.length : (res.total || res.count || 0) } finally { this.loading = false } }, onSearch () { this.pagination.current = 1; this.fetchData() }, onReset () { this.search = { server_name: '', device_name: '', command: '' }; this.onSearch() }, onPageChange (p) { this.pagination.current = p.current; this.pagination.size = p.size; this.fetchData() } } }
</script>
