ModelReport.vue 12 KB

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