MonitorTable.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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, nextTick } 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. ? {
  118. current: 1,
  119. pageSize: 50,
  120. pageSizeOptions: ['10', '30', '50', '100', '500'],
  121. showQuickJumper: false,
  122. }
  123. : false,
  124. beforeFetch: (params) => {
  125. if (props.deviceType?.startsWith('safetymonitor')) {
  126. return Object.assign(params, {
  127. filterParams: { dataTypeName: params['dataTypeName'], strinstallpos: '*' + params['strinstallpos'] + '*' },
  128. });
  129. } else if (props.deviceType?.startsWith('location')) {
  130. return Object.assign(params, {
  131. filterParams: { strinstallpos: '*' + params['strinstallpos'] + '*', userName: '*' + params['strname'] + '*', userJson: '' },
  132. });
  133. } else if (props.deviceType?.startsWith('vehicle')) {
  134. return Object.assign(params, {
  135. filterParams: { strinstallpos: '*' + params['strinstallpos'] + '*', vehicleName: '*' + params['strname'] + '*' },
  136. });
  137. } else {
  138. return Object.assign(params, { column: 'createTime' });
  139. }
  140. },
  141. },
  142. });
  143. const [registerTable, { reload, setLoading, setSelectedRowKeys, getSelectRowKeys, getForm, setPagination }, { rowSelection, selectedRowKeys }] =
  144. tableContext;
  145. watch(
  146. () => {
  147. return props.dataSource;
  148. },
  149. (newVal, oldVal) => {
  150. if (oldVal && newVal && oldVal.length < 1 && newVal.length > 0) {
  151. // 第一次
  152. if (getSelectRowKeys().length < 1) setSelectedRowKeys([newVal[0].deviceID]);
  153. }
  154. const list = <any[]>[];
  155. newVal.forEach((item) => {
  156. list.push(toRaw(item));
  157. });
  158. dataTableSource.value = list;
  159. nextTick(() => {
  160. setLoading(false);
  161. });
  162. },
  163. {
  164. immediate: true,
  165. }
  166. );
  167. watch(
  168. () => {
  169. return props.columnsType;
  170. },
  171. (newVal) => {
  172. console.log(newVal, 'val-----');
  173. if (!newVal) return;
  174. const column = getTableHeaderColumns(newVal.endsWith('_monitor') ? newVal : newVal + '_monitor');
  175. console.log('监测列表表头000------------>', newVal);
  176. if (column && column.length < 1) {
  177. const arr = newVal.split('_');
  178. const columnKey = arr.reduce((prev, cur, index) => {
  179. if (index !== arr.length - 2) {
  180. return prev + '_' + cur;
  181. } else {
  182. return prev;
  183. }
  184. });
  185. columns.value = getTableHeaderColumns(arr[0] + '_monitor');
  186. } else {
  187. columns.value = column;
  188. }
  189. },
  190. {
  191. immediate: true,
  192. }
  193. );
  194. watch(
  195. () => props.scroll.y,
  196. (newVal) => {
  197. if (newVal) {
  198. tableScroll.value = { y: newVal };
  199. } else {
  200. tableScroll.value = {};
  201. }
  202. }
  203. );
  204. watch(
  205. selectedRowKeys,
  206. (newKeys) => {
  207. console.log('设置的选中id---------->', newKeys, dataTableSource.value);
  208. const index = findIndex(dataTableSource.value, (data: any) => {
  209. return data.deviceID == selectedRowKeys.value[0];
  210. });
  211. if (index >= 0) emits('selectRow', dataTableSource.value[index], index);
  212. },
  213. { immediate: false }
  214. );
  215. function resetPagination() {
  216. if (ventTableRef.value) setPagination({ current: 1, pageSize: 50, total: 0 });
  217. }
  218. defineExpose({
  219. doRequest,
  220. setSelectedRowKeys,
  221. getSelectRowKeys,
  222. setLoading,
  223. reload,
  224. getForm,
  225. resetPagination,
  226. });
  227. onMounted(() => {
  228. // 如果是https
  229. // 反之是websocket
  230. });
  231. onUnmounted(() => {});
  232. </script>
  233. <style scoped lang="less">
  234. @ventSpace: zxm;
  235. :deep(.@{ventSpace}-table-body) {
  236. height: auto !important;
  237. tr > td {
  238. background: #ffffff00 !important;
  239. }
  240. tr.@{ventSpace}-table-row-selected {
  241. td {
  242. background: #007cc415 !important;
  243. }
  244. }
  245. }
  246. :deep(.jeecg-basic-table .@{ventSpace}-table-wrapper .@{ventSpace}-table-title) {
  247. min-height: 0;
  248. }
  249. :deep(.@{ventSpace}-pagination) {
  250. margin-right: 20px !important;
  251. }
  252. </style>