MonitorTable.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <div class="vent-table">
  3. <BasicTable ref="ventTableRef" @register="registerTable" :rowSelection="props.isShowSelect ? rowSelection: undefined">
  4. <template #tableTitle>
  5. <div></div>
  6. </template>
  7. <template #tableTop>
  8. <div></div>
  9. </template>
  10. <template #bodyCell="{ column, record }">
  11. <slot name="filterCell" v-bind="{ column, record }"></slot>
  12. </template>
  13. <template #action="{ record }">
  14. <slot name="action" v-bind="{ record }"></slot>
  15. </template>
  16. </BasicTable>
  17. </div>
  18. </template>
  19. <script lang="ts" setup>
  20. //ts语法
  21. import { defineExpose, toRaw, watch, ref, onMounted, onUnmounted } from 'vue';
  22. import { BasicTable } from '/@/components/Table';
  23. import { useListPage } from '/@/hooks/system/useListPage';
  24. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  25. import { findIndex } from 'lodash-es';
  26. import { FormProps } from '/@/components/Form';
  27. const props = defineProps({
  28. columnsType: {
  29. type: String,
  30. },
  31. columns: {
  32. type: Array,
  33. // required: true,
  34. default: () => [],
  35. },
  36. dataSource: {
  37. type: Array,
  38. required: true,
  39. },
  40. deviceType: {
  41. type: String,
  42. },
  43. designScope: {
  44. type: String,
  45. },
  46. isShowSelect: {
  47. type: Boolean,
  48. default:true,
  49. },
  50. isShowPagination: {
  51. type: Boolean,
  52. default: true,
  53. },
  54. isShowActionColumn: {
  55. type: Boolean,
  56. default: false,
  57. },
  58. scroll: {
  59. type: Object,
  60. default: {y: 0}
  61. },
  62. title: {
  63. type: String,
  64. },
  65. size: {
  66. type: String,
  67. default: 'small',
  68. },
  69. formConfig: {
  70. type: Object as PropType<FormProps> | undefined,
  71. default: undefined
  72. }
  73. });
  74. const emits = defineEmits(['selectRow']);
  75. const dataTableSource = ref<any[]>([]);
  76. // const loading = ref(true);
  77. const ventTableRef = ref();
  78. const tableMaxHeight = 150;
  79. const columns = ref([])
  80. const tableScroll = props.scroll.y ? ref({y: props.scroll.y}) : ref({})
  81. watch(
  82. () => {
  83. return props.dataSource;
  84. },
  85. (newVal, oldVal) => {
  86. if (oldVal && newVal && oldVal.length < 1 && newVal.length > 0) {
  87. // 第一次
  88. if(getSelectRowKeys().length < 1) setSelectedRowKeys([newVal[0].deviceID]);
  89. }
  90. const list = <any[]>[];
  91. newVal.forEach((item) => {
  92. list.push(toRaw(item));
  93. });
  94. dataTableSource.value = list;
  95. if(ventTableRef.value) setLoading(false)
  96. },
  97. {
  98. immediate: true
  99. }
  100. );
  101. watch(
  102. () => {
  103. return props.columnsType;
  104. },
  105. (newVal) => {
  106. if(!newVal) return
  107. const column = getTableHeaderColumns(newVal)
  108. if(column && column.length < 1){
  109. const arr = newVal.split('_')
  110. const columnKey = arr.reduce((prev, cur, index) => {
  111. if(index !== arr.length - 2){
  112. return prev + '_' + cur
  113. }else {
  114. return prev
  115. }
  116. })
  117. columns.value = getTableHeaderColumns(arr[0]+'_monitor');
  118. }else{
  119. columns.value = column
  120. }
  121. },
  122. {
  123. immediate: true
  124. }
  125. );
  126. watch(() => props.scroll.y, (newVal) => {
  127. if (newVal) {
  128. tableScroll.value = { y: newVal }
  129. } else {
  130. tableScroll.value = {}
  131. }
  132. }
  133. )
  134. // 列表页面公共参数、方法
  135. const { prefixCls, tableContext, doRequest } = useListPage({
  136. designScope: props.designScope,
  137. tableProps: {
  138. title: props.title,
  139. dataSource: dataTableSource,
  140. columns: props.columnsType ? columns : (props.columns as any[]),
  141. rowSelection: { type: props.isShowSelect? 'radio': undefined, columnWidth: 100 },
  142. size: props.size,
  143. useSearchForm: props.formConfig ? true : false,
  144. showTableSetting: false,
  145. showActionColumn: props.isShowActionColumn,
  146. maxHeight: tableMaxHeight,
  147. bordered: false,
  148. scroll: tableScroll,
  149. rowKey: 'deviceID',
  150. formConfig: props.formConfig,
  151. // striped: true,
  152. loading: true,
  153. actionColumn: {
  154. width: 180,
  155. },
  156. pagination: props.isShowPagination ? {
  157. current: 1,
  158. pageSize: 5,
  159. pageSizeOptions: ['5', '10', '20'],
  160. } : false,
  161. beforeFetch: (params) => {
  162. if(props.deviceType?.startsWith('safetymonitor')){
  163. return Object.assign(params, { filterParams: {'dataTypeName': params['dataTypeName'], strinstallpos: params['strinstallpos'] } });
  164. }else{
  165. return Object.assign(params, { column: 'createTime' });
  166. }
  167. },
  168. },
  169. });
  170. //注册table数据
  171. const [registerTable, { reload, setLoading, setSelectedRowKeys, getSelectRowKeys }, { rowSelection, selectedRowKeys, }] = tableContext;
  172. watch(
  173. selectedRowKeys,
  174. (newKeys) => {
  175. console.log('设置的选中id---------->', newKeys, dataTableSource.value)
  176. const index = findIndex(dataTableSource.value, (data: any) => {
  177. return data.deviceID == selectedRowKeys.value[0];
  178. });
  179. if (index >= 0) emits('selectRow', dataTableSource.value[index], index);
  180. },
  181. { immediate: false }
  182. );
  183. defineExpose({
  184. doRequest,
  185. setSelectedRowKeys,
  186. getSelectRowKeys,
  187. setLoading,
  188. reload
  189. });
  190. onMounted(() => {
  191. // 如果是https
  192. // 反之是websocket
  193. });
  194. onUnmounted(() => {});
  195. </script>
  196. <style scoped lang="less">
  197. @ventSpace: zxm;
  198. :deep(.@{ventSpace}-table-body) {
  199. height: auto !important;
  200. tr > td {
  201. background: #ffffff00 !important;
  202. }
  203. tr.@{ventSpace}-table-row-selected {
  204. td {
  205. background: #007cc415 !important;
  206. }
  207. }
  208. }
  209. :deep(.jeecg-basic-table .@{ventSpace}-table-wrapper .@{ventSpace}-table-title) {
  210. min-height: 0;
  211. }
  212. </style>