index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <scTable ref="xGridTable" batchDel :apiObj="$API.scc.record" :formConfig="formConfig" :paramsColums="paramsColums" :toolbarConfig="toolbarConfig" :columns="columns" v-bind="props.options">
  3. <template #default_imgUrl="{ row }">
  4. <template v-if="XEUtils.get(XEUtils.toStringJSON(row.features), 'bigImage.image')">
  5. <vxe-image style="cursor: pointer;" :src="'/minio' + XEUtils.get(XEUtils.toStringJSON(row.features), 'bigImage.image')" width="40" height="40" :toolbar-config="imageToolbar"></vxe-image>
  6. </template>
  7. </template>
  8. <template #action="{ row }">
  9. <el-button type="primary" link @click="table_edit(row)">
  10. <template #icon><sc-iconify icon="ant-design:edit-outlined"></sc-iconify></template>修改
  11. </el-button>
  12. <el-button type="primary" link @click="table_del(row)">
  13. <template #icon><sc-iconify icon="ant-design:delete-outlined"></sc-iconify></template>删除
  14. </el-button>
  15. </template>
  16. </scTable>
  17. <record-detail v-if="dialog" ref="recordRef" :projectId="props.isTemp ? 1 : TOOL.data.get('PROJECT_ID')" @success="refreshTable" @closed="dialog = false"></record-detail>
  18. </template>
  19. <script setup>
  20. import moment from "moment";
  21. import XEUtils from "xe-utils";
  22. import API from "@/api";
  23. import TOOL from "@/utils/tool";
  24. import { mapFormItemSelect, mapFormItemDatePicker } from "@/components/scTable/helper";
  25. import { dataSource, objectToArray } from "@/utils/basicDic";
  26. import { typeDic, unitDic } from "@/views/dataMock/standard/main";
  27. import recordDetail from "./detail";
  28. const props = defineProps({
  29. options: { type: Object, default: () => {} },
  30. isTemp: { type: Boolean, default: false },
  31. hideHandler: { type: Boolean, default: false }
  32. })
  33. const visible = computed(() => !props.isTemp);
  34. const radioConfig = reactive({
  35. span: props.isTemp ? 5 : 6,
  36. resetValue: 0,
  37. options: [{ label: "全部", value: 0 }, { label: "报警数据", value: 1 }],
  38. props: { filterable: false, clearable: false },
  39. events: {
  40. change: data => XEUtils.merge(formConfig.data, data)
  41. }
  42. })
  43. const proConfig = reactive({
  44. visible,
  45. storageKey: "PROJECT",
  46. resetValue: TOOL.data.get("PROJECT_ID"),
  47. optionProps: { label: "projectName", value: "fpiId" },
  48. events: {
  49. change: data => XEUtils.assign(formConfig.data, { ...data, mountedId: null })
  50. }
  51. })
  52. const mountedConfig = reactive({
  53. visible,
  54. api: {
  55. key: "scc.mounted",
  56. query: {
  57. projectId: computed(() => formConfig.data.projectId),
  58. projectIdNot: 1
  59. }
  60. },
  61. slot: {
  62. style: { float: "right", paddingLeft: "6px", color: "#8492a6" }
  63. },
  64. optionProps: { label: "mountedName", value: "id", slot: ({ data }) => XEUtils.get(XEUtils.find(TOOL.data.get("PROJECT"), item => item.fpiId === data.projectId), "projectName") },
  65. events: {
  66. change: data => XEUtils.assign(formConfig.data, data)
  67. }
  68. })
  69. const selectConfig = reactive({
  70. options: objectToArray(typeDic),
  71. events: {
  72. change: data => XEUtils.merge(formConfig.data, data)
  73. }
  74. })
  75. const datetimerangeConfig = reactive({
  76. span: 7,
  77. resetValue: () => [moment().startOf("day").format("YYYY-MM-DD HH:mm:ss"), moment().format("YYYY-MM-DD HH:mm:ss")],
  78. props: {
  79. type: "datetimerange",
  80. startPlaceholder: "开始时间",
  81. endPlaceholder: "结束时间",
  82. format: "YYYY-MM-DD HH:mm"
  83. }
  84. })
  85. const toolbarConfig = reactive({
  86. enabled: true,
  87. print: false
  88. })
  89. const formConfig = reactive({
  90. data: {
  91. projectId: TOOL.data.get("PROJECT_ID"),
  92. projectIdNot: 1,
  93. isWarning: 0,
  94. createTime: [moment().startOf("day").format("YYYY-MM-DD HH:mm:ss"), moment().format("YYYY-MM-DD HH:mm:ss")]
  95. },
  96. items: [
  97. mapFormItemSelect("isWarning", "数据类型", radioConfig),
  98. mapFormItemSelect("projectId", "所属项目", proConfig),
  99. mapFormItemSelect("mountedId", "设备安装点", mountedConfig),
  100. mapFormItemSelect("vtype", "监测类型", selectConfig),
  101. mapFormItemDatePicker("createTime", "监测时间", datetimerangeConfig)
  102. ]
  103. })
  104. const paramsColums = reactive([
  105. { column: "projectId", field: visible.value ? "" : "projectIdNot" },
  106. visible.value ? { column: "projectIdNot" } : {},
  107. { column: "mountedId" },
  108. { column: "isWarning" },
  109. { column: "vtype" },
  110. { column: "createTimeBegin", field: "createTime[0]" },
  111. { column: "createTimeEnd", field: "createTime[1]" }
  112. ])
  113. const columns = reactive([
  114. { visible: !props.hideHandler, type: "checkbox", fixed: "left", width: 40 },
  115. { type: "seq", fixed: "left", width: 60 },
  116. { visible, type: "html", field: "projectName", title: "项目名称", minWidth: 160, sortable: true, formatter: ({ cellValue, row }) => cellValue || XEUtils.get(XEUtils.find(TOOL.data.get("PROJECT"), item => item.fpiId == row.projectId), "projectName") },
  117. { visible, type: "html", field: "groundName", title: "工地场区", minWidth: 160, sortable: true },
  118. { visible, type: "html", field: "mountedName", title: "设备安装点", minWidth: 160, sortable: true },
  119. { type: "html", field: "vtype", title: "监测类型", minWidth: 100, sortable: true, formatter: ({ cellValue }) => XEUtils.get(typeDic, cellValue, cellValue) },
  120. { type: "html", field: "taskValue", title: "监测数值", minWidth: 100, sortable: true, formatter: ({ cellValue, row }) => cellValue || XEUtils.divide(XEUtils.get(row, "value"), 100) + XEUtils.get(unitDic, XEUtils.get(row, "vtype")) },
  121. { type: "html", field: "createTime", title: "监测时间", minWidth: 160, sortable: true },
  122. { visible, type: "html", field: "dataSource", title: "数据来源", fixed: "right", minWidth: 100, sortable: true, formatter: ({ cellValue }) => XEUtils.get(dataSource, cellValue, cellValue) },
  123. { visible: !props.hideHandler, title: "操作", fixed: "right", width: 140, align: "center", slots: { default: "action" } }
  124. ])
  125. const imageToolbar = reactive({
  126. print: false,
  127. download: true
  128. })
  129. // 显示隐藏 筛选表单
  130. const xGridTable = ref();
  131. const toggleFormEnabled = () => xGridTable.value.toggleFormEnabled();
  132. const getTableTotal = () => xGridTable.value.getTableData().tableData.length;
  133. const refreshTable = () => {
  134. xGridTable.value.reloadColumn(columns);
  135. xGridTable.value.searchData();
  136. }
  137. const recordRef = ref();
  138. const dialog = ref(false);
  139. const table_add = () => {
  140. dialog.value = true;
  141. nextTick(() => recordRef.value?.open());
  142. }
  143. const table_edit = row => {
  144. dialog.value = true;
  145. nextTick(() => recordRef.value?.setData(row));
  146. }
  147. const table_del = ({ id }) => {
  148. ElMessageBox.confirm("是否确认删除该监测记录?", "删除警告", {
  149. type: "warning",
  150. confirmButtonText: "确定",
  151. cancelButtonText: "取消"
  152. }).then(() => {
  153. API.scc.record.del({ id }).then(() => {
  154. ElMessage.success("操作成功");
  155. refreshTable();
  156. });
  157. });
  158. }
  159. defineExpose({
  160. table_add,
  161. refreshTable,
  162. getTableTotal
  163. })
  164. </script>