hldy_yunwei_vue/src/views/iot/hs/electricity/index.vue

230 lines
6.1 KiB
Vue
Raw Normal View History

2026-03-04 17:41:12 +08:00
<template>
<div>
<!--引用表格-->
<BasicTable @register="registerTable">
<!--插槽:table标题-->
<template #tableTitle>
<a-button type="primary" preIcon="ant-design:plus-outlined" @click="handleAdd"> 添加设备</a-button>
</template>
<template #bodyCell="{ column, record, index, text }">
<template v-if="column.dataIndex === 'relayState'">
2026-03-05 11:03:48 +08:00
<span v-if="record.relayState ==null||record.relayState ===''" style="color:red">
未知
2026-03-04 17:41:12 +08:00
</span>
2026-03-05 11:03:48 +08:00
<span v-else>
<span v-if="record.relayState ==='1'" style="color:green">
合闸
</span>
<span v-if="record.relayState ==='0'" style="color:red">
2026-03-05 17:12:00 +08:00
拉闸
2026-03-05 11:03:48 +08:00
</span>
2026-03-04 17:41:12 +08:00
</span>
</template>
</template>
<!--操作栏-->
<template #action="{ record }">
<TableAction :actions="getTableAction(record)"/>
</template>
</BasicTable>
<ApiLogModal ref="apiLogModal"></ApiLogModal>
<DrawerModal ref="registerDrawer" @success="handleSuccess" />
<a-modal v-model:visible="tipVisible" width="300px">
<template #title>
<Icon icon="ant-design:info-circle-outlined" :size="20" style="margin-right:10px;color:white;background:#1ea0fa;border-radius:10px;"/>{{tipTitle}}
</template>
<div style="text-align: center;margin: 40px 0;">
{{tipContent}}
</div>
<template #footer style="text-align: center;">
<a-button type="primary" style="margin-right: 35%" @click="handleCancel">知道了</a-button>
</template>
</a-modal>
</div>
</template>
<script lang="ts" name="iot-nuIotElectricitynInfo" setup>
import {reactive, ref,h} from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { useListPage } from '/@/hooks/system/useListPage';
import { useUserStore } from '/@/store/modules/user';
import {Modal} from "ant-design-vue";
2026-03-05 11:03:48 +08:00
import {list, save, deleteMeter, eleReset, eleCutOff, eleConnected, eleRead} from './electricity.api';
2026-03-04 17:41:12 +08:00
import { columns, searchFormSchema } from './electricity.data';
import {useModal} from "@/components/Modal";
2026-03-09 11:21:19 +08:00
import ApiLogModal from "/@/views/iot/tq/electricity/apilog/ApiLogModal.vue";
2026-03-04 17:41:12 +08:00
import DrawerModal from "./components/DrawerModal.vue";
import { defHttp } from '/@/utils/http/axios';
const queryParam = reactive<any>({});
const apiLogModal = ref();
const registerDrawer = ref();
const tipVisible = ref(false);
const tipTitle = ref('提示');
const tipContent = ref('');
//注册model
const [registerModal, {openModal}] = useModal();
//注册table数据
const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
tableProps:{
title: '智能电表',
api: list,
columns,
canResize:false,
2026-03-05 11:03:48 +08:00
// showIndexColumn: true,
2026-03-04 17:41:12 +08:00
formConfig: {
//labelWidth: 120,
schemas: searchFormSchema,
autoSubmitOnEnter:true,
showAdvancedButton:false,
fieldMapToNumber: [
],
fieldMapToTime: [
],
},
actionColumn: {
width: 290,
fixed:'right'
},
beforeFetch: (params) => {
return Object.assign(params, queryParam);
},
},
})
const [registerTable, {reload},{ rowSelection, selectedRowKeys }] = tableContext
/**
* 编辑
*/
function handleAdd() {
registerDrawer.value.disableSubmit = false;
registerDrawer.value.add();
}
function handleCancel() {
tipVisible.value = false;
}
/**
* 成功回调
*/
function handleSuccess() {
(selectedRowKeys.value = []) && reload();
}
/**
* 操作栏
*/
function getTableAction(record){
return [
{
label: '删除',
2026-03-05 11:03:48 +08:00
popConfirm: {
title: '是否确认删除数据',
confirm: handleDelete.bind(null, record),
placement: 'topLeft',
},
2026-03-04 17:41:12 +08:00
ifShow: record.izAllocate != 'Y',
},
{
label: '抄表',
onClick: handleRead.bind(null, record),
},
{
label: '拉闸',
popConfirm: {
title: '是否确认拉闸',
confirm: handleControlLz.bind(null, record),
placement: 'topLeft',
},
ifShow: record.relayState == 1,
},
{
label: '合闸',
popConfirm: {
title: '是否确认合闸',
confirm: handleControlHz.bind(null, record),
placement: 'topLeft',
},
ifShow: record.relayState == 0,
},
{
label: '清零',
popConfirm: {
title: '是否确认清零',
confirm: handleReset.bind(null, record),
placement: 'topLeft',
},
},
2026-03-05 17:12:00 +08:00
// {
// label: '日志',
// onClick: showApiLog.bind(null, record),
// },
2026-03-04 17:41:12 +08:00
]
}
2026-03-05 11:03:48 +08:00
// 删除
async function handleDelete(record: Recordable) {
2026-03-05 17:12:00 +08:00
await deleteMeter(record);
2026-03-05 11:03:48 +08:00
reload();
}
2026-03-04 17:41:12 +08:00
// 抄电表
async function handleRead(record: Recordable) {
const params = {
2026-03-05 11:03:48 +08:00
'sn' : record.sn,
2026-03-04 17:41:12 +08:00
};
await eleRead(params);
reload();
}
// 电表拉闸
async function handleControlLz(record: Recordable) {
if(record.relayState == '0'){
tipVisible.value=true;
tipTitle.value = "拉闸";
tipContent.value = "此电表已拉闸!";
return;
}
const params = {
'sn' : record.sn
};
await eleCutOff(params);
reload();
}
// 电表合闸
async function handleControlHz(record: Recordable) {
if(record.relayState == '1'){
tipVisible.value=true;
tipTitle.value = "合闸";
tipContent.value = "此电表已合闸!";
return;
}
const params = {
'sn' : record.sn
};
await eleConnected(params);
reload();
}
// 电表清零
async function handleReset(record: Recordable) {
const params = {
'sn' : record.sn
};
await eleReset(params);
reload();
}
/**
* 查看api日志
*/
function showApiLog(record){
console.log(record);
apiLogModal.value.disableSubmit = true;
apiLogModal.value.showApiLog(record);
}
</script>