ModelReport_master104.vue 13 KB

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