<template>
|
<div class="table-box">
|
<!-- 根据布局模式渲染不同的组件 -->
|
|
<ProTable ref="proTable" :columns="columns" :request-api="getTableList" :init-param="initParam">
|
<!-- Expand -->
|
<template #expand="scope">
|
{{ scope.row }}
|
</template>
|
<!-- 表格 header 按钮 -->
|
|
<template #Sign="scope">
|
<span style="margin-left: 10px">
|
<b>{{ scope.row.baoliu10 }}</b>
|
<el-divider direction="vertical" border-style="dashed" />{{ scope.row.objectid }}
|
</span>
|
</template>
|
<template #Context="scope">
|
<el-tabs>
|
<el-tab-pane :label="t('Warning.alarmInfo')">
|
<p>{{ t("Warning.type") }}:{{ scope.row.type }}</p>
|
<p>{{ t("Warning.fence") }}:{{ scope.row.baoliu2 }}</p>
|
<p>{{ t("Config.time") }}:{{ scope.row.time }}</p>
|
<!-- 基本信息字段 -->
|
</el-tab-pane>
|
</el-tabs>
|
</template>
|
<template #Footer>
|
<el-button type="danger">{{ t("Warning.handle") }}</el-button>
|
<el-button type="primary">{{ t("Warning.details") }}</el-button>
|
</template>
|
<!-- 表格操作 -->
|
<!-- 表格操作 -->
|
<template #operation="scope">
|
<!-- <el-button type="primary" link :icon="View">{{ t("Config.view") }}</el-button> -->
|
<el-button type="primary" v-if="BUTTONS.edit" link :icon="EditPen" @click="openDrawer(t('Config.update'), scope.row)">
|
{{ t("Config.update") }}
|
</el-button>
|
</template>
|
</ProTable>
|
|
<warnTongJiDrawer ref="drawerRef" />
|
<ImportExcel ref="dialogRef" />
|
</div>
|
</template>
|
|
<script setup lang="tsx" name="useProTable">
|
import { ref, reactive } from "vue";
|
import { User } from "@/api/interface";
|
import {} from "@/hooks/useHandleData";
|
import ProTable from "@/components/ProTable/card.vue";
|
import ImportExcel from "@/components/ImportExcel/index.vue";
|
import warnTongJiDrawer from "@/views/proTable/components/hxzk/statistics/warnTongJiDrawer.vue";
|
import { EditPen } from "@element-plus/icons-vue";
|
import { ProTableInstance, ColumnProps } from "@/components/ProTable/interface";
|
import { getWarnCountList, editWarningTongJi } from "@/api/modules/hxzk/statistics/warncount";
|
import { useAuthButtons } from "@/hooks/useAuthButtons";
|
import { useI18n } from "vue-i18n";
|
|
// 使用 useI18n 获取 i18n 实例
|
const { t } = useI18n({
|
useScope: "global"
|
});
|
|
const { BUTTONS } = useAuthButtons();
|
// ProTable 实例
|
const proTable = ref<ProTableInstance>();
|
|
// 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
|
const initParam = reactive({ type: 1 });
|
const getTableList = (params: any) => {
|
let newParams = JSON.parse(JSON.stringify(params));
|
|
// 提取 tableList 对象
|
const { pageSize, pageNum, objectid, baoliu10, ...restParams } = newParams;
|
const tableList = { pageSize, pageNum };
|
|
// 提取 person 对象
|
const { ...restParams2 } = restParams;
|
const warning = { objectid, baoliu10 };
|
|
// 处理 createTime 字段
|
if (restParams2.createTime) {
|
restParams2.startTime = restParams2.createTime[0];
|
restParams2.endTime = restParams2.createTime[1];
|
delete restParams2.createTime;
|
}
|
|
// 合并所有参数
|
const finalParams = {
|
...restParams2,
|
tableList,
|
warning
|
};
|
|
return getWarnCountList(finalParams);
|
};
|
|
// 表格配置项
|
const columns = reactive<ColumnProps<User.ResUserList>[]>([
|
{ type: "selection", fixed: "left", width: 70 },
|
{ type: "index", fixed: "left", width: 70 },
|
{
|
prop: "title",
|
label: t("warncount.title")
|
},
|
{
|
prop: "num",
|
label: t("warncount.count")
|
},
|
{
|
prop: "danwei",
|
label: t("warncount.unit")
|
},
|
{
|
prop: "isshow",
|
label: t("warncount.isShow"),
|
render(scope) {
|
return scope.row.isshow === 1 ? t("warncount.show") : t("warncount.hide");
|
}
|
},
|
{
|
prop: "company",
|
label: t("warncount.belongCompany")
|
},
|
{ prop: "operation", label: t("Config.operation"), width: 260 }
|
]);
|
|
// 打开 drawer(新增、查看、编辑)
|
const drawerRef = ref<InstanceType<typeof warnTongJiDrawer> | null>(null);
|
const openDrawer = (title: string, row: Partial<User.ResUserList> = {}) => {
|
const params = {
|
title,
|
initParam,
|
isView: title === t("Config.view"),
|
row: { ...row },
|
api: title === t("Config.add") ? editWarningTongJi : title === t("Config.update") ? editWarningTongJi : undefined,
|
getTableList: proTable.value?.getTableList
|
};
|
drawerRef.value?.acceptParams(params);
|
};
|
</script>
|