GroupMonitorTable.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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">
  5. <template #bodyCell="{ column, record, index }">
  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 { defineExpose, 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. });
  43. const emits = defineEmits(['selectRow']);
  44. const dataTableSource = ref<any[]>([]);
  45. const loading = ref(true);
  46. // 默认初始是第一行
  47. const selectRowIndex = ref(0);
  48. watch(
  49. () => {
  50. return props.dataSource;
  51. },
  52. (newVal, oldVal) => {
  53. const list: unknown[] = [];
  54. newVal.forEach((item) => {
  55. const data: any = toRaw(item);
  56. const emptyData = new Object();
  57. for (const key in data) {
  58. if (
  59. Object.prototype.hasOwnProperty.call(data, key) &&
  60. key !== 'deviceID' &&
  61. key !== 'fanStart1' &&
  62. key !== 'fanStart2' &&
  63. key !== 'strinstallpos' &&
  64. key !== 'readTime'
  65. ) {
  66. emptyData[key] = '-';
  67. } else {
  68. emptyData[key] = data[key];
  69. }
  70. }
  71. if (data.fanStart1 == 1) {
  72. // 主风机启动
  73. data['runDevice'] = '主机';
  74. emptyData['runDevice'] = '备机';
  75. list.push(data, emptyData);
  76. } else if (data.fanStart2 == 1) {
  77. // 备风机启动
  78. data['runDevice'] = '备机';
  79. emptyData['runDevice'] = '主机';
  80. list.push(emptyData, data);
  81. } else {
  82. list.push({ ...emptyData, runDevice: '主机' }, { ...emptyData, runDevice: '备机' });
  83. }
  84. });
  85. if (oldVal.length < 1) {
  86. // 第一次
  87. if (list[0] && list[0]['fanStart1'] == 1) {
  88. setSelectedRowKeys(list[0]['deviceID']);
  89. } else if (list[1] && list[1]['fanStart2'] == 1) {
  90. setSelectedRowKeys(list[1]['deviceID']);
  91. } else if (list[0]) {
  92. setSelectedRowKeys(list[0]['deviceID']);
  93. }
  94. }
  95. dataTableSource.value = list;
  96. loading.value = false;
  97. }
  98. );
  99. const setSelectedRowKeys = (target) => {
  100. console.log(target, Object.prototype.toString.call(target));
  101. if (Object.prototype.toString.call(target) === '[object String]') {
  102. selectRowIndex.value = target;
  103. emits('selectRow', target);
  104. } else if (Object.prototype.toString.call(target) === '[object Object]') {
  105. const data = target.target.value;
  106. selectRowIndex.value = data;
  107. emits('selectRow', data);
  108. }
  109. };
  110. /** 定义table Columns */
  111. function setColumns() {
  112. const isCheckColumn = {
  113. title: '',
  114. dataIndex: 'isCheck',
  115. width: 60,
  116. align: 'center',
  117. customCell: (_, index) => {
  118. if (index % 2 == 0) {
  119. return { rowSpan: 2 };
  120. } else {
  121. return { rowSpan: 0 };
  122. }
  123. },
  124. };
  125. const runDevice = {
  126. title: '运行风机',
  127. dataIndex: 'runDevice',
  128. width: 80,
  129. align: 'center',
  130. };
  131. let columns: any[] = getTableHeaderColumns(props.columnsType);
  132. const strinstallpos = columns.find((item) => {
  133. return item.dataIndex === 'strinstallpos' || item.dataIndex === 'strname';
  134. });
  135. if (strinstallpos) {
  136. strinstallpos.customCell = (_, index) => {
  137. if (index % 2 == 0) {
  138. return { rowSpan: 2 };
  139. } else {
  140. return { rowSpan: 0 };
  141. }
  142. };
  143. }
  144. columns.splice(1, 0, runDevice);
  145. columns = [isCheckColumn, ...columns];
  146. return columns;
  147. }
  148. const columns = setColumns();
  149. console.log('[ columns ] >', columns);
  150. onMounted(() => {
  151. // 如果是https
  152. // 反之是websocket
  153. });
  154. onUnmounted(() => {});
  155. </script>
  156. <style scoped lang="less">
  157. :deep(.ant-table-body) {
  158. height: auto !important;
  159. }
  160. :deep(.jeecg-basic-table .ant-table-wrapper .ant-table-title) {
  161. min-height: 0;
  162. }
  163. </style>