1
0

MonitorTable.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. // default: () => [],
  39. required: true,
  40. },
  41. deviceType: {
  42. type: String,
  43. },
  44. designScope: {
  45. type: String,
  46. },
  47. isShowSelect: {
  48. type: Boolean,
  49. default:true,
  50. },
  51. isShowPagination: {
  52. type: Boolean,
  53. default: true,
  54. },
  55. isShowActionColumn: {
  56. type: Boolean,
  57. default: false,
  58. },
  59. scroll: {
  60. type: Object,
  61. default: {y: 0}
  62. },
  63. title: {
  64. type: String,
  65. },
  66. size: {
  67. type: String,
  68. default: 'small',
  69. },
  70. formConfig: {
  71. type: Object as PropType<FormProps> | undefined,
  72. default: undefined
  73. }
  74. });
  75. const emits = defineEmits(['selectRow']);
  76. const dataTableSource = ref<any[]>([]);
  77. // const loading = ref(true);
  78. const ventTableRef = ref();
  79. const tableMaxHeight = 150;
  80. const columns = ref([])
  81. const tableScroll = props.scroll.y ? ref({y: props.scroll.y}) : ref({})
  82. //注册table数据
  83. // 列表页面公共参数、方法
  84. const { prefixCls, tableContext, doRequest } = useListPage({
  85. designScope: props.designScope,
  86. tableProps: {
  87. title: props.title,
  88. dataSource: dataTableSource,
  89. columns: props.columnsType ? columns : (props.columns as any[]),
  90. rowSelection: { type: props.isShowSelect? 'radio': undefined, columnWidth: 100 },
  91. size: props.size,
  92. useSearchForm: props.formConfig ? true : false,
  93. showTableSetting: false,
  94. showIndexColumn: true,
  95. showActionColumn: props.isShowActionColumn,
  96. maxHeight: tableMaxHeight,
  97. bordered: false,
  98. scroll: tableScroll,
  99. rowKey: 'deviceID',
  100. formConfig: props.formConfig,
  101. // striped: true,
  102. loading: true,
  103. actionColumn: {
  104. width: 180,
  105. },
  106. pagination: props.isShowPagination ? {
  107. current: 1,
  108. pageSize: 50,
  109. pageSizeOptions: ['10', '30', '50', '100', '500'],
  110. showQuickJumper: false
  111. } : false,
  112. beforeFetch: (params) => {
  113. if(props.deviceType?.startsWith('safetymonitor')){
  114. return Object.assign(params, { filterParams: {'dataTypeName': params['dataTypeName'], strinstallpos: '*'+params['strinstallpos']+'*'} });
  115. }else if(props.deviceType?.startsWith('location')) {
  116. return Object.assign(params, { filterParams: { strinstallpos: '*' + params['strinstallpos'] + '*', userName: '*' + params['strname'] + '*', userJson: '' } });
  117. }else if(props.deviceType?.startsWith('vehicle')) {
  118. return Object.assign(params, { filterParams: {strinstallpos: '*'+params['strinstallpos']+'*', vehicleName: '*'+params['strname']+'*' } });
  119. }else{
  120. return Object.assign(params, { column: 'createTime' });
  121. }
  122. },
  123. },
  124. });
  125. const [registerTable, { reload, setLoading, setSelectedRowKeys, getSelectRowKeys, getForm }, { rowSelection, selectedRowKeys, }] = tableContext;
  126. watch(
  127. () => {
  128. return props.dataSource;
  129. },
  130. (newVal, oldVal) => {
  131. if (oldVal && newVal && oldVal.length < 1 && newVal.length > 0) {
  132. // 第一次
  133. if(getSelectRowKeys().length < 1) setSelectedRowKeys([newVal[0].deviceID]);
  134. }
  135. const list = <any[]>[];
  136. newVal.forEach((item) => {
  137. list.push(toRaw(item));
  138. });
  139. dataTableSource.value = list;
  140. if(ventTableRef.value) setLoading(false)
  141. },
  142. {
  143. immediate: true
  144. }
  145. );
  146. watch(
  147. () => {
  148. return props.columnsType;
  149. },
  150. (newVal) => {
  151. console.log(newVal,'val-----')
  152. debugger;
  153. if(!newVal) return
  154. const column = getTableHeaderColumns(newVal.endsWith('_monitor') ? newVal : newVal+'_monitor')
  155. console.log('监测列表表头000------------>', newVal)
  156. if(column && column.length < 1){
  157. const arr = newVal.split('_')
  158. const columnKey = arr.reduce((prev, cur, index) => {
  159. if(index !== arr.length - 2){
  160. return prev + '_' + cur
  161. }else {
  162. return prev
  163. }
  164. })
  165. columns.value = getTableHeaderColumns(arr[0]+'_monitor');
  166. }else{
  167. columns.value = column
  168. }
  169. },
  170. {
  171. immediate: true
  172. }
  173. );
  174. watch(() => props.scroll.y, (newVal) => {
  175. if (newVal) {
  176. tableScroll.value = { y: newVal }
  177. } else {
  178. tableScroll.value = {}
  179. }
  180. }
  181. )
  182. watch(
  183. selectedRowKeys,
  184. (newKeys) => {
  185. console.log('设置的选中id---------->', newKeys, dataTableSource.value)
  186. const index = findIndex(dataTableSource.value, (data: any) => {
  187. return data.deviceID == selectedRowKeys.value[0];
  188. });
  189. if (index >= 0) emits('selectRow', dataTableSource.value[index], index);
  190. },
  191. { immediate: false }
  192. );
  193. defineExpose({
  194. doRequest,
  195. setSelectedRowKeys,
  196. getSelectRowKeys,
  197. setLoading,
  198. reload,
  199. getForm
  200. });
  201. onMounted(() => {
  202. // 如果是https
  203. // 反之是websocket
  204. });
  205. onUnmounted(() => {});
  206. </script>
  207. <style scoped lang="less">
  208. @ventSpace: zxm;
  209. :deep(.@{ventSpace}-table-body) {
  210. height: auto !important;
  211. tr > td {
  212. background: #ffffff00 !important;
  213. }
  214. tr.@{ventSpace}-table-row-selected {
  215. td {
  216. background: #007cc415 !important;
  217. }
  218. }
  219. }
  220. :deep(.jeecg-basic-table .@{ventSpace}-table-wrapper .@{ventSpace}-table-title) {
  221. min-height: 0;
  222. }
  223. :deep(.@{ventSpace}-pagination) {
  224. margin-right: 20px !important;
  225. }
  226. </style>