udp调试页面的完全适配
This commit is contained in:
45
ruoyi-ui/src/api/mill/millData.js
Normal file
45
ruoyi-ui/src/api/mill/millData.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
/** 获取所有报文Schema定义 */
|
||||
export function getSchemas() {
|
||||
return request({ url: '/mill/data/schemas', method: 'get' })
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送报文(字段表单模式)
|
||||
* @param {Object} data - { host, port, id, fields: {} }
|
||||
*/
|
||||
export function sendPacket(data) {
|
||||
return request({ url: '/mill/data/send', method: 'post', data })
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送原始Hex报文
|
||||
* @param {Object} data - { host, port, hex: '...' }
|
||||
*/
|
||||
export function sendRawPacket(data) {
|
||||
return request({ url: '/mill/data/sendRaw', method: 'post', data })
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析Hex为字段值
|
||||
* @param {Object} data - { hex: '...' }
|
||||
*/
|
||||
export function parsePacket(data) {
|
||||
return request({ url: '/mill/data/parse', method: 'post', data })
|
||||
}
|
||||
|
||||
/** 获取报文历史 */
|
||||
export function getHistory(query) {
|
||||
return request({ url: '/mill/data/history', method: 'get', params: query })
|
||||
}
|
||||
|
||||
/** 获取统计信息 */
|
||||
export function getStats() {
|
||||
return request({ url: '/mill/data/stats', method: 'get' })
|
||||
}
|
||||
|
||||
/** 清空历史记录 */
|
||||
export function clearHistory() {
|
||||
return request({ url: '/mill/data/history', method: 'delete' })
|
||||
}
|
||||
796
ruoyi-ui/src/views/mill/mill-debug.vue
Normal file
796
ruoyi-ui/src/views/mill/mill-debug.vue
Normal file
@@ -0,0 +1,796 @@
|
||||
<template>
|
||||
<div class="mill-debug">
|
||||
|
||||
<!-- ══ 顶栏 ══════════════════════════════════════════════════════ -->
|
||||
<div class="top-bar">
|
||||
<span class="top-title">报文调试工具</span>
|
||||
<span class="top-proto">帧格式:[4B LE ID] [4B LE 长度] [数据体(小端)]</span>
|
||||
<div class="top-right">
|
||||
<el-tag size="small" type="info">收 {{ stats.inbound }}</el-tag>
|
||||
<el-tag size="small" type="warning" style="margin-left:6px">发 {{ stats.outbound }}</el-tag>
|
||||
<el-switch v-model="autoRefresh" active-text="自动刷新" inactive-text="" size="mini" style="margin-left:12px" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ══ 主体:左发送 / 右接收 ══════════════════════════════════════ -->
|
||||
<el-row :gutter="14" class="body-row">
|
||||
|
||||
<!-- ─── 左列:发送 ───────────────────────────────────────────── -->
|
||||
<el-col :span="11" class="left-col">
|
||||
|
||||
<!-- 目标地址 + 模板 -->
|
||||
<el-card class="panel-card" shadow="never">
|
||||
<div slot="header" class="ph"><i class="el-icon-s-promotion" /> 发送配置</div>
|
||||
<el-form :model="sf" size="small" label-width="72px" class="cfg-form">
|
||||
<el-row :gutter="8">
|
||||
<el-col :span="15">
|
||||
<el-form-item label="目标IP">
|
||||
<el-input v-model="sf.host" placeholder="127.0.0.1" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="9">
|
||||
<el-form-item label="端口">
|
||||
<el-input-number v-model="sf.port" :min="1" :max="65535" :controls="false" style="width:100%" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-form-item label="报文模板">
|
||||
<el-select v-model="sf.schemaId" style="width:100%" @change="onSchemaChange">
|
||||
<el-option v-for="s in schemas" :key="s.id" :value="s.id"
|
||||
:label="`ID = ${s.id} (${s.description},${s.totalBytes}字节)`" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<!-- 字段输入 -->
|
||||
<el-card class="panel-card fields-card" shadow="never" style="margin-top:10px">
|
||||
<div slot="header" class="ph">
|
||||
<i class="el-icon-edit-outline" /> 字段值
|
||||
<div class="ph-right">
|
||||
<el-button size="mini" @click="fillTest">测试数据</el-button>
|
||||
<el-button size="mini" @click="resetFields">清空</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="fields-scroll" v-if="curSchema">
|
||||
<template v-for="fd in curSchema.fields">
|
||||
|
||||
<!-- I4含位字段 -->
|
||||
<div v-if="fd.bits && fd.bits.length" :key="fd.name" class="bit-block">
|
||||
<div class="bit-hdr">
|
||||
<span class="fn">{{ fd.name }}</span>
|
||||
<span class="fdesc">{{ fd.description }}</span>
|
||||
<span class="badge i4">I4</span>
|
||||
<el-input-number v-model="fv[fd.name]" size="mini" :controls="false"
|
||||
placeholder="整体值" style="width:88px;margin-left:auto"
|
||||
@change="v => syncBitsFrom(fd, v)" />
|
||||
</div>
|
||||
<div class="bits-wrap">
|
||||
<el-tooltip v-for="bit in fd.bits" :key="bit.name" :content="`bit${bit.index}: ${bit.description}`" placement="top">
|
||||
<label class="bit-label" :class="{ active: bv[bit.name] }">
|
||||
<el-switch v-model="bv[bit.name]" @change="syncIntFrom(fd)" />
|
||||
<span>{{ bit.name }}</span>
|
||||
</label>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 普通字段 -->
|
||||
<div v-else :key="fd.name" class="field-row">
|
||||
<span class="fn">{{ fd.name }}</span>
|
||||
<span class="fdesc">{{ fd.description }}</span>
|
||||
<span :class="['badge', fd.type.toLowerCase()]">{{ fd.type }}</span>
|
||||
<el-input-number v-model="fv[fd.name]" size="mini" :controls="false"
|
||||
:precision="fd.type==='F4' ? 4 : 0"
|
||||
style="width:110px;margin-left:auto"
|
||||
@change="v => { fv = { ...fv, [fd.name]: v } }" />
|
||||
<span class="unit">{{ fd.unit }}</span>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
</div>
|
||||
<div v-else class="empty-hint">请先选择报文模板</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 发送按钮 -->
|
||||
<div class="send-row">
|
||||
<el-button type="primary" icon="el-icon-s-promotion" :loading="sending" @click="doSend">
|
||||
{{ sending ? '发送中…' : '发送报文' }}
|
||||
</el-button>
|
||||
<span v-if="lastResult" :class="['send-tip', lastResult.ok ? 'ok' : 'err']">
|
||||
{{ lastResult.msg }}
|
||||
</span>
|
||||
</div>
|
||||
</el-col>
|
||||
|
||||
<!-- ─── 右列:格式预览 + 接收 ──────────────────────────────── -->
|
||||
<el-col :span="13" class="right-col">
|
||||
|
||||
<!-- 报文格式预览(实时) -->
|
||||
<el-card class="panel-card" shadow="never">
|
||||
<div slot="header" class="ph">
|
||||
<i class="el-icon-view" /> 报文预览(实时)
|
||||
<el-tag size="mini" type="info" style="margin-left:8px">
|
||||
{{ previewBytes.length }} 字节
|
||||
</el-tag>
|
||||
</div>
|
||||
|
||||
<el-tabs v-model="previewTab" type="card" size="small">
|
||||
|
||||
<!-- JSON -->
|
||||
<el-tab-pane label="JSON(字段值)" name="json">
|
||||
<pre class="code-block json-block">{{ previewJson }}</pre>
|
||||
</el-tab-pane>
|
||||
|
||||
<!-- Hex -->
|
||||
<el-tab-pane label="Hex(十六进制)" name="hex">
|
||||
<div class="hex-legend">
|
||||
<span class="leg hdr-leg">■ 头部 8字节(ID + 数据长度)</span>
|
||||
<span class="leg body-leg">■ 数据体</span>
|
||||
</div>
|
||||
<div class="hex-dump" v-html="previewHexHtml" />
|
||||
</el-tab-pane>
|
||||
|
||||
<!-- 二进制 -->
|
||||
<el-tab-pane label="Binary(二进制)" name="bin">
|
||||
<div class="hex-legend">
|
||||
<span class="leg hdr-leg">■ 头部 8字节</span>
|
||||
<span class="leg body-leg">■ 数据体</span>
|
||||
<span style="margin-left:auto;font-size:11px;color:#909399">每行8字节 · 含偏移量</span>
|
||||
</div>
|
||||
<div class="bin-dump" v-html="previewBinHtml" />
|
||||
</el-tab-pane>
|
||||
|
||||
</el-tabs>
|
||||
</el-card>
|
||||
|
||||
<!-- 接收记录 -->
|
||||
<el-card class="panel-card recv-card" shadow="never" style="margin-top:10px">
|
||||
<div slot="header" class="ph">
|
||||
<i class="el-icon-download" /> 接收记录
|
||||
<el-button size="mini" icon="el-icon-delete" @click="doClear" style="margin-left:auto">清空</el-button>
|
||||
</div>
|
||||
|
||||
<el-table ref="histTable" :data="history" size="mini" height="200"
|
||||
highlight-current-row @current-change="onSelect" style="width:100%">
|
||||
<el-table-column label="方向" width="52" align="center">
|
||||
<template slot-scope="{ row }">
|
||||
<el-tag :type="row.direction==='IN'?'success':'warning'" size="mini">
|
||||
{{ row.direction==='IN'?'收':'发' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="packetId" label="ID" width="55" align="center" />
|
||||
<el-table-column prop="timestamp" label="时间" min-width="150" />
|
||||
<el-table-column prop="dataLength" label="B" width="45" align="center" />
|
||||
<el-table-column label="地址" min-width="110">
|
||||
<template slot-scope="{ row }">
|
||||
<span class="addr">{{ row.direction==='IN'
|
||||
? `${row.sourceHost}:${row.sourcePort}`
|
||||
: `→ ${row.targetHost}:${row.targetPort}` }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 选中报文多格式展示 -->
|
||||
<div v-if="sel" class="detail-area">
|
||||
<el-tabs v-model="detailTab" type="card" size="small">
|
||||
|
||||
<el-tab-pane label="JSON(字段值)" name="json">
|
||||
<pre class="code-block json-block">{{ selJson }}</pre>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane label="Hex(十六进制)" name="hex">
|
||||
<div class="hex-legend">
|
||||
<span class="leg hdr-leg">■ 头部</span>
|
||||
<span class="leg body-leg">■ 数据体</span>
|
||||
</div>
|
||||
<div class="hex-dump" v-html="selHexHtml" />
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane label="Binary(二进制)" name="bin">
|
||||
<div class="hex-legend">
|
||||
<span class="leg hdr-leg">■ 头部</span>
|
||||
<span class="leg body-leg">■ 数据体</span>
|
||||
</div>
|
||||
<div class="bin-dump" v-html="selBinHtml" />
|
||||
</el-tab-pane>
|
||||
|
||||
</el-tabs>
|
||||
</div>
|
||||
<div v-else class="empty-hint" style="padding:12px 0">↑ 点击记录查看详情</div>
|
||||
</el-card>
|
||||
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
getSchemas, sendPacket, getHistory, getStats, clearHistory
|
||||
} from '@/api/mill/millData'
|
||||
|
||||
export default {
|
||||
name: 'MillDebug',
|
||||
|
||||
data() {
|
||||
return {
|
||||
schemas: [],
|
||||
curSchema: null,
|
||||
|
||||
// 发送表单
|
||||
sf: { host: '127.0.0.1', port: 9000, schemaId: null },
|
||||
fv: {}, // field values: name → Number
|
||||
bv: {}, // bit values: bitName → Boolean
|
||||
|
||||
sending: false,
|
||||
lastResult: null,
|
||||
|
||||
// 预览
|
||||
previewTab: 'hex',
|
||||
|
||||
// 接收
|
||||
history: [],
|
||||
stats: { inbound: 0, outbound: 0 },
|
||||
sel: null,
|
||||
detailTab: 'hex',
|
||||
autoRefresh: true,
|
||||
timer: null
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
// ── 实时预览(自动追踪 fv / bv 变化)──────────────────────────
|
||||
previewBytes() {
|
||||
if (!this.curSchema || !this.sf.schemaId) return []
|
||||
const merged = {}
|
||||
for (const fd of this.curSchema.fields) {
|
||||
if (fd.bits && fd.bits.length) {
|
||||
let v = 0
|
||||
for (const b of fd.bits) { if (this.bv[b.name]) v |= (1 << b.index) }
|
||||
merged[fd.name] = v
|
||||
} else {
|
||||
merged[fd.name] = this.fv[fd.name] || 0
|
||||
}
|
||||
}
|
||||
return this.encodePacket(this.sf.schemaId, this.curSchema.fields, merged)
|
||||
},
|
||||
|
||||
previewJson() {
|
||||
if (!this.curSchema) return '{}'
|
||||
const obj = {}
|
||||
for (const fd of this.curSchema.fields) {
|
||||
if (fd.bits && fd.bits.length) {
|
||||
obj[fd.name] = this.fv[fd.name] || 0
|
||||
for (const b of fd.bits) obj[b.name] = this.bv[b.name] ? 1 : 0
|
||||
} else {
|
||||
obj[fd.name] = this.fv[fd.name] || 0
|
||||
}
|
||||
}
|
||||
return JSON.stringify(obj, null, 2)
|
||||
},
|
||||
|
||||
previewHexHtml() {
|
||||
return this.buildHexHtml(this.previewBytes)
|
||||
},
|
||||
|
||||
previewBinHtml() {
|
||||
return this.buildBinHtml(this.previewBytes)
|
||||
},
|
||||
|
||||
// ── 选中记录计算 ───────────────────────────────────────────────
|
||||
selJson() {
|
||||
if (!this.sel || !this.sel.fields) return '(无解析数据)'
|
||||
return JSON.stringify(this.sel.fields, null, 2)
|
||||
},
|
||||
|
||||
selHexHtml() {
|
||||
if (!this.sel) return ''
|
||||
return this.buildHexHtml(this.hexStrToBytes(this.sel.rawHex))
|
||||
},
|
||||
|
||||
selBinHtml() {
|
||||
if (!this.sel) return ''
|
||||
return this.buildBinHtml(this.hexStrToBytes(this.sel.rawHex))
|
||||
}
|
||||
},
|
||||
|
||||
created() {
|
||||
this.loadSchemas()
|
||||
this.loadHistory()
|
||||
this.loadStats()
|
||||
this.timer = setInterval(() => {
|
||||
if (this.autoRefresh) { this.loadHistory(); this.loadStats() }
|
||||
}, 2000)
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
clearInterval(this.timer)
|
||||
},
|
||||
|
||||
methods: {
|
||||
// ── Schema ──────────────────────────────────────────────────────
|
||||
async loadSchemas() {
|
||||
try {
|
||||
const res = await getSchemas()
|
||||
this.schemas = (res.data && res.data.schemas) || []
|
||||
if (this.schemas.length && !this.sf.schemaId) {
|
||||
this.sf.schemaId = this.schemas[0].id
|
||||
this.onSchemaChange(this.schemas[0].id)
|
||||
}
|
||||
} catch { /**/ }
|
||||
},
|
||||
|
||||
onSchemaChange(id) {
|
||||
this.curSchema = this.schemas.find(s => s.id === id) || null
|
||||
// 整体替换对象 → Vue 2 会完整观察新对象的所有 key
|
||||
const newFv = {}
|
||||
const newBv = {}
|
||||
if (this.curSchema) {
|
||||
for (const fd of this.curSchema.fields) {
|
||||
newFv[fd.name] = 0
|
||||
if (fd.bits) for (const b of fd.bits) newBv[b.name] = false
|
||||
}
|
||||
}
|
||||
this.fv = newFv
|
||||
this.bv = newBv
|
||||
},
|
||||
|
||||
// ── 位字段同步 ───────────────────────────────────────────────────
|
||||
syncBitsFrom(fd, val) {
|
||||
const v = val || 0
|
||||
const newBv = { ...this.bv }
|
||||
for (const b of (fd.bits || [])) newBv[b.name] = !!((v >> b.index) & 1)
|
||||
this.bv = newBv
|
||||
},
|
||||
|
||||
syncIntFrom(fd) {
|
||||
let v = 0
|
||||
for (const b of (fd.bits || [])) { if (this.bv[b.name]) v |= (1 << b.index) }
|
||||
this.fv = { ...this.fv, [fd.name]: v }
|
||||
},
|
||||
|
||||
// ── 测试 / 清空 ──────────────────────────────────────────────────
|
||||
fillTest() {
|
||||
if (!this.curSchema) return
|
||||
const newFv = {}
|
||||
const newBv = {}
|
||||
for (const fd of this.curSchema.fields) {
|
||||
if (fd.name === 'counter') newFv[fd.name] = 1
|
||||
else if (fd.name === 'passNo') newFv[fd.name] = 3
|
||||
else if (fd.type === 'I4' || fd.type === 'I2') newFv[fd.name] = 0
|
||||
else newFv[fd.name] = parseFloat((Math.random() * 100).toFixed(3))
|
||||
if (fd.bits) {
|
||||
for (const b of fd.bits) newBv[b.name] = !!((newFv[fd.name] >> b.index) & 1)
|
||||
}
|
||||
}
|
||||
this.fv = newFv
|
||||
this.bv = newBv
|
||||
},
|
||||
|
||||
resetFields() {
|
||||
if (this.curSchema) this.onSchemaChange(this.sf.schemaId)
|
||||
},
|
||||
|
||||
// ── 发送 ─────────────────────────────────────────────────────────
|
||||
async doSend() {
|
||||
if (!this.sf.host) return this.$message.warning('请输入目标IP')
|
||||
if (!this.sf.schemaId) return this.$message.warning('请选择报文模板')
|
||||
this.sending = true
|
||||
this.lastResult = null
|
||||
try {
|
||||
// previewBytes computed 里已经合并了位字段,直接复用同一份 merged 逻辑
|
||||
const merged = {}
|
||||
for (const fd of (this.curSchema ? this.curSchema.fields : [])) {
|
||||
if (fd.bits && fd.bits.length) {
|
||||
let v = 0
|
||||
for (const b of fd.bits) { if (this.bv[b.name]) v |= (1 << b.index) }
|
||||
merged[fd.name] = v
|
||||
} else {
|
||||
merged[fd.name] = this.fv[fd.name] || 0
|
||||
}
|
||||
}
|
||||
await sendPacket({ host: this.sf.host, port: this.sf.port, id: this.sf.schemaId, fields: merged })
|
||||
this.lastResult = { ok: true, msg: `✓ 已发送 → ${this.sf.host}:${this.sf.port}` }
|
||||
this.$message.success(this.lastResult.msg)
|
||||
await this.loadHistory()
|
||||
await this.loadStats()
|
||||
} catch (e) {
|
||||
this.lastResult = { ok: false, msg: `✗ ${e.message}` }
|
||||
this.$message.error(this.lastResult.msg)
|
||||
} finally {
|
||||
this.sending = false
|
||||
}
|
||||
},
|
||||
|
||||
// ── 历史 ─────────────────────────────────────────────────────────
|
||||
async loadHistory() {
|
||||
try {
|
||||
const res = await getHistory({ pageNum: 1, pageSize: 100 })
|
||||
const rows = (res.data && res.data.rows) || []
|
||||
const selId = this.sel && this.sel.id
|
||||
this.history = rows
|
||||
if (selId) {
|
||||
const found = rows.find(r => r.id === selId)
|
||||
this.$nextTick(() => {
|
||||
this.sel = found || this.sel
|
||||
if (found && this.$refs.histTable) {
|
||||
this.$refs.histTable.setCurrentRow(found)
|
||||
}
|
||||
})
|
||||
}
|
||||
} catch { /**/ }
|
||||
},
|
||||
|
||||
async loadStats() {
|
||||
try {
|
||||
const res = await getStats()
|
||||
this.stats = res.data || this.stats
|
||||
} catch { /**/ }
|
||||
},
|
||||
|
||||
async doClear() {
|
||||
try {
|
||||
await this.$confirm('确定清空所有记录?', '提示', { type: 'warning' })
|
||||
await clearHistory()
|
||||
this.history = []
|
||||
this.sel = null
|
||||
this.stats = { inbound: 0, outbound: 0 }
|
||||
} catch { /**/ }
|
||||
},
|
||||
|
||||
onSelect(row) {
|
||||
this.sel = row
|
||||
this.detailTab = row && row.fields ? 'json' : 'hex'
|
||||
},
|
||||
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
// 前端小端编码(与后端 MillDataCodec 一致)
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
encodePacket(id, fields, values) {
|
||||
// 计算数据体大小
|
||||
const bodyLen = fields.reduce((s, f) => s + (f.type === 'I2' ? 2 : 4), 0)
|
||||
const total = 8 + bodyLen
|
||||
const buf = new ArrayBuffer(total)
|
||||
const dv = new DataView(buf)
|
||||
let off = 0
|
||||
|
||||
// 头部
|
||||
dv.setUint32(off, id, true); off += 4 // LE ID
|
||||
dv.setUint32(off, bodyLen, true); off += 4 // LE length
|
||||
|
||||
// 数据体
|
||||
for (const fd of fields) {
|
||||
const v = values[fd.name] || 0
|
||||
if (fd.type === 'I4') { dv.setInt32(off, v | 0, true); off += 4 }
|
||||
else if (fd.type === 'I2') { dv.setInt16(off, v | 0, true); off += 2 }
|
||||
else { dv.setFloat32(off, parseFloat(v) || 0, true); off += 4 }
|
||||
}
|
||||
|
||||
return Array.from(new Uint8Array(buf))
|
||||
},
|
||||
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
// 格式化工具
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
hexStrToBytes(hexStr) {
|
||||
if (!hexStr) return []
|
||||
return hexStr.split(/\s+/).filter(Boolean).map(h => parseInt(h, 16))
|
||||
},
|
||||
|
||||
/** Hex dump HTML,每行16字节,头部前8字节蓝色,其余绿色 */
|
||||
buildHexHtml(bytes) {
|
||||
if (!bytes || !bytes.length) return '<span style="color:#666">(无数据)</span>'
|
||||
const rows = []
|
||||
for (let i = 0; i < bytes.length; i += 16) {
|
||||
const rowBytes = bytes.slice(i, i + 16)
|
||||
const offset = i.toString(16).padStart(4, '0').toUpperCase()
|
||||
const hexParts = rowBytes.map((b, j) => {
|
||||
const abs = i + j
|
||||
const hex = b.toString(16).padStart(2, '0').toUpperCase()
|
||||
const cls = abs < 8 ? 'hdr' : 'body'
|
||||
return `<span class="hx ${cls}">${hex}</span>`
|
||||
})
|
||||
// 中间空格
|
||||
if (rowBytes.length > 8) {
|
||||
hexParts.splice(8, 0, '<span class="hx-gap"> </span>')
|
||||
}
|
||||
rows.push(`<div class="dump-row"><span class="off">${offset}</span> ${hexParts.join(' ')}</div>`)
|
||||
}
|
||||
return rows.join('')
|
||||
},
|
||||
|
||||
/** Binary dump HTML,每行8字节,每字节8位,头部蓝色 */
|
||||
buildBinHtml(bytes) {
|
||||
if (!bytes || !bytes.length) return '<span style="color:#666">(无数据)</span>'
|
||||
const rows = []
|
||||
for (let i = 0; i < bytes.length; i += 8) {
|
||||
const rowBytes = bytes.slice(i, i + 8)
|
||||
const offset = i.toString(16).padStart(4, '0').toUpperCase()
|
||||
const binParts = rowBytes.map((b, j) => {
|
||||
const abs = i + j
|
||||
const bits = b.toString(2).padStart(8, '0')
|
||||
const cls = abs < 8 ? 'hdr' : 'body'
|
||||
return `<span class="bx ${cls}">${bits}</span>`
|
||||
})
|
||||
rows.push(`<div class="dump-row"><span class="off">${offset}</span> ${binParts.join(' ')}</div>`)
|
||||
}
|
||||
return rows.join('')
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
// ── 全局 ─────────────────────────────────────────────────────────────
|
||||
.mill-debug {
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: #f0f2f5;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
// ── 顶栏 ─────────────────────────────────────────────────────────────
|
||||
.top-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 8px 16px;
|
||||
background: #1c2b3a;
|
||||
color: #c8d8e8;
|
||||
flex-shrink: 0;
|
||||
|
||||
.top-title { font-size: 15px; font-weight: 700; color: #fff; margin-right: 16px; }
|
||||
.top-proto { font-family: monospace; font-size: 12px; color: #6a8aab; flex: 1; }
|
||||
.top-right { display: flex; align-items: center; }
|
||||
}
|
||||
|
||||
// ── 主体 ─────────────────────────────────────────────────────────────
|
||||
.body-row {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
margin: 10px 10px 0 !important;
|
||||
|
||||
.left-col, .right-col {
|
||||
height: 100%;
|
||||
overflow-y: auto;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
// ── 卡片 ─────────────────────────────────────────────────────────────
|
||||
.panel-card {
|
||||
border-radius: 6px;
|
||||
::v-deep .el-card__body { padding: 10px 12px; }
|
||||
}
|
||||
|
||||
.ph {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
color: #303133;
|
||||
gap: 6px;
|
||||
.ph-right { margin-left: auto; display: flex; gap: 6px; }
|
||||
}
|
||||
|
||||
// ── 配置表单 ─────────────────────────────────────────────────────────
|
||||
.cfg-form ::v-deep .el-form-item { margin-bottom: 8px; }
|
||||
|
||||
// ── 字段列表 ─────────────────────────────────────────────────────────
|
||||
.fields-card {
|
||||
::v-deep .el-card__body { padding: 0; }
|
||||
}
|
||||
|
||||
.fields-scroll {
|
||||
max-height: 340px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.field-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 5px 12px;
|
||||
font-size: 12px;
|
||||
border-bottom: 1px solid #f5f5f5;
|
||||
gap: 6px;
|
||||
&:hover { background: #f8fbff; }
|
||||
&:last-child { border-bottom: none; }
|
||||
}
|
||||
|
||||
.fn {
|
||||
width: 128px;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 12px;
|
||||
color: #1f3c5e;
|
||||
flex-shrink: 0;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.fdesc {
|
||||
flex: 1;
|
||||
color: #909399;
|
||||
font-size: 11px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.unit {
|
||||
width: 40px;
|
||||
font-size: 11px;
|
||||
color: #c0c4cc;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
// ── 位字段块 ─────────────────────────────────────────────────────────
|
||||
.bit-block {
|
||||
border-left: 3px solid #409eff;
|
||||
background: #f0f7ff;
|
||||
margin: 2px 0;
|
||||
}
|
||||
|
||||
.bit-hdr {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 5px 12px;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
border-bottom: 1px dashed #c8dcf0;
|
||||
}
|
||||
|
||||
.bits-wrap {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
padding: 6px 12px 8px 20px;
|
||||
}
|
||||
|
||||
.bit-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
font-size: 11px;
|
||||
color: #606266;
|
||||
cursor: pointer;
|
||||
padding: 2px 6px;
|
||||
border-radius: 3px;
|
||||
background: #fff;
|
||||
border: 1px solid #ddd;
|
||||
transition: all .15s;
|
||||
|
||||
&.active {
|
||||
background: #ecf5ff;
|
||||
border-color: #409eff;
|
||||
color: #409eff;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
::v-deep .el-switch { transform: scale(0.75); }
|
||||
}
|
||||
|
||||
// ── 类型徽章 ─────────────────────────────────────────────────────────
|
||||
.badge {
|
||||
flex-shrink: 0;
|
||||
font-size: 10px;
|
||||
font-weight: 700;
|
||||
padding: 1px 5px;
|
||||
border-radius: 3px;
|
||||
font-family: monospace;
|
||||
|
||||
&.i4 { background: #ecf5ff; color: #409eff; }
|
||||
&.i2 { background: #f0f9eb; color: #67c23a; }
|
||||
&.f4 { background: #fdf6ec; color: #e6a23c; }
|
||||
}
|
||||
|
||||
// ── 发送按钮行 ───────────────────────────────────────────────────────
|
||||
.send-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 10px 4px 4px;
|
||||
.send-tip { font-size: 12px; }
|
||||
.ok { color: #67c23a; }
|
||||
.err { color: #f56c6c; }
|
||||
}
|
||||
|
||||
// ── 代码块 ───────────────────────────────────────────────────────────
|
||||
.code-block {
|
||||
margin: 0;
|
||||
padding: 10px;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
color: #2d6a2d;
|
||||
background: #f6fff6;
|
||||
border-radius: 0 0 4px 4px;
|
||||
overflow-x: auto;
|
||||
max-height: 240px;
|
||||
overflow-y: auto;
|
||||
border: 1px solid #e0ede0;
|
||||
}
|
||||
|
||||
.json-block {
|
||||
color: #1a6b1a;
|
||||
}
|
||||
|
||||
// ── 图例 ─────────────────────────────────────────────────────────────
|
||||
.hex-legend {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 4px 10px;
|
||||
background: #f5f7fa;
|
||||
border-bottom: 1px solid #e4e7ed;
|
||||
font-size: 11px;
|
||||
|
||||
.leg { display: flex; align-items: center; gap: 4px; }
|
||||
.hdr-leg { color: #1a6db5; font-weight: 600; }
|
||||
.body-leg { color: #2a7a2a; font-weight: 600; }
|
||||
}
|
||||
|
||||
// ── Hex dump ─────────────────────────────────────────────────────────
|
||||
.hex-dump {
|
||||
background: #fff;
|
||||
border: 1px solid #e4e7ed;
|
||||
padding: 8px 10px;
|
||||
border-radius: 0 0 4px 4px;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.9;
|
||||
overflow-x: auto;
|
||||
max-height: 240px;
|
||||
overflow-y: auto;
|
||||
|
||||
::v-deep .dump-row { white-space: nowrap; }
|
||||
::v-deep .off { color: #aaa; margin-right: 10px; font-size: 11px; user-select: none; }
|
||||
::v-deep .hx-gap { display: inline-block; width: 10px; }
|
||||
::v-deep .hx.hdr { color: #1a6db5; font-weight: 600; }
|
||||
::v-deep .hx.body { color: #2a7a2a; }
|
||||
}
|
||||
|
||||
// ── Binary dump ──────────────────────────────────────────────────────
|
||||
.bin-dump {
|
||||
background: #fff;
|
||||
border: 1px solid #e4e7ed;
|
||||
padding: 8px 10px;
|
||||
border-radius: 0 0 4px 4px;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 11.5px;
|
||||
line-height: 1.9;
|
||||
overflow-x: auto;
|
||||
max-height: 240px;
|
||||
overflow-y: auto;
|
||||
|
||||
::v-deep .dump-row { white-space: nowrap; }
|
||||
::v-deep .off { color: #aaa; margin-right: 10px; font-size: 11px; user-select: none; }
|
||||
::v-deep .bx { letter-spacing: 1px; }
|
||||
::v-deep .bx.hdr { color: #1a6db5; font-weight: 600; }
|
||||
::v-deep .bx.body { color: #2a7a2a; }
|
||||
}
|
||||
|
||||
// ── 接收卡片 ─────────────────────────────────────────────────────────
|
||||
.recv-card {
|
||||
.addr { font-family: monospace; font-size: 11px; color: #606266; }
|
||||
}
|
||||
|
||||
.detail-area {
|
||||
margin-top: 8px;
|
||||
border: 1px solid #ebeef5;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
::v-deep .el-tabs__header { margin: 0; }
|
||||
}
|
||||
|
||||
// ── 空态 ─────────────────────────────────────────────────────────────
|
||||
.empty-hint {
|
||||
text-align: center;
|
||||
color: #c0c4cc;
|
||||
font-size: 13px;
|
||||
padding: 20px 0;
|
||||
}
|
||||
</style>
|
||||
@@ -267,7 +267,7 @@ export default {
|
||||
|
||||
// 配置表单
|
||||
configForm: {
|
||||
localPort: 8080,
|
||||
localPort: 8090,
|
||||
remotePort: 8081,
|
||||
remoteHost: '192.168.1.100',
|
||||
bufferSize: 8192,
|
||||
|
||||
Reference in New Issue
Block a user