| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475 |
- <template>
- <div class="panel-manage">
- <a-row :gutter="[24, 24]">
- <!-- 概览 -->
- <a-col :span="24">
- <a-card>
- <div class="overview-bar">
- <div class="overview-item">
- <span class="overview-label">已注册线架</span>
- <a-tag color="blue">{{ panels.length }} 台</a-tag>
- </div>
- <div class="overview-item">
- <span class="overview-label">在线</span>
- <a-tag color="green">{{ onlineCount }} 台</a-tag>
- </div>
- <div class="overview-item">
- <span class="overview-label">缺失待接管</span>
- <a-tag color="orange">{{ missingCount }} 台</a-tag>
- </div>
- <div class="overview-item">
- <span class="overview-label">离线</span>
- <a-tag color="default">{{ offlineCount }} 台</a-tag>
- </div>
- <div class="overview-item">
- <span class="overview-label">地址段</span>
- <a-tag color="purple">{{ addressRange.start }} - {{ addressRange.end }}</a-tag>
- <a-tooltip title="地址段在「系统配置 → DTU配置」中修改">
- <question-circle-outlined class="tip-icon" />
- </a-tooltip>
- </div>
- <div class="overview-item">
- <span class="overview-label">最近更新</span>
- <span class="overview-value">{{ lastUpdate || '--' }}</span>
- </div>
- <div class="overview-item" style="margin-left: auto">
- <a-space>
- <a-button size="small" :loading="loading" @click="refreshData">
- <reload-outlined /> 刷新
- </a-button>
- <a-button size="small" @click="openConfigAddress">
- <setting-outlined /> 配置地址
- </a-button>
- <a-button size="small" type="primary" :loading="scanning" @click="scanNewPanels">
- <search-outlined /> 扫描新线架
- </a-button>
- </a-space>
- </div>
- </div>
- <a-alert
- type="info"
- show-icon
- style="margin-top: 12px"
- message="线架注册说明"
- description="DTU 按地址段定时查询:已绑定地址带线架 UID 查询(同时作为保活),未绑定地址用 UID 全 0 探测;线架不会自动分配地址,新线架地址需现场刷配置卡设置(点「配置地址」)。换架时新线架自动接管原地址并继承全部端口映射数据,无需重新匹配。删除绑定仅解除注册;线架若仍在总线上,下一轮扫描会重新绑定。"
- />
- </a-card>
- </a-col>
- <!-- 线架列表 -->
- <a-col :span="24">
- <a-card title="已注册线架">
- <a-table
- :data-source="panels"
- :columns="columns"
- row-key="address"
- size="middle"
- :loading="loading"
- :pagination="{ pageSize: 10, showSizeChanger: false }"
- >
- <template #bodyCell="{ column, record }">
- <template v-if="column.key === 'address'">
- <a-tag>{{ record.address }}</a-tag>
- </template>
- <template v-else-if="column.key === 'uid'">
- <span class="mono">{{ formatUid(record.uid) }}</span>
- </template>
- <template v-else-if="column.key === 'status'">
- <a-tag :color="statusColor(record.status)">{{ statusLabel(record.status) }}</a-tag>
- </template>
- <template v-else-if="column.key === 'last_seen'">
- {{ formatTime(record.last_seen) }}
- </template>
- <template v-else-if="column.key === 'ports'">
- <a-space>
- <span>{{ record.connected_count }}/{{ record.port_count }}</span>
- <a-tag v-if="record.alarm_count > 0" color="red">告警 {{ record.alarm_count }}</a-tag>
- </a-space>
- </template>
- <template v-else-if="column.key === 'action'">
- <a-space :size="0">
- <a-popconfirm
- title="清空该线架的全部端口映射?"
- :description="`地址 ${record.address}:删除平台保存的端口↔卡号映射;线架在线时会同时把硬件 24 个端口全部清成无卡。不影响线架注册绑定。`"
- ok-text="清空"
- cancel-text="取消"
- @confirm="clearMappings(record)"
- >
- <a-button type="link" size="small">清空映射</a-button>
- </a-popconfirm>
- <a-popconfirm
- title="确定解除该线架的注册绑定?"
- :description="`地址 ${record.address}(UID ${formatUid(record.uid)})。若线架仍在总线上,下一轮扫描会自动重新绑定。`"
- @confirm="unbindPanel(record)"
- >
- <a-button type="link" size="small" danger>删除</a-button>
- </a-popconfirm>
- </a-space>
- </template>
- </template>
- </a-table>
- </a-card>
- </a-col>
- </a-row>
- <!-- 配置地址(刷配置卡设置线架地址) -->
- <a-modal
- v-model:open="configModalOpen"
- title="配置线架地址"
- :footer="null"
- width="640px"
- @cancel="closeConfigAddress"
- >
- <a-alert
- type="warning"
- show-icon
- style="margin-bottom: 16px"
- message="一次只能配置一台线架"
- description="发送指令后,地址段轮询会暂停,线架进入「配置地址状态」;请把配置卡放到目标线架的天线上完成地址设置,线架回复新地址后自动恢复轮询并尝试注册。"
- />
- <a-steps
- size="small"
- direction="vertical"
- :current="configStep"
- style="margin-bottom: 16px"
- >
- <a-step title="发送配置地址指令" description="点击下方按钮,DTU 会广播让线架进入配置地址状态" />
- <a-step title="刷配置卡" description="把配置卡放到目标线架的天线上,线架读取后回复天线号与新地址" />
- <a-step title="自动注册" description="DTU 收到应答后探测新地址并完成绑定(换架自动接管原映射)" />
- </a-steps>
- <a-descriptions bordered size="small" :column="1" style="margin-bottom: 16px">
- <a-descriptions-item label="状态">
- <a-tag :color="configStatusColor">{{ configStatusText }}</a-tag>
- <span v-if="configStatus.timeout" style="margin-left: 8px; color: #999">
- 超时 {{ configStatus.timeout }}s
- </span>
- </a-descriptions-item>
- <a-descriptions-item label="读取天线">
- {{ configStatus.antenna != null ? configStatus.antenna : '--' }}
- </a-descriptions-item>
- <a-descriptions-item label="新地址">
- {{ configStatus.address != null ? configStatus.address : '--' }}
- </a-descriptions-item>
- <a-descriptions-item v-if="configStatus.error" label="错误">
- <span style="color: #cf1322">{{ configStatus.error }}</span>
- </a-descriptions-item>
- <a-descriptions-item v-if="configStatus.raw" label="原始应答">
- <span class="mono">{{ configStatus.raw }}</span>
- </a-descriptions-item>
- </a-descriptions>
- <a-space>
- <a-button
- type="primary"
- :loading="configStarting || configRunning"
- :disabled="configRunning"
- @click="startConfigAddress"
- >
- {{ configRunning ? '等待刷配置卡...' : '开始配置地址' }}
- </a-button>
- <a-button @click="closeConfigAddress">关闭</a-button>
- </a-space>
- </a-modal>
- </div>
- </template>
- <script setup>
- import { ref, computed, onMounted, onUnmounted } from 'vue'
- import { message } from 'ant-design-vue'
- import {
- ReloadOutlined,
- SearchOutlined,
- QuestionCircleOutlined,
- SettingOutlined
- } from '@ant-design/icons-vue'
- import apiService from '../api/apiService'
- const loading = ref(false)
- const scanning = ref(false)
- const panels = ref([])
- const addressRange = ref({ start: 1, end: 50 })
- const lastUpdate = ref('')
- let pollTimer = null
- // 配置地址(刷配置卡)
- const configModalOpen = ref(false)
- const configStarting = ref(false)
- const configRunning = ref(false)
- const configStatus = ref({
- running: false,
- started_at: null,
- finished_at: null,
- timeout: null,
- antenna: null,
- address: null,
- raw: '',
- error: null
- })
- let configPollTimer = null
- const columns = [
- { title: '地址', key: 'address', width: 80 },
- { title: '面板ID', dataIndex: 'panel_id', key: 'panel_id', width: 200 },
- { title: '线架 UID', key: 'uid', width: 260 },
- { title: '状态', key: 'status', width: 130 },
- { title: '最后响应', key: 'last_seen', width: 180 },
- { title: '端口(已连/总)', key: 'ports', width: 160 },
- { title: '操作', key: 'action', width: 180 }
- ]
- const onlineCount = computed(() => panels.value.filter(p => p.status === 'online').length)
- const missingCount = computed(() => panels.value.filter(p => p.status === 'missing').length)
- const offlineCount = computed(() => panels.value.filter(p => p.status === 'offline').length)
- const configStep = computed(() => {
- const st = configStatus.value
- if (st.address != null) return 3
- if (st.running) return 1
- return 0
- })
- const configStatusText = computed(() => {
- const st = configStatus.value
- if (st.running) return '等待刷配置卡'
- if (st.address != null) return '配置成功'
- if (st.error) return '失败'
- if (st.finished_at) return '已结束'
- return '未开始'
- })
- const configStatusColor = computed(() => {
- const st = configStatus.value
- if (st.running) return 'processing'
- if (st.address != null) return 'green'
- if (st.error) return 'red'
- return 'default'
- })
- function statusLabel(status) {
- return { online: '在线', missing: '缺失待接管', offline: '离线' }[status] || status
- }
- function statusColor(status) {
- return { online: 'green', missing: 'orange', offline: 'default' }[status] || 'default'
- }
- function formatUid(uid) {
- if (!uid) return '--'
- return String(uid).toUpperCase().replace(/[:\s-]/g, '')
- }
- function formatTime(ts) {
- if (!ts) return '--'
- return new Date(ts * 1000).toLocaleString()
- }
- async function loadPanels() {
- try {
- const res = await apiService.panel.getBindings()
- if (res.data.success) {
- panels.value = res.data.panels || []
- if (res.data.address_range) addressRange.value = res.data.address_range
- }
- } catch (e) {
- console.error('load panels error:', e)
- }
- }
- async function refreshData() {
- loading.value = true
- try {
- await loadPanels()
- lastUpdate.value = new Date().toLocaleTimeString()
- } finally {
- loading.value = false
- }
- }
- async function scanNewPanels() {
- scanning.value = true
- try {
- const res = await apiService.panel.scan()
- if (!res.data.success) {
- message.warning(res.data.message || '扫描请求失败')
- return
- }
- message.info('已开始扫描地址段内未绑定地址')
- // 每 2 秒查询一次进度,最多 60 秒
- for (let i = 0; i < 30; i++) {
- await new Promise((resolve) => setTimeout(resolve, 2000))
- const st = await apiService.panel.getScanStatus()
- const scan = st.data.scan || {}
- if (!scan.running) {
- const found = scan.found || []
- if (found.length) {
- message.success(`扫描完成,发现 ${found.length} 台新线架: ${found.map(f => `地址${f.address}`).join('、')}`)
- } else {
- message.info('扫描完成,未发现新线架')
- }
- break
- }
- }
- await refreshData()
- } catch (e) {
- console.error('scan error:', e)
- message.error('扫描失败,请检查串口连接')
- } finally {
- scanning.value = false
- }
- }
- async function openConfigAddress() {
- configModalOpen.value = true
- try {
- const res = await apiService.panel.getConfigAddressStatus()
- if (res.data.success) {
- configStatus.value = res.data.config || configStatus.value
- configRunning.value = !!configStatus.value.running
- if (configRunning.value) startConfigPolling(true)
- }
- } catch (e) {
- console.error('get config address status error:', e)
- }
- }
- function startConfigPolling(silent = false) {
- if (configPollTimer) return
- if (!silent) configRunning.value = true
- configPollTimer = setInterval(pollConfigStatus, 1000)
- }
- async function pollConfigStatus() {
- try {
- const res = await apiService.panel.getConfigAddressStatus()
- if (!res.data.success) return
- configStatus.value = res.data.config || {}
- configRunning.value = !!configStatus.value.running
- if (!configRunning.value) {
- stopConfigPolling()
- if (configStatus.value.address != null) {
- message.success(`配置成功:天线 ${configStatus.value.antenna} → 地址 ${configStatus.value.address}`)
- await refreshData()
- } else if (configStatus.value.error) {
- message.error(configStatus.value.error)
- }
- }
- } catch (e) {
- console.error('poll config address status error:', e)
- }
- }
- function stopConfigPolling() {
- if (configPollTimer) {
- clearInterval(configPollTimer)
- configPollTimer = null
- }
- configRunning.value = false
- }
- async function startConfigAddress() {
- configStarting.value = true
- try {
- const res = await apiService.panel.configAddress({ timeout: 60 })
- if (!res.data.success) {
- message.warning(res.data.message || '发送配置地址指令失败')
- return
- }
- message.info(res.data.message || '已发送配置地址指令,请刷配置卡')
- configStatus.value = {
- running: true,
- timeout: res.data.timeout,
- antenna: null,
- address: null,
- raw: '',
- error: null
- }
- startConfigPolling()
- } catch (e) {
- message.error(
- (e.response && e.response.data && e.response.data.message) || '发送配置地址指令失败,请检查串口连接'
- )
- } finally {
- configStarting.value = false
- }
- }
- function closeConfigAddress() {
- configModalOpen.value = false
- // 若仍在等待线架应答,后台继续轮询,结束后仍会提示结果
- if (!configRunning.value) stopConfigPolling()
- }
- async function unbindPanel(record) {
- try {
- const res = await apiService.panel.unbind({ address: record.address })
- if (res.data.success) {
- message.success(res.data.message || '已解除绑定')
- await refreshData()
- } else {
- message.error(res.data.message || '解除绑定失败')
- }
- } catch (e) {
- message.error((e.response && e.response.data && e.response.data.message) || '解除绑定失败')
- }
- }
- async function clearMappings(record) {
- try {
- const res = await apiService.panel.clearMappings({
- panel_id: record.panel_id,
- address: record.address
- })
- if (res.data.success) {
- const hw = res.data.hardware || {}
- if (hw.cleared) {
- message.success(`已清空 ${res.data.removed} 条端口映射,硬件端口已同步清空`)
- } else {
- message.success(`已清空 ${res.data.removed} 条端口映射${hw.message ? '(' + hw.message + ')' : ''}`)
- }
- await refreshData()
- } else {
- message.error(res.data.message || '清空映射失败')
- }
- } catch (e) {
- message.error((e.response && e.response.data && e.response.data.message) || '清空映射失败')
- }
- }
- onMounted(async () => {
- await refreshData()
- pollTimer = setInterval(loadPanels, 5000)
- })
- onUnmounted(() => {
- if (pollTimer) clearInterval(pollTimer)
- if (configPollTimer) clearInterval(configPollTimer)
- })
- </script>
- <style scoped>
- .overview-bar {
- display: flex;
- align-items: center;
- gap: 24px;
- flex-wrap: wrap;
- }
- .overview-item {
- display: flex;
- align-items: center;
- gap: 8px;
- }
- .overview-label {
- font-size: 14px;
- color: #666;
- }
- .overview-value {
- font-size: 14px;
- color: #333;
- }
- .tip-icon {
- color: #999;
- }
- .mono {
- font-family: monospace;
- font-size: 12px;
- }
- </style>
|