<template>
|
<div class="table-box">
|
<!-- 根据布局模式渲染不同的组件 -->
|
|
<ProTable ref="proTable" :columns="columns" :request-api="getTableList" :init-param="initParam">
|
<template #tableHeader>
|
<el-button type="primary" v-if="BUTTONS.add" plain :icon="CirclePlus" @click="openAddDrawer('新增')">
|
{{ t("Tag.addDevice") }}
|
</el-button>
|
<el-button type="primary" plain :icon="Setting" @click="openDrawer('新增')">
|
{{ t("Tag.setDevice") }}
|
</el-button>
|
</template>
|
<!-- Expand -->
|
<template #expand="scope">
|
{{ scope.row }}
|
</template>
|
<template #Sign="scope">
|
<span style="margin-left: 10px">
|
<b>{{ t("Tag.tagId") }} </b>
|
<el-divider direction="vertical" border-style="dashed" />{{ scope.row.tagId }}
|
</span>
|
</template>
|
<template #power="scope">
|
<VueUiGizmo :config="config" :dataset="scope.row.power" />
|
</template>
|
<template #Context="scope">
|
<el-tabs>
|
<el-tab-pane :label="t('Tag.info')">
|
<p>
|
{{ t("Tag.type") }}:<el-tag effect="plain">{{ scope.row.type }}</el-tag>
|
</p>
|
<p>
|
{{ t("Tag.power") }}:<el-tag effect="plain">{{ scope.row.power }}</el-tag>
|
</p>
|
<p>
|
{{ t("Tag.version") }}:<el-tag effect="plain">{{ scope.row.version }}</el-tag>
|
</p>
|
<!-- 基本信息字段 -->
|
</el-tab-pane>
|
</el-tabs>
|
</template>
|
<template #Footer="scope">
|
<span>
|
<b>{{ t("Tag.status") }}:</b>
|
<el-tag :type="getStatusType(scope.row.anchormode)">{{ getStatusText(scope.row.anchormode) }}</el-tag>
|
</span>
|
</template>
|
<!-- 表格操作 -->
|
<template #operation="scope">
|
<el-button type="primary" link :icon="View" @click="openAddDrawer($t('Config.view'), scope.row)">{{
|
$t("Config.view")
|
}}</el-button>
|
<el-button type="primary" v-if="BUTTONS.edit" link :icon="EditPen" @click="openAddDrawer($t('Config.update'), scope.row)">
|
{{ $t("Config.update") }}
|
</el-button>
|
<el-button type="primary" v-if="BUTTONS.delete" link :icon="Delete" @click="deleteAccount(scope.row)">{{
|
$t("Config.delete")
|
}}</el-button>
|
</template>
|
</ProTable>
|
|
<tagDrawer ref="drawerRef" />
|
<tagDrawerAdd ref="drawerRefAdd" />
|
<ImportExcel ref="dialogRef" />
|
</div>
|
</template>
|
|
<script setup lang="tsx" name="useProTable">
|
import { ref, reactive } from "vue";
|
import { User } from "@/api/interface";
|
import { useHandleData } from "@/hooks/useHandleData";
|
import { ElMessage } from "element-plus";
|
import ProTable from "@/components/ProTable/card.vue";
|
import ImportExcel from "@/components/ImportExcel/index.vue";
|
import tagDrawer from "@/views/proTable/components/hxzk/device/tagDrawer.vue";
|
import tagDrawerAdd from "@/views/proTable/components/hxzk/device/tagDrawerAdd.vue";
|
import { ProTableInstance, ColumnProps } from "@/components/ProTable/interface";
|
import { Setting, CirclePlus, Delete, EditPen, View } from "@element-plus/icons-vue";
|
import { getTagList, addTag, editTag, deleteTag } from "@/api/modules/hxzk/device/tag";
|
import { VueUiGizmo } from "vue-data-ui";
|
import "vue-data-ui/style.css";
|
import { useDict } from "@/utils/dict";
|
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>();
|
const { TagType } = useDict();
|
// 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
|
|
const getTableList = (params: any) => {
|
let newParams = JSON.parse(JSON.stringify(params));
|
|
// 提取 tableList 对象
|
const { pageSize, pageNum, tagId, type, ...restParams } = newParams;
|
const tableList = { pageSize, pageNum };
|
|
// 提取 person 对象
|
const { ...restParams2 } = restParams;
|
const tag = { tagId, type };
|
|
// 处理 createTime 字段
|
if (restParams2.createTime) {
|
restParams2.startTime = restParams2.createTime[0];
|
restParams2.endTime = restParams2.createTime[1];
|
delete restParams2.createTime;
|
}
|
|
// 合并所有参数
|
const finalParams = {
|
...restParams2,
|
tableList,
|
tag
|
};
|
|
return getTagList(finalParams);
|
};
|
|
// 表格配置项
|
const columns = reactive<ColumnProps<User.ResUserList>[]>([
|
{ type: "selection", fixed: "left", width: 70 },
|
|
{
|
prop: "status",
|
label: t("Tag.status"),
|
render: scope => {
|
const statusText = scope.row.status === "1" ? t("Tag.statusOnline") : t("Tag.statusOffline");
|
const tagType = scope.row.status === "1" ? "success" : "danger";
|
return (
|
<el-tag size="large" effect="plain" type={tagType}>
|
{statusText}
|
</el-tag>
|
);
|
}
|
},
|
{
|
prop: "tagId",
|
label: t("Tag.tagId"),
|
search: { el: "input", span: 4 }
|
},
|
{
|
prop: "version",
|
label: t("Tag.version")
|
},
|
{
|
prop: "power",
|
label: t("Tag.power")
|
},
|
{
|
prop: "type",
|
label: t("Tag.type"),
|
enum: TagType,
|
search: { el: "select", props: { filterable: true }, span: 4 }
|
},
|
{
|
prop: "addtime",
|
label: t("Config.time"),
|
width: 160
|
},
|
|
{ prop: "operation", label: t("Config.operation"), width: 260 }
|
]);
|
|
// 电量配置项
|
const config = ref({
|
type: "battery",
|
size: 60,
|
stroke: "#8a8a8aff",
|
color: "#33ff57ff",
|
useGradient: false,
|
gradientColor: "rgba(255, 0, 0, 1)",
|
showPercentage: true,
|
textColor: "rgba(26, 26, 26, 1)",
|
fontFamily: "inherit",
|
formatter: null
|
});
|
// 根据 anchormode 的值返回状态文字
|
const getStatusText = anchormode => {
|
return anchormode === "1" ? t("Tag.statusOnline") : t("Tag.statusOffline");
|
};
|
|
// 根据 anchormode 的值返回标签类型
|
const getStatusType = anchormode => {
|
return anchormode === "1" ? "success" : "danger";
|
};
|
// 打开 drawer(新增、查看、编辑)
|
const drawerRef = ref<InstanceType<typeof UserDrawer> | null>(null);
|
const drawerRefAdd = ref<InstanceType<typeof UserDrawer> | null>(null);
|
const openAddDrawer = (title: string, row: Partial<User.ResUserList> = {}) => {
|
const params = {
|
title,
|
isView: title === "查看",
|
row: { ...row },
|
api: title === `${t("Config.add")}` ? addTag : title === `${t("Config.update")}` ? editTag : undefined,
|
getTableList: proTable.value?.getTableList
|
};
|
drawerRefAdd.value?.acceptParams(params);
|
};
|
const openDrawer = (title: string, row: Partial<User.ResUserList> = {}) => {
|
if (proTable.value?.selectedList.length < 1) {
|
ElMessage.error(t("Tag.selectDeviceFirst"));
|
return;
|
}
|
row.tagId = "";
|
for (let i = 0; i < proTable.value?.selectedList.length; i++) {
|
row.tagId += proTable.value?.selectedList[i].tagId + ";";
|
}
|
const params = {
|
title,
|
isView: title === "查看",
|
row: { ...row },
|
api: title === `${t("Config.add")}` ? null : title === `${t("Config.update")}` ? null : undefined,
|
getTableList: proTable.value?.getTableList
|
};
|
drawerRef.value?.acceptParams(params);
|
};
|
// 删除设备信息
|
const deleteAccount = async (params: User.ResUserList) => {
|
await useHandleData(deleteTag, { tagId: params.tagId }, t("Tag.deleteConfirm", { id: params.tagId }), t);
|
proTable.value?.getTableList();
|
};
|
</script>
|