MonitorTable.vue 7.1 KB

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