passqrcode.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <el-container class="is-vertical">
  3. <sc-page-header>
  4. <template #extra-right>
  5. <el-button type="warning" @click="refreshState">刷新状态</el-button>
  6. </template>
  7. </sc-page-header>
  8. <scTable ref="xGridTable" :apiObj="$API.system.device" :formConfig="formConfig" :paramsColums="paramsColums" :toolbarConfig="toolbarConfig" :columns="columns"></scTable>
  9. </el-container>
  10. </template>
  11. <script setup>
  12. import moment from "moment";
  13. import XEUtils from "xe-utils";
  14. import API from "@/api";
  15. import TOOL from "@/utils/tool";
  16. import { gateTypeDic, deviceStateDic } from "@/utils/basicDic";
  17. import { mapFormItemInput, mapFormItemSelect } from "@/components/scTable/helper";
  18. const deviceState = ref({});
  19. const refreshTime = ref(moment().add(20, "second").valueOf());
  20. const interval = ref(null);
  21. const formatGate = ({ projectId, deviceNum }) => XEUtils.find(TOOL.data.get("PASSQRCODE_GATE"), item => XEUtils.findIndexOf(item.devices, d => d.project_id == projectId && d.device_num === deviceNum) !== -1);
  22. const projectConfig = reactive({
  23. options: TOOL.data.get("PROJECT"),
  24. optionProps: { label: "projectName", value: "fpiId" },
  25. events: {
  26. change: data => XEUtils.merge(formConfig.data, data)
  27. }
  28. })
  29. const toolbarConfig = reactive({
  30. enabled: true,
  31. print: false
  32. })
  33. const formConfig = reactive({
  34. data: {
  35. categoryId: 22,
  36. modelId: 29
  37. },
  38. items: [
  39. mapFormItemSelect("projectId", "所属项目", projectConfig),
  40. mapFormItemInput("deviceNum", "设备唯一标识")
  41. ]
  42. })
  43. const paramsColums = reactive([
  44. { column: "categoryId" },
  45. { column: "modelId" },
  46. { column: "projectId" },
  47. { column: "deviceNum" }
  48. ])
  49. const columns = reactive([
  50. { type: "seq", fixed: "left", width: 60 },
  51. { type: "html", field: "deviceCode", title: "设备唯一标识", minWidth: 150, sortable: true, formatter: ({ cellValue, row }) => cellValue || row.deviceNum },
  52. { type: "html", field: "projectName", title: "所属项目", minWidth: 200, sortable: true, formatter: ({ cellValue, row }) => cellValue || XEUtils.get(XEUtils.find(TOOL.data.get("PROJECT"), item => item.fpiId === row.projectId), "projectName") },
  53. { type: "html", field: "groundName", title: "工地场区", minWidth: 150, sortable: true, formatter: ({ cellValue, row }) => cellValue || XEUtils.get(formatGate(row), "ground.groundName") },
  54. { type: "html", field: "gateName", title: "闸口名称", minWidth: 150, sortable: true, formatter: ({ cellValue, row }) => cellValue || XEUtils.get(formatGate(row), "gateName") },
  55. { type: "html", field: "gateType", title: "闸口类型", minWidth: 150, sortable: true, formatter: ({ cellValue, row }) => cellValue || XEUtils.get(gateTypeDic, XEUtils.get(formatGate(row), "gateType")) },
  56. { field: "state", title: "在线状态", minWidth: 100, align: "center", formatter: ({ row }) => XEUtils.get(deviceStateDic, XEUtils.get(deviceState.value, row.deviceNum), "离线"), editRender: { name: "$cell-tag" } },
  57. // { title: "操作", fixed: "right", minWidth: 400, slots: { default: "action" } }
  58. ])
  59. // 显示隐藏 筛选表单
  60. const xGridTable = ref();
  61. // const tableLength = computed(() => xGridTable.value?.getTableData().fullData.length);
  62. // watch(tableLength, value => value > 0 && getDeviceState());
  63. onMounted(() => window.addEventListener("setItemEvent", ({ key, newValue }) => key == "PASSQRCODE_GATE" && newValue && xGridTable.value?.reloadColumn(columns)));
  64. onUnmounted(() => window.removeEventListener("setItemEvent", () => {}));
  65. const getDeviceState = () => {
  66. if (interval.value) {
  67. clearInterval(interval.value);
  68. interval.value = null;
  69. }
  70. stateCheck();
  71. refreshTime.value = moment().add(20, "second").valueOf();
  72. interval.value = setInterval(() => {
  73. stateCheck();
  74. refreshTime.value = moment().add(20, "second").valueOf();
  75. }, 120 * 1000);
  76. }
  77. const stateCheck = XEUtils.throttle(function() {
  78. API.passqrcode.check.get({ expands: XEUtils.zipObject(xGridTable.value.getTableData().fullData.map(f => f.deviceNum), new Array(xGridTable.value.getTableData().fullData.map(f => f.deviceNum).length).fill("ask")) }).then(res => {
  79. XEUtils.assign(deviceState.value, res.expands);
  80. xGridTable.value.reloadColumn(columns);
  81. });
  82. }, 500, { trailing: true, leading: false });
  83. onUnmounted(() => {
  84. if (interval.value) {
  85. clearInterval(interval.value);
  86. interval.value = null;
  87. }
  88. })
  89. const refreshState = () => {
  90. if (moment().diff(refreshTime.value, "second") < 0) return ElMessage.warning("请勿重复刷新!(间隔时间至少20秒)");
  91. // getDeviceState();
  92. }
  93. </script>