ModelReport_master104.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <!-- 设备报文 -->
  2. <template>
  3. <div class="table-container" style="padding-top:20px;float: left;width: 100%;">
  4. <div class="buttons">
  5. <div class="title-main" style="line-height: 2rem;">报文</div>
  6. <div class="left">
  7. <div class="search">
  8. <el-form ref="searchForm" :model="searchForm" class="search-form" label-width="30px">
  9. <el-form-item class="search-parames">
  10. <el-select v-model="searchForm.selectVal" filterable @change="changeSelect">
  11. <el-option
  12. v-for="item in searchForm.selectOptions"
  13. :key="item.id"
  14. :label="item.name"
  15. :value="item.id"
  16. />
  17. </el-select>
  18. </el-form-item>
  19. </el-form>
  20. <!-- 下拉框改变化,自动就刷新数据了,不需要再点击搜索按钮
  21. <div class="search-button">
  22. <el-button class="dark-button" icon="el-icon-search" size="small" @click="refreshReport()">搜索</el-button>
  23. </div> -->
  24. </div>
  25. </div>
  26. <div class="right">
  27. <div class="export">
  28. <a target="_blank" :href="`${APP_BASE_API}/test/execute/${reportParames.curPlanId}/message.xls`"><el-button icon="el-icon-download" class="light-button" size="small">导出</el-button></a>
  29. </div>
  30. <div class="refresh">
  31. <el-button class="light-button" icon="el-icon-refresh-left" size="small" @click="refreshReport({page:paginationNumber-1,limit:pageLimit},true)">刷新</el-button>
  32. </div>
  33. <div class="clear">
  34. <el-button type="primary" icon="el-icon-delete" class="dark-button" size="small" @click="clearReport()">清空</el-button>
  35. </div>
  36. </div>
  37. </div>
  38. <el-row type="flex" style="float:left;width: 100%;">
  39. <el-col :span="18">
  40. <div class="left-report">
  41. <!-- 表格 -->
  42. <el-table :data="deviceReportData" :height="tableHeight" @row-click="analysisReport">
  43. <!-- id隐藏不显示,作为操作数据依据 -->
  44. <el-table-column v-if="false" property="id" label="id" />
  45. <el-table-column property="occur" label="时间" width="160px" />
  46. <el-table-column property="channelName" label="通道号" width="100px" />
  47. <el-table-column property="evtName" label="事件" width="75px" />
  48. <el-table-column property="hex" label="报文" />
  49. <el-table-column
  50. fixed="right"
  51. label="操作"
  52. width="125px"
  53. >
  54. <template slot-scope="scope">
  55. <el-button v-if="scope.row.id" v-clipboard:copy="scope.row.hex" v-clipboard:success="clipboardSuccess" class="table-act" type="text" icon="el-icon-delete" size="small">复制</el-button>
  56. <el-button v-if="scope.row.id" class="table-act" type="text" icon="el-icon-edit" size="small">解析</el-button>
  57. <!-- <el-button v-clipboard:copy="copyClipData" v-clipboard:success="clipboardSuccess" class="table-act" type="text" icon="el-icon-delete" size="small" @click="copyReport(scope.row)">复制</el-button> -->
  58. </template>
  59. </el-table-column>
  60. </el-table>
  61. </div>
  62. </el-col>
  63. <el-col :span="6">
  64. <div class="right-report">
  65. <!-- 解析结果显示 -->
  66. <div class="analysis-result">
  67. <div v-if="comonentVar.analysisResult.length<=0" class="empty-result">暂无解析结果</div>
  68. <div v-else>
  69. <ul
  70. v-for="item in comonentVar.analysisResult"
  71. :key="item.index"
  72. class="result"
  73. >
  74. <!-- <li class="key"> {{ item.first }} </li>
  75. <li class="value"> {{ item.second }} </li> -->
  76. <li class="oneBox">
  77. <span>参数:{{ item.first }}</span>
  78. <span>值:{{ item.second }}</span>
  79. </li>
  80. </ul>
  81. </div>
  82. </div>
  83. </div>
  84. </el-col>
  85. </el-row>
  86. <el-row>
  87. <el-col>
  88. <pagination
  89. background
  90. layout="pager"
  91. :limit="pageLimit"
  92. :total="paginationTotalElements"
  93. :current-page.sync="paginationNumber"
  94. @pagination="refreshReport"
  95. />
  96. </el-col>
  97. </el-row>
  98. </div>
  99. </template>
  100. <script>
  101. import { mapGetters } from 'vuex'
  102. import { delRecord, download, httpGet } from '@/api/common-action'
  103. import clipboard from '@/directive/clipboard/index.js'
  104. import Pagination from '@/components/Pagination'
  105. export default {
  106. name: 'ModelReport',
  107. directives: {
  108. clipboard
  109. },
  110. components: { Pagination },
  111. // report-parames
  112. props: {
  113. reportParames: {
  114. type: Object,
  115. default: function() {
  116. return {}
  117. }
  118. }
  119. },
  120. data() {
  121. return {
  122. APP_BASE_API: window.STATIC_CONFIG.proxyUrl,
  123. // 报文表格数据
  124. deviceReportData: [
  125. {
  126. 'id': '读取中...',
  127. 'occur': '读取中...',
  128. 'runnerId': '读取中...',
  129. 'channelId': '读取中...',
  130. 'channelName': '读取中...',
  131. 'evtId': '读取中...',
  132. 'bytes': '读取中...'
  133. }
  134. ],
  135. // 组件变量
  136. comonentVar: {
  137. deviceReportTitle: '读取中...',
  138. analysisResult: ''
  139. },
  140. // 搜索表单
  141. searchForm: {
  142. selectOptions: [
  143. { id: 'pt15m', name: '最近15分钟' },
  144. { id: 'pt4h', name: '最近4小时' },
  145. { id: 'pt24h', name: '最近24小时' }
  146. ],
  147. // 查询时间范围
  148. // PT4H是一种时间表示格式,表示持续时间为4小时。其中“PT”代表“持续时间(duration)”,后面的“4H”代表4个小时(hours)的意思。
  149. // PT2H 2小时 “PT3M”(3分钟)和“PT30S”(30秒)
  150. selectVal: 'pt4h'
  151. },
  152. copyClipData: {
  153. copyTestName: '剪切板复制测试内容-name',
  154. copyTestValue: '剪切板复制测试内容-value'
  155. },
  156. pageLimit: 20,
  157. paginationNumber: 0,
  158. paginationTotalElements: 0,
  159. // 动态设置table高度
  160. tableHeight: 0
  161. }
  162. },
  163. computed: {
  164. ...mapGetters([
  165. 'roles'
  166. ])
  167. },
  168. created() {
  169. // 获取后端报文数据
  170. // 报文查询 接口 /test/execute/:runner/message
  171. // 猜测 runner 应该是 planId
  172. // 动态设置表格高度
  173. const marginBottom = 440
  174. this.tableHeight = window.innerHeight - marginBottom
  175. this.refreshReport()
  176. },
  177. mounted() {
  178. this.comonentVar.deviceReportTitle = `[${this.reportParames.deviceName}]报文详情`
  179. },
  180. methods: {
  181. // 关闭model
  182. toggleModel() {
  183. // console.log('toggleModel started')
  184. this.$emit('toggleModel', 'ModelReport', false)
  185. },
  186. // 报文时间改变时执行
  187. changeSelect(selectVal) {
  188. // console.log('changeSelect selectVal=', selectVal)
  189. this.refreshReport()
  190. // 清空解析结果
  191. this.comonentVar.analysisResult = ''
  192. },
  193. // 清空报文
  194. // swagger 接口 删除通信日志 /test/execute/{id}/message
  195. // id 3200000252
  196. clearReport() {
  197. const delUrl = `/test/execute/${this.reportParames.curPlanId}/message`
  198. delRecord(delUrl).then(res => {
  199. // 删除成功
  200. // 刷新表格
  201. this.refreshReport()
  202. this.$message({
  203. message: '清空成功',
  204. type: 'success',
  205. duration: 1500,
  206. offset: window.screen.height / 3
  207. })
  208. })
  209. },
  210. // 刷新
  211. refreshReport(pageObj, isRe) {
  212. pageObj = pageObj || {
  213. page: 0,
  214. limit: this.pageLimit
  215. }
  216. // 报文查询 接口 /test/execute/:runner/message
  217. // #TODO: 这里要使用新标准,需要添加绝对时间参数的判断
  218. const getUrl = `/test/execute/${this.reportParames.curPlanId}/message?period=${this.searchForm.selectVal}&page=${pageObj.page}&size=${pageObj.limit}`
  219. // console.log('refreshReport getUrl=', getUrl)
  220. httpGet(getUrl).then(res => {
  221. // console.log('刷新后端报文数据 httpGet res=', res)
  222. this.deviceReportData = res.content
  223. this.paginationNumber = res.number + 1
  224. this.paginationTotalElements = res.totalElements * 1 // *1 强制转换为数字型
  225. if (isRe) {
  226. this.$message({
  227. message: '刷新成功',
  228. type: 'success',
  229. duration: 500,
  230. offset: window.screen.height / 3
  231. })
  232. }
  233. // 返回数据示例
  234. // "content": [
  235. // {
  236. // "id": "4",
  237. // "occur": "2023-06-11 08:31:11",
  238. // "runnerId": "999",
  239. // "channelId": null,
  240. // "channelName": "389434b4",
  241. // "evtId": "READ",
  242. // "bytes": "000100000003018401"
  243. // }],
  244. // "totalPages": 1,
  245. // "totalElements": "4",
  246. // "size": 20,
  247. // "number": 0,
  248. // "numberOfElements": 4
  249. // }
  250. })
  251. },
  252. // 导出
  253. exportReport() {
  254. // 接口 报文导出 /test/execute/:runner/message.xls
  255. // :runner 3200000315
  256. download(`/test/execute/${this.reportParames.curPlanId}/message.xls`).then(res => {
  257. const link = document.createElement('a')
  258. const blob = new Blob([res], {
  259. type: 'application/vnd.ms-excel;charset=utf-8'
  260. })
  261. link.style.display = 'none'
  262. link.href = URL.createObjectURL(blob)
  263. link.setAttribute('download', `导出报文-${this.componentParames.curPlanId}.xls`)
  264. document.body.appendChild(link)
  265. link.click()
  266. document.body.removeChild(link)
  267. })
  268. },
  269. // 解析报文
  270. analysisReport(row) {
  271. // 报文解析接口 /test/message/:id
  272. // 猜测 这个id 应该是前面 报文查询 接口 返回的id
  273. httpGet(`/test/message/${row.id}`).then(res => {
  274. if (res.items && res.items.length > 0) {
  275. this.comonentVar.analysisResult = res.items
  276. }
  277. })
  278. },
  279. // 复制报文 成功回调
  280. clipboardSuccess(val) {
  281. this.$message({
  282. message: '复制成功:' + val.text,
  283. type: 'success',
  284. duration: 1500,
  285. offset: window.screen.height / 3
  286. })
  287. }
  288. }
  289. }
  290. </script>
  291. <style lang="scss" scoped>
  292. .title-main {
  293. color: #111;
  294. font-weight: bold;
  295. float: left;
  296. width: auto;
  297. }
  298. .buttons {
  299. display: block;
  300. height: 3.5rem;
  301. width: 100%;
  302. justify-content: space-between;
  303. .left {
  304. float: left;
  305. width: auto;
  306. .search{
  307. display: flex;
  308. justify-content: left;
  309. .search-form {
  310. .search-parames {
  311. text-align: left;
  312. }
  313. }
  314. .search-button {
  315. padding-left: 20px;
  316. }
  317. }
  318. }
  319. .right{
  320. float: right;
  321. width: auto;
  322. justify-content: right;
  323. padding-bottom: 20px;
  324. .export{
  325. float: left;
  326. width: 70px;
  327. }
  328. .clear,.refresh {
  329. padding-left: 20px;
  330. float: left;
  331. width: 90px;
  332. }
  333. }
  334. }
  335. .right-report {
  336. height: 100%;
  337. // 解析结果
  338. .analysis-result {
  339. margin-left: 4px;
  340. border:1px #eaefef solid;
  341. background-color: #fcfdfd;
  342. width: 100%;
  343. height: 100%;
  344. padding: 0;
  345. // display: flex;
  346. // justify-content: center;
  347. // align-items: flex-start;
  348. .result {
  349. width: 100%;
  350. display: flex;
  351. justify-content: flex-start;
  352. align-items: center;
  353. text-align: left;
  354. color: #909399;
  355. &:nth-child(2n){
  356. background-color: #eee;
  357. }
  358. // .key,.value {
  359. // list-style-type: none;
  360. // }
  361. // .key {
  362. // width: 80px;
  363. // text-align: right;
  364. // padding-right:10px;
  365. // ::after {
  366. // width:10px;
  367. // }
  368. // }
  369. .oneBox{
  370. width: 100%;
  371. list-style-type: none;
  372. margin: 0;
  373. padding: 0;
  374. display: flex;
  375. flex-direction: column;
  376. }
  377. }
  378. .empty-result {
  379. text-align: center;
  380. color: #ccc;
  381. }
  382. }
  383. }
  384. // ::v-deep .diaClass{
  385. // position: relative;
  386. // top: 10%;
  387. // left:25%
  388. // }
  389. // 按钮公用样式
  390. .dark-button {
  391. background-color: #00706B;
  392. border: 1px #00706B solid;
  393. color: #fff;
  394. }
  395. .light-button {
  396. color: #00706B;
  397. border: 1px #00706B solid;
  398. }
  399. </style>