MonitorTable.vue 7.4 KB

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