MonitorTable.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. if(!newVal) return
  153. const column = getTableHeaderColumns(newVal.endsWith('_monitor') ? newVal : newVal+'_monitor')
  154. console.log('监测列表表头000------------>', newVal)
  155. if(column && column.length < 1){
  156. const arr = newVal.split('_')
  157. const columnKey = arr.reduce((prev, cur, index) => {
  158. if(index !== arr.length - 2){
  159. return prev + '_' + cur
  160. }else {
  161. return prev
  162. }
  163. })
  164. columns.value = getTableHeaderColumns(arr[0]+'_monitor');
  165. }else{
  166. columns.value = column
  167. }
  168. },
  169. {
  170. immediate: true
  171. }
  172. );
  173. watch(() => props.scroll.y, (newVal) => {
  174. if (newVal) {
  175. tableScroll.value = { y: newVal }
  176. } else {
  177. tableScroll.value = {}
  178. }
  179. }
  180. )
  181. watch(
  182. selectedRowKeys,
  183. (newKeys) => {
  184. console.log('设置的选中id---------->', newKeys, dataTableSource.value)
  185. const index = findIndex(dataTableSource.value, (data: any) => {
  186. return data.deviceID == selectedRowKeys.value[0];
  187. });
  188. if (index >= 0) emits('selectRow', dataTableSource.value[index], index);
  189. },
  190. { immediate: false }
  191. );
  192. defineExpose({
  193. doRequest,
  194. setSelectedRowKeys,
  195. getSelectRowKeys,
  196. setLoading,
  197. reload,
  198. getForm
  199. });
  200. onMounted(() => {
  201. // 如果是https
  202. // 反之是websocket
  203. });
  204. onUnmounted(() => {});
  205. </script>
  206. <style scoped lang="less">
  207. @ventSpace: zxm;
  208. :deep(.@{ventSpace}-table-body) {
  209. height: auto !important;
  210. tr > td {
  211. background: #ffffff00 !important;
  212. }
  213. tr.@{ventSpace}-table-row-selected {
  214. td {
  215. background: #007cc415 !important;
  216. }
  217. }
  218. }
  219. :deep(.jeecg-basic-table .@{ventSpace}-table-wrapper .@{ventSpace}-table-title) {
  220. min-height: 0;
  221. }
  222. :deep(.@{ventSpace}-pagination) {
  223. margin-right: 20px !important;
  224. }
  225. </style>