MonitorTable.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. console.log('监测列表表头000------------>', newVal)
  109. if(column && column.length < 1){
  110. const arr = newVal.split('_')
  111. const columnKey = arr.reduce((prev, cur, index) => {
  112. if(index !== arr.length - 2){
  113. return prev + '_' + cur
  114. }else {
  115. return prev
  116. }
  117. })
  118. columns.value = getTableHeaderColumns(arr[0]+'_monitor');
  119. }else{
  120. columns.value = column
  121. }
  122. },
  123. {
  124. immediate: true
  125. }
  126. );
  127. watch(() => props.scroll.y, (newVal) => {
  128. if (newVal) {
  129. tableScroll.value = { y: newVal }
  130. } else {
  131. tableScroll.value = {}
  132. }
  133. }
  134. )
  135. // 列表页面公共参数、方法
  136. const { prefixCls, tableContext, doRequest } = useListPage({
  137. designScope: props.designScope,
  138. tableProps: {
  139. title: props.title,
  140. dataSource: dataTableSource,
  141. columns: props.columnsType ? columns : (props.columns as any[]),
  142. rowSelection: { type: props.isShowSelect? 'radio': undefined, columnWidth: 100 },
  143. size: props.size,
  144. useSearchForm: props.formConfig ? true : false,
  145. showTableSetting: false,
  146. showIndexColumn: true,
  147. showActionColumn: props.isShowActionColumn,
  148. maxHeight: tableMaxHeight,
  149. bordered: false,
  150. scroll: tableScroll,
  151. rowKey: 'deviceID',
  152. formConfig: props.formConfig,
  153. // striped: true,
  154. loading: true,
  155. actionColumn: {
  156. width: 180,
  157. },
  158. pagination: props.isShowPagination ? {
  159. current: 1,
  160. pageSize: 50,
  161. pageSizeOptions: ['10', '30', '50', '100', '500'],
  162. showQuickJumper: false
  163. } : false,
  164. beforeFetch: (params) => {
  165. if(props.deviceType?.startsWith('safetymonitor')){
  166. return Object.assign(params, { filterParams: {'dataTypeName': params['dataTypeName'], strinstallpos: '*'+params['strinstallpos']+'*'} });
  167. }else if(props.deviceType?.startsWith('location')) {
  168. return Object.assign(params, { filterParams: {strinstallpos: '*'+params['strinstallpos']+'*', userName: '*'+params['strname']+'*' } });
  169. }else if(props.deviceType?.startsWith('vehicle')) {
  170. return Object.assign(params, { filterParams: {strinstallpos: '*'+params['strinstallpos']+'*', vehicleName: '*'+params['strname']+'*' } });
  171. }else{
  172. return Object.assign(params, { column: 'createTime' });
  173. }
  174. },
  175. },
  176. });
  177. //注册table数据
  178. const [registerTable, { reload, setLoading, setSelectedRowKeys, getSelectRowKeys, getForm }, { rowSelection, selectedRowKeys, }] = tableContext;
  179. watch(
  180. selectedRowKeys,
  181. (newKeys) => {
  182. console.log('设置的选中id---------->', newKeys, dataTableSource.value)
  183. const index = findIndex(dataTableSource.value, (data: any) => {
  184. return data.deviceID == selectedRowKeys.value[0];
  185. });
  186. if (index >= 0) emits('selectRow', dataTableSource.value[index], index);
  187. },
  188. { immediate: false }
  189. );
  190. defineExpose({
  191. doRequest,
  192. setSelectedRowKeys,
  193. getSelectRowKeys,
  194. setLoading,
  195. reload,
  196. getForm
  197. });
  198. onMounted(() => {
  199. // 如果是https
  200. // 反之是websocket
  201. });
  202. onUnmounted(() => {});
  203. </script>
  204. <style scoped lang="less">
  205. @ventSpace: zxm;
  206. :deep(.@{ventSpace}-table-body) {
  207. height: auto !important;
  208. tr > td {
  209. background: #ffffff00 !important;
  210. }
  211. tr.@{ventSpace}-table-row-selected {
  212. td {
  213. background: #007cc415 !important;
  214. }
  215. }
  216. }
  217. :deep(.jeecg-basic-table .@{ventSpace}-table-wrapper .@{ventSpace}-table-title) {
  218. min-height: 0;
  219. }
  220. :deep(.@{ventSpace}-pagination) {
  221. margin-right: 20px !important;
  222. }
  223. </style>