Sample_master104.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. <!-- 采样表格
  2. 返回数据示例
  3. {
  4. "id": "24577",
  5. "name": "A相电压",
  6. "offset": 0,
  7. "value": null,
  8. "occur": null,
  9. "iec104": 24577,
  10. "modbus": 40001,
  11. "range": "HOLDING_REGISTER"
  12. },
  13. 无法分页 采样表格无法分页,数据在内存中
  14. 微信聊天记录 边缘代理2开发沟通 - 2023-06-27 采样表格无法分页,数据在内存中
  15. -->
  16. <template>
  17. <div class="table-container">
  18. <!-- 采样模块 -->
  19. <div class="device-values">
  20. <!-- 采样 -->
  21. <div class="title-container">
  22. <div class="title-main">采样值</div>
  23. <div class="title-right">
  24. <div class="check-resaults">
  25. <el-button
  26. icon="el-icon-refresh-left"
  27. class="light-button"
  28. size="mini"
  29. @click="refreshManual(true)"
  30. >刷新</el-button>
  31. </div>
  32. <div class="check-resaults">
  33. <!-- 导入即是上传文件 -->
  34. <el-upload
  35. ref="upload"
  36. :action="importCsvActionStr"
  37. :show-file-list="false"
  38. :auto-upload="false"
  39. accept=".csv"
  40. :on-change="submitUpload"
  41. >
  42. <el-button
  43. class="light-button"
  44. icon="el-icon-upload2"
  45. size="mini"
  46. >导入</el-button>
  47. </el-upload>
  48. </div>
  49. <div class="check-resaults">
  50. <el-button
  51. class="light-button"
  52. icon="el-icon-download"
  53. size="mini"
  54. @click="getPlanExport"
  55. >导出</el-button>
  56. </div>
  57. <div class="check-resaults">
  58. <el-button
  59. icon="el-icon-plus"
  60. type="primary"
  61. size="mini"
  62. :disabled="componentParames.isDisable"
  63. @click="editRow()"
  64. >添加</el-button>
  65. </div>
  66. <div class="check-resaults" style="margin-left: 20px;">
  67. <el-button
  68. icon="el-icon-postcard"
  69. :type="cardModelTag"
  70. size="mini"
  71. @click="swicthCardModel(true)"
  72. >卡片</el-button>
  73. </div>
  74. <div class="check-resaults">
  75. <el-button
  76. icon="el-icon-s-grid"
  77. size="mini"
  78. :type="tableModelTag"
  79. @click="swicthCardModel(false)"
  80. >列表</el-button>
  81. </div>
  82. </div>
  83. </div>
  84. <!-- 采样卡片 -->
  85. <div v-if="showCard == true" class="table-container">
  86. <div v-for="(item, index) in carddata" :key="index">
  87. <div class="card">{{ item }}</div>
  88. </div>
  89. </div>
  90. <!-- 采样表格 -->
  91. <div v-if="showCard == false" class="table-container">
  92. <el-table :key="tableIsUpdate" v-loading="vLoading" :data="tableData" stripe max-height="300">
  93. <el-table-column prop="iec104" label="104点号" width="100px" />
  94. <el-table-column prop="name" label="测点名称" />
  95. <el-table-column prop="groupingName" label="设备名称" />
  96. <el-table-column prop="rangeName" label="点号类型" width="175px">
  97. <template slot-scope="scope">
  98. <span class="range">{{ scope.row.rangeName }}</span>
  99. </template>
  100. </el-table-column>
  101. <el-table-column prop="offset" label="点号" width="100px" />
  102. <el-table-column prop="value" label="值" width="100px" />
  103. <el-table-column prop="occur" label="时间" width="175px" />
  104. <el-table-column fixed="right" label="操作" width="250px">
  105. <template slot-scope="scope">
  106. <el-button
  107. v-if="scope.row.range=='COIL_STATUS' && scope.row.relationTag!=''"
  108. class="table-act"
  109. type="text"
  110. icon="el-icon-setting"
  111. size="small"
  112. @click="editRow(scope.$index)"
  113. >遥控操作</el-button>
  114. <el-button
  115. v-if="scope.row.range=='COIL_SHOLDING_REGISTERTATUS' && scope.row.relationTag!=''"
  116. class="table-act"
  117. type="text"
  118. icon="el-icon-edit"
  119. size="small"
  120. @click="editRow(scope.$index)"
  121. >遥调操作</el-button>
  122. <el-button
  123. class="table-act"
  124. type="text"
  125. icon="el-icon-edit"
  126. size="small"
  127. @click="editRow(scope.$index)"
  128. >编辑</el-button>
  129. <el-button
  130. class="table-act"
  131. type="text"
  132. icon="el-icon-delete"
  133. size="small"
  134. @click="delRow(scope.$index)"
  135. >删除</el-button>
  136. <el-button
  137. class="table-act"
  138. type="text"
  139. icon="el-icon-data-line"
  140. size="small"
  141. @click="sampleEchart(scope.row)"
  142. >曲线</el-button>
  143. </template>
  144. </el-table-column>
  145. <!-- 隐藏 列 这里不用显示,但是在编辑的时候需要获取此数据 -->
  146. <el-table-column
  147. v-if="false"
  148. prop="deviceCheckId"
  149. label="序号"
  150. />
  151. <!-- 隐藏 列 -->
  152. </el-table>
  153. </div>
  154. <!-- 采样分页
  155. <div class="page-bar">
  156. <pagination
  157. background
  158. layout="pager"
  159. :limit="tablePrames.pageLimit"
  160. :total="tablePrames.paginationTotalElements"
  161. :current-page.sync="tablePrames.paginationNumber"
  162. @pagination="getTableData"
  163. />
  164. </div>
  165. -->
  166. </div>
  167. <!-- 添加/编辑 采样 model -->
  168. <ModelFormSample
  169. v-if="showModelForm"
  170. :model-parames="{
  171. 'curPlanId':componentParames.curPlanId,
  172. 'productId':componentParames.productId,
  173. 'deviceName':componentParames.deviceName,
  174. 'curSuiteId':componentParames.curSuiteId,
  175. 'modelFormData':modelFormData
  176. }"
  177. :sample-data="tableData"
  178. @toggleModel="closeModel"
  179. />
  180. <!-- #TODO: 以后做成公用 dialog ,不再使用 toggleModel 关闭 dialog -->
  181. <el-dialog
  182. :visible="showEchart"
  183. :before-close="closeSampleEchart"
  184. :title="curPointName"
  185. >
  186. <!-- 采样 曲线 model -->
  187. <ModelSampleEchart
  188. v-if="showEchart"
  189. :model-parames="{
  190. 'curPlanId':componentParames.curPlanId,
  191. 'curPointId':curPointId,
  192. 'curPointName':curPointName
  193. }"
  194. />
  195. </el-dialog>
  196. </div>
  197. </template>
  198. <script>
  199. import {
  200. httpGet,
  201. delRecord,
  202. download
  203. } from '@/api/common-action'
  204. // 分页
  205. // import Pagination from '@/components/Pagination'
  206. // 显示采样曲线
  207. import ModelSampleEchart from '../components/ModelSampleEchart'
  208. // 添加/编辑 采样
  209. import ModelFormSample from '../components/ModelFormSample'
  210. // 导入总线
  211. import { EventBus } from '@/main.js'
  212. export default {
  213. name: 'Sample',
  214. components: {
  215. // Pagination,
  216. ModelSampleEchart,
  217. ModelFormSample
  218. },
  219. props: {
  220. componentParames: {
  221. type: Object,
  222. default: function() {
  223. return {}
  224. }
  225. }
  226. },
  227. data() {
  228. return {
  229. vLoading: true,
  230. showCard: true, // 卡片显示模式。false时为表格显示模式
  231. cardModelTag: 'primary',
  232. tableModelTag: 'default',
  233. carddata: [],
  234. tableData: [],
  235. // 采样
  236. tablePrames: {
  237. pageLimit: 5,
  238. paginationNumber: 1,
  239. paginationTotalElements: 1
  240. },
  241. // 是否显示 添加/编辑 采样
  242. showModelForm: false,
  243. // 是否显示曲线
  244. showEchart: false,
  245. // 当前采样id
  246. curPointId: '0',
  247. // 当前采样名称
  248. curPointName: '0',
  249. // 导入csv 请求参数
  250. importCsvActionStr: '#',
  251. // 表格是否更新标示,用于解决表格内数据变化了不会刷新的问题
  252. tableIsUpdate: '0'
  253. }
  254. },
  255. // watch: {
  256. // componentParames: {
  257. // handler() {
  258. // // 监听传入的值 是否有变化 ,如有 刷新表格数据
  259. // // console.log('刷新表格数据 componentParames')
  260. // // this.refreshTableData()
  261. // }
  262. // }
  263. // },
  264. created() {
  265. const envUrl = process.env.VUE_APP_BASE_API
  266. // 网页加载完成后执行
  267. // 接口 导入测点 /test/plan/:plan/points.csv
  268. this.importCsvActionStr = envUrl + `/test/plan/${this.componentParames.curPlanId}/points.csv`
  269. // console.log('this.importCsvActionStr=', this.importCsvActionStr)
  270. // 在bus上挂载刷新事件
  271. EventBus.$on('refreshManualSample', this.refreshManual)
  272. },
  273. mounted() {
  274. this.$nextTick(() => {
  275. // 网页加载完成后执行
  276. this.initFunctions()
  277. })
  278. },
  279. methods: {
  280. swicthCardModel(flag) {
  281. this.showCard = flag
  282. if (flag) {
  283. this.cardModelTag = 'primary'
  284. this.tableModelTag = 'default'
  285. } else {
  286. this.cardModelTag = 'default'
  287. this.tableModelTag = 'primary'
  288. }
  289. },
  290. //
  291. async initFunctions() {
  292. // 所有需要加载时初始化的函数都放这里
  293. // 获取用例列表数据 ,不传分页信息,即采集默认分页获取第一页数据
  294. this.getTableData()
  295. },
  296. // 导出
  297. async getPlanExport() {
  298. // 接口 导出测点 /test/plan/:plan/points.csv
  299. download(`/test/plan/${this.componentParames.curPlanId}/points.csv`).then(res => {
  300. const link = document.createElement('a')
  301. const blob = new Blob([res], {
  302. type: 'application/vnd.ms-excel;charset=utf-8'
  303. })
  304. link.style.display = 'none'
  305. link.href = URL.createObjectURL(blob)
  306. link.setAttribute('download', `导出采样数据-${this.componentParames.curPlanId}.csv`)
  307. document.body.appendChild(link)
  308. link.click()
  309. document.body.removeChild(link)
  310. })
  311. },
  312. // 格式化bool值
  313. formatBool(val) {
  314. const rs = val.not.toString()
  315. return rs
  316. },
  317. // 格式化 测试状态
  318. formatState(val) {
  319. return '未获取'
  320. },
  321. // 获取采样表格数据
  322. getTableData(pageObj) {
  323. this.vLoading = true
  324. pageObj = pageObj || {
  325. page: 0,
  326. limit: this.tablePrames.pageLimit
  327. }
  328. // 获取表格数据
  329. // 接口 采样数据查询 /test/execute/:runner/values
  330. // :runner 例:3200000208
  331. httpGet(`/test/execute/${this.componentParames.curPlanId}/values?page=${pageObj.page}&size=${pageObj.limit}`).then((response) => {
  332. this.vLoading = false
  333. delete response.code
  334. this.tableData = response
  335. this.tablePrames.paginationTotalElements = response.totalElements * 1
  336. // this.requestData.deviceProtocolOptions = response
  337. // 刷新一次状态
  338. this.refreshManual(false)
  339. })
  340. },
  341. // 编辑
  342. editRow(index) {
  343. // console.log('this.tableData[index]=', this.tableData[index].id)
  344. // 如果是添加,则index为空,modelFormData也为空
  345. this.modelFormData = this.tableData[index]
  346. this.showModelForm = true
  347. },
  348. // 删除
  349. delRow(index) {
  350. this.$confirm(
  351. '此操作将永久删除该记录, 是否继续?',
  352. `删除`,
  353. {
  354. confirmButtonText: '确定',
  355. cancelButtonText: '取消',
  356. type: 'warning'
  357. }
  358. )
  359. .then(() => {
  360. // console.log('delRow index=', index)
  361. // 接口 删除测点 /product/model/:product/:tag
  362. // :product 1100000645
  363. // :tag 6386 tag id 为采样列表序号id
  364. const delUrl = `/product/model/${this.componentParames.productId}/${this.tableData[index].id}`
  365. // console.log('delRow delUrl=', delUrl)
  366. delRecord(delUrl).then(res => {
  367. this.$message({
  368. message: '删除成功',
  369. type: 'success',
  370. offset: window.screen.height / 3
  371. })
  372. // 后端成功执行后,前端再删除选中行
  373. this.tableData.splice(index, 1)
  374. })
  375. })
  376. .catch(() => {
  377. this.$message({
  378. type: 'info',
  379. message: '已取消删除',
  380. offset: window.screen.height / 3
  381. })
  382. })
  383. },
  384. // 采样值数据获取
  385. // 手动刷新时,通过models接口获取实时数据信息
  386. // isHand: 是否手动刷新。false表示自动触发 true表示界面刷新按钮操作
  387. refreshManual(isHand) {
  388. // 默认接口 采样数据(高频刷新) /test/execute/:runner/models
  389. var getUrl = `/test/execute/${this.componentParames.curPlanId}/models`
  390. httpGet(getUrl).then(res => {
  391. if (this.tableData.length > 0) {
  392. this.tableData.forEach(item => {
  393. res.forEach(ritem => {
  394. if (item.id === ritem.id) {
  395. item.value = ritem.value
  396. item.occur = ritem.occur
  397. // 解决tableData无法刷新的问题
  398. this.tableIsUpdate = 'sample-' + new Date().getTime()
  399. }
  400. })
  401. })
  402. }
  403. if (isHand != null && isHand) {
  404. this.$message({
  405. message: '采样值刷新成功',
  406. type: 'success',
  407. duration: 500,
  408. offset: window.screen.height / 3
  409. })
  410. }
  411. // console.log('this.tableData', this.tableData)
  412. })
  413. },
  414. // 导入
  415. submitUpload() {
  416. // 上传文件
  417. this.$refs.upload.submit()
  418. // 上传之后刷新页面查看上传结果
  419. this.getTableData()
  420. },
  421. // 关闭 model
  422. closeModel(modelName, modelShow) {
  423. // console.log('closeModel modelName=', modelName)
  424. // console.log('closeModel modelShow=', modelShow)
  425. switch (modelName) {
  426. // case 'ModelAddStep':
  427. // this.deviceDetail.showModelAddStep = modelShow
  428. // break
  429. case 'ModelFormSample':
  430. this.showModelForm = modelShow
  431. // 操作过用例模态框 刷新一次表格数据
  432. this.getTableData()
  433. break
  434. case 'ModelSampleEchart':
  435. this.showEchart = modelShow
  436. break
  437. default:
  438. console.log('未获取到 modelName')
  439. break
  440. }
  441. },
  442. // 曲线
  443. sampleEchart(row) {
  444. // 接口 /test/execute/:runner/point/:point/chart?period=pt4h
  445. // :runner 示例 3200000235
  446. // :point 示例 24755
  447. // const getUrl = `/test/execute/${this.componentParames.curPlanId}/point/0/chart?period=pt4h`
  448. // httpGet(getUrl).then(res => {
  449. // // const sampleEchartData = {
  450. // // xAxis: res.xAxis[0],
  451. // // yAxis: res.yAxis[0],
  452. // // series: res.series[0]
  453. // // }
  454. // // const sampleEchartData = {
  455. // // xAxis: { type: 'category', min: '2023-06-14 06:52:46', max: '2023-06-14 10:52:46' },
  456. // // yAxis: res.yAxis[0],
  457. // // series: { data: [820, 932, 901, 934, 1290, 1330, 1320], type: 'line' }
  458. // // }
  459. // const sampleEchartData = res
  460. // const chart = this.$refs.chart
  461. // const myChart = echarts.init(chart)
  462. // myChart.setOption(sampleEchartData)
  463. // // window.addEventListener('resize', function() {
  464. // // myChart.resize()
  465. // // })
  466. // // this.$on('hook:destroyed', () => {
  467. // // window.removeEventListener('resize', function() {
  468. // // myChart.resize()
  469. // // })
  470. // // })
  471. // console.log('sampleEchart 数据获取成功 res=', res)
  472. // console.log('sampleEchart 数据获取成功 sampleEchartData=', sampleEchartData)
  473. // })
  474. // console.log('sampleEchart started 展示方式待定', row.id)
  475. this.curPointId = row.id
  476. this.curPointName = row.name
  477. this.showEchart = true
  478. },
  479. // 关闭Echart弹窗
  480. closeSampleEchart() {
  481. this.showEchart = false
  482. }
  483. }
  484. }
  485. </script>
  486. <style lang="scss" scoped>
  487. .card{
  488. float: left;
  489. width: 10rem;
  490. height: 5rem;
  491. border-radius: 5px;
  492. border: 1px solid #ccc;
  493. }
  494. .card_opt{
  495. background-color: #ededed;
  496. }
  497. .title-container {
  498. display: flex;
  499. justify-content: space-between;
  500. padding: 20px 0;
  501. .title-right {
  502. display: flex;
  503. align-items: center;
  504. .check-resaults {
  505. padding-right: 16px;
  506. .success {
  507. color: #00706b;
  508. }
  509. .faild {
  510. color: #f00;
  511. padding-right: 6px;
  512. }
  513. span {
  514. font-weight: bold;
  515. }
  516. }
  517. }
  518. }
  519. .title-main {
  520. color: #111;
  521. font-weight: bold;
  522. }
  523. // 用例表格样式
  524. .table-container {
  525. // padding: 20px 0;
  526. .el-table {
  527. font-size: 12px;
  528. }
  529. .range {
  530. white-space: nowrap;
  531. }
  532. }
  533. // 底部按钮
  534. .bottom-button {
  535. display: flex;
  536. justify-content: center;
  537. padding-bottom: 20px;
  538. .cancel-plan {
  539. padding-right: 20px;
  540. }
  541. }
  542. // 按钮公用样式
  543. .dark-button {
  544. background-color: #00706B;
  545. border: 1px #00706B solid;
  546. color: #fff;
  547. }
  548. .light-button {
  549. color: #00706B;
  550. border: 1px #00706B solid;
  551. }
  552. </style>