GroupMonitorTable.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <div class="vent-table">
  3. <a-radio-group v-model:value="selectRowIndex" @change="setSelectedRowKeys" style="width: 100%">
  4. <a-table :columns="columns" :pagination="false" :data-source="dataTableSource" bordered style="margin-top: 5px" :scroll="scroll">
  5. <template #bodyCell="{ column, record }">
  6. <template v-if="column.dataIndex === 'isCheck'">
  7. <a-radio :value="record.deviceID" />
  8. </template>
  9. <a-tag v-if="column.dataIndex === 'warnFlag'" :color="record.warnFlag == 0 ? 'green' : 'red'">{{
  10. record.warnFlag == 0 ? '正常' : '报警'
  11. }}</a-tag>
  12. <a-tag v-if="column.dataIndex === 'netStatus'" :color="record.netStatus == 0 ? 'default' : 'green'">{{
  13. record.netStatus == 0 ? '断开' : '连接'
  14. }}</a-tag>
  15. </template>
  16. </a-table>
  17. </a-radio-group>
  18. </div>
  19. </template>
  20. <script lang="ts" setup>
  21. //ts语法
  22. import { toRaw, watch, ref, onMounted, onUnmounted } from 'vue';
  23. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  24. const props = defineProps({
  25. columnsType: {
  26. type: String,
  27. required: true,
  28. },
  29. dataSource: {
  30. type: Array,
  31. required: true,
  32. },
  33. deviceType: {
  34. type: String,
  35. },
  36. designScope: {
  37. type: String,
  38. },
  39. title: {
  40. type: String,
  41. },
  42. scroll: {
  43. type: Object,
  44. default: () => null
  45. },
  46. });
  47. const emits = defineEmits(['selectRow']);
  48. const dataTableSource = ref<any[]>([]);
  49. const loading = ref(true);
  50. // 默认初始是第一行
  51. const selectRowIndex = ref(0);
  52. const setSelectedRowKeys = (target) => {
  53. console.log(target, Object.prototype.toString.call(target));
  54. if (Object.prototype.toString.call(target) === '[object String]') {
  55. selectRowIndex.value = target;
  56. emits('selectRow', target);
  57. } else if (Object.prototype.toString.call(target) === '[object Object]') {
  58. const data = target.target.value;
  59. selectRowIndex.value = data;
  60. emits('selectRow', data);
  61. }
  62. };
  63. /** 定义table Columns */
  64. function setColumns() {
  65. const isCheckColumn = {
  66. title: '',
  67. dataIndex: 'isCheck',
  68. width: 60,
  69. align: 'center',
  70. customCell: (_, index) => {
  71. if (index % 2 == 0) {
  72. return { rowSpan: 2 };
  73. } else {
  74. return { rowSpan: 0 };
  75. }
  76. },
  77. };
  78. const runDevice = {
  79. title: '运行风机',
  80. dataIndex: 'runDevice',
  81. width: 80,
  82. align: 'center',
  83. };
  84. let columns: any[] = getTableHeaderColumns(props.columnsType);
  85. const strinstallpos = columns.find((item) => {
  86. return item.dataIndex === 'strinstallpos' || item.dataIndex === 'strname';
  87. });
  88. if (strinstallpos) {
  89. strinstallpos.customCell = (_, index) => {
  90. if (index % 2 == 0) {
  91. return { rowSpan: 2 };
  92. } else {
  93. return { rowSpan: 0 };
  94. }
  95. };
  96. }
  97. columns.splice(1, 0, runDevice);
  98. columns = [isCheckColumn, ...columns];
  99. return columns;
  100. }
  101. const columns = setColumns();
  102. console.log('[ columns ] >', columns);
  103. watch(
  104. () => {
  105. return props.dataSource;
  106. },
  107. (newVal, oldVal) => {
  108. const list: unknown[] = [];
  109. newVal.forEach((item) => {
  110. const data: any = toRaw(item);
  111. const resultData1 = {};
  112. const resultData2 = {};
  113. // 将主风机、备风机的数据进行拆分
  114. columns.forEach((column) => {
  115. const columnKey = column.dataIndex;
  116. // data.f
  117. if (columnKey.startsWith('Fan')) {
  118. const key1 = columnKey.replace('Fan', 'Fan1');
  119. const key2 = columnKey.replace('Fan', 'Fan2');
  120. resultData1[columnKey] = data[key1];
  121. resultData2[columnKey] = data[key2];
  122. } else {
  123. resultData1[columnKey] = resultData2[columnKey] = data[columnKey];
  124. }
  125. });
  126. resultData1['deviceID'] = resultData2['deviceID'] = data['deviceID'];
  127. resultData1['runDevice'] = '主机';
  128. resultData2['runDevice'] = '备机';
  129. list.push(resultData1, resultData2);
  130. // const emptyData = new Object();
  131. // for (const key in data) {
  132. // if (
  133. // Object.prototype.hasOwnProperty.call(data, key) &&
  134. // key !== 'deviceID' &&
  135. // key !== 'Fan1StartStatus' &&
  136. // key !== 'Fan2StartStatus' &&
  137. // key !== 'strinstallpos' &&
  138. // key !== 'readTime'
  139. // ) {
  140. // emptyData[key] = '-';
  141. // } else {
  142. // emptyData[key] = data[key];
  143. // }
  144. // }
  145. // if (data.Fan1StartStatus == 1) {
  146. // // 主风机启动
  147. // data['runDevice'] = '主机';
  148. // emptyData['runDevice'] = '备机';
  149. // list.push(data, emptyData);
  150. // } else if (data.Fan2StartStatus == 1) {
  151. // // 备风机启动
  152. // data['runDevice'] = '备机';
  153. // emptyData['runDevice'] = '主机';
  154. // list.push(emptyData, data);
  155. // } else {
  156. // list.push({ ...emptyData, runDevice: '主机' }, { ...emptyData, runDevice: '备机' });
  157. // }
  158. });
  159. if (oldVal.length < 1) {
  160. // 第一次
  161. setSelectedRowKeys(list[0]['deviceID']);
  162. }
  163. dataTableSource.value = list;
  164. loading.value = false;
  165. }
  166. );
  167. onMounted(() => {
  168. // 如果是https
  169. // 反之是websocket
  170. });
  171. onUnmounted(() => {});
  172. </script>
  173. <style scoped lang="less">
  174. @ventSpace: zxm;
  175. :deep(.@{ventSpace}-table-body) {
  176. height: auto !important;
  177. }
  178. :deep(.jeecg-basic-table .@{ventSpace}-table-wrapper .@{ventSpace}-table-title) {
  179. min-height: 0;
  180. }
  181. </style>