Data.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <template>
  2. <div class="realtime-data" style="height: auto">
  3. <navigation-name :msg="companyName" show-time show-other>
  4. <div style="margin-left: 20px;">
  5. <el-select
  6. v-model="localAcquisitionStationId"
  7. popper-class="jg-select"
  8. :popper-append-to-body="false"
  9. placeholder="采集站数据"
  10. @change="changeAcquisitionStation"
  11. >
  12. <el-option
  13. v-for="(item, index) in acquisitionStationList"
  14. :key="index"
  15. :label="item.name"
  16. :value="item.id"/>
  17. </el-select>
  18. </div>
  19. </navigation-name>
  20. <div style="font-weight: bolder;font-size: 30px;padding-top: 16px;text-align: center">
  21. {{ factoryName }}
  22. <!--数据显示-->
  23. </div>
  24. <br/>
  25. <!-- <div>{{ tableLoading }}</div>-->
  26. <el-table
  27. :data="tableData"
  28. height="100%"
  29. :span-method="objectSpanMethod"
  30. :header-cell-style="{
  31. background: '#BFBFBF',
  32. boxShadow: 'inset grey 0px -1px',
  33. color: '#333333',
  34. borderColor: '#eaeaea',
  35. fontSize: '20px',
  36. }"
  37. :cell-style="{
  38. background: '#f6f5f5',
  39. color: '#333333',
  40. borderColor: '#eaeaea',
  41. fontSize: '18px',
  42. cursor: 'pointer',
  43. }"
  44. @row-click="rowClick"
  45. row-key="id"
  46. border
  47. stripe
  48. style="width: 100%; background-color: inherit;min-height: 820px;">
  49. <el-table-column
  50. v-for="(item, index) in tableColumns"
  51. :key="index"
  52. :column-key="item.prop"
  53. :label="item.label"
  54. :width="item.width"
  55. :class-name="item.className"
  56. :align="item.align ? item.align : 'center'"
  57. >
  58. <template slot-scope="scope">
  59. <div v-if="item.prop === 'status'" style="display: flex;justify-content: center">
  60. <div v-if="scope.row[item.prop] === 1" style="display: flex;align-items: center;">
  61. <div style="height: 16px;width: 16px;border-radius: 50%;background-color: #5daf34"/>
  62. <div style="margin-left: 16px">正在运行</div>
  63. </div>
  64. <div v-else-if="scope.row[item.prop] === 0" style="display: flex;align-items: center;">
  65. <div style="height: 16px;width: 16px;border-radius: 50%;background-color: #f1092b"/>
  66. <div style="margin-left: 16px">停止运行</div>
  67. </div>
  68. <div v-else-if="scope.row[item.prop] === -1" style="display: flex;align-items: center;">
  69. <div style="height: 16px;width: 16px;border-radius: 50%;background-color: #0930f1"/>
  70. <div style="margin-left: 16px">RTU模块连接异常</div>
  71. </div>
  72. </div>
  73. <div v-else>{{ scope.row[item.prop] }}</div>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <position-modal ref="positionModal" :message="realtimeData"/>
  78. </div>
  79. </template>
  80. <script>
  81. import NavigationName from '@/components/NavigationName'
  82. import PositionModal from '@/components/PositionModal'
  83. import { mapState, mapMutations } from 'vuex'
  84. import { findEntityByAcqId } from '@/api/CollectEntity'
  85. import { findColumnsByTableName } from '@/api/TableConfig'
  86. import { findAll, updateAcquisitionStation } from '@/api/AcquisitionStation'
  87. export default {
  88. name: 'Data',
  89. components: {
  90. PositionModal,
  91. NavigationName
  92. },
  93. data() {
  94. return {
  95. tableColumns: [],
  96. tableDataWrapper: [],
  97. acquisitionStationList: [],
  98. localAcquisitionStationId: null,
  99. }
  100. },
  101. mounted () {
  102. this.fetchData()
  103. },
  104. watch: {
  105. acquisitionStationId: {
  106. handler(newVal) {
  107. this.localAcquisitionStationId = newVal
  108. },
  109. immediate: true
  110. }
  111. },
  112. computed: {
  113. ...mapState({
  114. clientCode: (state, getter) => state.company.clientCode,
  115. companyName: (state, getter) => state.company.companyName,
  116. factoryName: (state, getter) => state.company.factoryName,
  117. realtimeData: (state, getter) => state.queue.realtimeData,
  118. acquisitionStationId: state => state.company.acquisitionStationId,
  119. }),
  120. tableData() {
  121. const tableDataWrapper = this.tableDataWrapper
  122. if (this.realtimeData) {
  123. for (const item of tableDataWrapper) {
  124. for (const msg of this.realtimeData) {
  125. if (msg.collectEntityId === item.id + '') {
  126. item[msg.tableColumn] = msg.value
  127. }
  128. }
  129. item.status = item.FEEDBACK
  130. }
  131. return tableDataWrapper
  132. } else {
  133. return []
  134. }
  135. },
  136. tableLoading() {
  137. return !this.tableData || this.tableData.length <= 0
  138. },
  139. },
  140. methods: {
  141. ...mapMutations(['SET_ACQUISITION_STATION_ID', 'SET_ACQUISITION_STATION', 'SET_WORKSHOP_NAME']),
  142. getPositionArr() {
  143. const obj = {}
  144. this.tableData.forEach(e => {
  145. if (obj[e.first]) {
  146. obj[e.first] += 1
  147. } else {
  148. obj[e.first] = 1
  149. }
  150. })
  151. const arr = []
  152. for (const key in obj) {
  153. const cc = new Array(obj[key]).fill(0)
  154. cc[0] = obj[key]
  155. arr.push(...cc)
  156. }
  157. return arr
  158. },
  159. objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  160. if (columnIndex === 0) {
  161. const rowspan = this.getPositionArr()[rowIndex]
  162. return {
  163. rowspan,
  164. colspan: 1
  165. }
  166. }
  167. },
  168. objectSpanMethod261({ row, column, rowIndex, columnIndex }) {
  169. if (columnIndex === 0) {
  170. const rowspan = this.getPositionArr()[rowIndex]
  171. return {
  172. rowspan,
  173. colspan: 1
  174. }
  175. }
  176. if (columnIndex === 1 || columnIndex === 5) {
  177. if (rowIndex === 0 || rowIndex === 3) {
  178. return {
  179. rowspan: 2,
  180. colspan: 1
  181. }
  182. }
  183. if (rowIndex === 1 || rowIndex === 4) {
  184. return {
  185. rowspan: 0,
  186. colspan: 0
  187. }
  188. }
  189. }
  190. },
  191. objectSpanMethod262({ row, column, rowIndex, columnIndex }) {
  192. if (columnIndex === 0) {
  193. const rowspan = this.getPositionArr()[rowIndex]
  194. return {
  195. rowspan,
  196. colspan: 1
  197. }
  198. }
  199. if (columnIndex === 1 || columnIndex === 5) {
  200. if (rowIndex === 0) {
  201. return {
  202. rowspan: 2,
  203. colspan: 1
  204. }
  205. }
  206. if (rowIndex === 1) {
  207. return {
  208. rowspan: 0,
  209. colspan: 0
  210. }
  211. }
  212. if (rowIndex === 2) {
  213. return {
  214. rowspan: 3,
  215. colspan: 1
  216. }
  217. }
  218. if (rowIndex === 3 || rowIndex === 4) {
  219. return {
  220. rowspan: 0,
  221. colspan: 0
  222. }
  223. }
  224. }
  225. },
  226. objectSpanMethod275({ row, column, rowIndex, columnIndex }) {
  227. if (columnIndex === 0) {
  228. const rowspan = this.getPositionArr()[rowIndex]
  229. return {
  230. rowspan,
  231. colspan: 1
  232. }
  233. }
  234. if (columnIndex === 1 || columnIndex === 5) {
  235. if (rowIndex === 1 || rowIndex === 5 || rowIndex === 7) {
  236. return {
  237. rowspan: 2,
  238. colspan: 1
  239. }
  240. }
  241. if (rowIndex === 2 || rowIndex === 6 || rowIndex === 8) {
  242. return {
  243. rowspan: 0,
  244. colspan: 0
  245. }
  246. }
  247. }
  248. },
  249. rowClick(row, column, event) {
  250. // console.log(row, column, event)
  251. let entity = {}
  252. for (const e of this.tableDataWrapper) {
  253. if (e.id === row.id) {
  254. entity = { ...row }
  255. }
  256. }
  257. this.$refs.positionModal.showModal(row.id, entity)
  258. },
  259. async fetchData() {
  260. await findAll().then(res => {
  261. this.acquisitionStationList = res.data
  262. })
  263. await findColumnsByTableName({
  264. tableName: 'Data',
  265. clientCode: this.clientCode
  266. }).then(res => {
  267. console.log('findColumnsByTableName =>', res.data)
  268. if (res && res.code === '200') {
  269. this.tableColumns = res.data
  270. } else {
  271. this.$message.error(res.message)
  272. }
  273. })
  274. await this.getCollectEntity()
  275. },
  276. getCollectEntity() {
  277. const entityParams = {
  278. acquisitionStationId: this.acquisitionStationId
  279. }
  280. findEntityByAcqId(entityParams).then(res => {
  281. console.log('findEntityByAcqId =>', res.data)
  282. // 按照实体分类, 对应第二列
  283. const tableDataWrapper = []
  284. handleData(tableDataWrapper, res.data)
  285. setOperate275(tableDataWrapper)
  286. this.tableDataWrapper = tableDataWrapper
  287. })
  288. const handleData = (dataArr, data) => {
  289. for (const item of data) {
  290. const obj = {
  291. id: item.id,
  292. first: item.acquisitionStationName,
  293. second: item.entityName,
  294. startType: item.startType,
  295. limitValue: item.limitValue,
  296. tagList: item.collectEntityTagVoList,
  297. }
  298. if (item.collectEntityTagVoList && item.collectEntityTagVoList.length > 0) {
  299. for (const e of item.collectEntityTagVoList) {
  300. obj[e.tableColumn] = '0.9'
  301. }
  302. dataArr.push(obj)
  303. }
  304. }
  305. }
  306. const setOperate275 = tableDataWrapper => {
  307. tableDataWrapper.forEach((tableData, index) => {
  308. switch (index) {
  309. case 0:
  310. tableData.remark = '硝化一间'
  311. break
  312. case 1:
  313. tableData.remark = '硝化二间'
  314. break
  315. case 3:
  316. tableData.remark = '转晶一间'
  317. break
  318. case 4:
  319. tableData.remark = '转晶二间'
  320. break
  321. case 5:
  322. tableData.remark = '球形一间'
  323. break
  324. case 7:
  325. tableData.remark = '球形二间'
  326. break
  327. default:
  328. break
  329. }
  330. })
  331. }
  332. const setOperate262 = tableDataWrapper => {
  333. tableDataWrapper.forEach((tableData, index) => {
  334. switch (index) {
  335. case 0:
  336. tableData.remark = '东间'
  337. break
  338. case 2:
  339. tableData.remark = '西间'
  340. break
  341. default:
  342. break
  343. }
  344. })
  345. }
  346. const setOperate261 = tableDataWrapper => {
  347. tableDataWrapper.forEach((tableData, index) => {
  348. switch (index) {
  349. case 0:
  350. tableData.remark = '硝化一间'
  351. break
  352. case 2:
  353. tableData.remark = '硝化二间'
  354. break
  355. case 3:
  356. tableData.remark = '转晶一间'
  357. break
  358. case 5:
  359. tableData.remark = '转晶二间'
  360. break
  361. default:
  362. break
  363. }
  364. })
  365. }
  366. },
  367. async changeAcquisitionStation(acquisitionStationId) {
  368. console.log('切换采集站', acquisitionStationId)
  369. this.SET_ACQUISITION_STATION_ID(acquisitionStationId)
  370. const params = {
  371. id: acquisitionStationId,
  372. status: 1
  373. }
  374. await updateAcquisitionStation(params).then(res => {
  375. this.getCollectEntity()
  376. this.SET_ACQUISITION_STATION(res.data)
  377. this.SET_WORKSHOP_NAME(res.data.name)
  378. })
  379. },
  380. },
  381. }
  382. </script>
  383. <style lang="less" scoped>
  384. .realtime-data {
  385. padding: 0 40px;
  386. height: 80vh;
  387. .el-table {
  388. box-shadow: 1px 1px 1px #BFBFBF, -1px -1px -1px #666666;
  389. }
  390. /deep/ .el-table .cell {
  391. white-space: pre-line;
  392. }
  393. .el-table--border, .el-table--group {
  394. border-radius: 10px;
  395. }
  396. /deep/ .el-table__row {
  397. .first-column {
  398. background-color: #d9d9d9 !important;
  399. box-shadow: inset #BFBFBF -1px -1px;
  400. cursor: default;
  401. // 取消点击事件
  402. pointer-events: none;
  403. }
  404. }
  405. /deep/ .el-dialog {
  406. position: relative;
  407. margin: 0 !important;
  408. background: #FFF;
  409. border-radius: 2px;
  410. box-shadow: 0 1px 3px rgb(0 0 0 / 30%);
  411. box-sizing: border-box;
  412. width: 50%;
  413. height: 100%;
  414. }
  415. }
  416. /deep/ .el-input__inner {
  417. background-color: #ebebeb;
  418. box-shadow: inset 0.1rem 0.1rem 0.1rem #AAA7A7, inset -0.1rem -0.1rem 0.1rem #FFFFFF;
  419. border: none;
  420. font-size: 16px;
  421. color: #666666;
  422. }
  423. /deep/ .el-input-group__append, .el-input-group__prepend {
  424. background-color: transparent;
  425. font-size: 14px;
  426. box-shadow: 0.1rem 0.1rem 0.1rem #aaa7a7, -0.05rem -0.05rem 0.05rem #FFFFFF;
  427. color: #333333;
  428. border: none;
  429. border-radius: 4px;
  430. padding: 0 10px;
  431. width: 1px;
  432. white-space: nowrap;
  433. }
  434. /deep/ .jg-select {
  435. padding: 10px;
  436. background-color: #ebebeb;
  437. box-shadow: 0.1rem 0.1rem 0.1rem #AAA7A7, -0.1rem -0.1rem 0.1rem #FFFFFF;
  438. .el-select-dropdown__item {
  439. box-shadow: 0.1rem 0.1rem 0.1rem #AAA7A7, -0.1rem -0.1rem 0.1rem #FFFFFF;
  440. margin: 8px 3px;
  441. border-radius: 5px;
  442. }
  443. }
  444. /deep/ .el-select-dropdown__item.selected {
  445. font-weight: normal;
  446. color: #FFFFFF;
  447. background-color: #A20D13;
  448. border-radius: 5px;
  449. box-shadow: inset 0.2rem 0.2rem 0.5rem #6E090C, inset -0.2rem -0.2rem 0.5rem #C71016;
  450. }
  451. /deep/ .popper__arrow {
  452. display: none;
  453. }
  454. </style>