157 lines
4.0 KiB
Vue
157 lines
4.0 KiB
Vue
|
<template>
|
||
|
<div>
|
||
|
<!--引用表格-->
|
||
|
<BasicTable @register="registerTable">
|
||
|
<!--插槽:table标题-->
|
||
|
<template #tableTitle>
|
||
|
<a-button type="primary" preIcon="ant-design:plus-outlined" @click="handleInsert"> 添加设备</a-button>
|
||
|
</template>
|
||
|
<template #bodyCell="{ column, record, index, text }">
|
||
|
<template v-if="column.dataIndex === 'status'">
|
||
|
<span v-if="record.status ==='0'" style="color:green">
|
||
|
在线
|
||
|
</span>
|
||
|
<span v-else style="color:red">
|
||
|
离线
|
||
|
</span>
|
||
|
</template>
|
||
|
</template>
|
||
|
<!--操作栏-->
|
||
|
<template #action="{ record }">
|
||
|
<TableAction :actions="getTableAction(record)"/>
|
||
|
</template>
|
||
|
</BasicTable>
|
||
|
<DeviceInfoDrawer @register="registerDrawer" @success="handleSuccess" />
|
||
|
<ApiLogAlarmModal ref="apiLogAlarmModal"></ApiLogAlarmModal>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script lang="ts" name="iot-nuIotRegionInfo" 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";
|
||
|
import {list, deleteDevice, updateDeviceRealTime} from './humid.api';
|
||
|
import { columns, searchFormSchema } from './humid.data';
|
||
|
import {useModal} from "@/components/Modal";
|
||
|
import {useDrawer} from "@/components/Drawer";
|
||
|
import ApiLogAlarmModal from './components/ApiLogAlarmModal.vue'
|
||
|
const apiLogAlarmModal = ref();
|
||
|
//注册drawer
|
||
|
const [registerDrawer, { openDrawer }] = useDrawer();
|
||
|
const queryParam = reactive<any>({});
|
||
|
//注册model
|
||
|
const [registerModal, {openModal}] = useModal();
|
||
|
//注册table数据
|
||
|
const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
|
||
|
tableProps:{
|
||
|
title: '温湿度',
|
||
|
api: list,
|
||
|
columns,
|
||
|
canResize:false,
|
||
|
showIndexColumn: true,
|
||
|
formConfig: {
|
||
|
//labelWidth: 120,
|
||
|
schemas: searchFormSchema,
|
||
|
autoSubmitOnEnter:true,
|
||
|
showAdvancedButton:true,
|
||
|
fieldMapToNumber: [
|
||
|
],
|
||
|
fieldMapToTime: [
|
||
|
],
|
||
|
},
|
||
|
actionColumn: {
|
||
|
width: 200,
|
||
|
fixed:'right'
|
||
|
},
|
||
|
beforeFetch: (params) => {
|
||
|
return Object.assign(params, queryParam);
|
||
|
},
|
||
|
},
|
||
|
})
|
||
|
|
||
|
const [registerTable, {reload},{ rowSelection, selectedRowKeys }] = tableContext
|
||
|
|
||
|
/**
|
||
|
* 成功回调
|
||
|
*/
|
||
|
function handleSuccess() {
|
||
|
(selectedRowKeys.value = []) && reload();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 操作栏
|
||
|
*/
|
||
|
function getTableAction(record){
|
||
|
return [
|
||
|
{
|
||
|
label: '抄表',
|
||
|
onClick: handleRead.bind(null, record),
|
||
|
},
|
||
|
{
|
||
|
label: '编辑',
|
||
|
onClick: handleEdit.bind(null, record),
|
||
|
},
|
||
|
{
|
||
|
label: '删除',
|
||
|
popConfirm: {
|
||
|
title: '是否确认删除',
|
||
|
confirm: handleDelete.bind(null, record),
|
||
|
placement: 'topLeft',
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
label: '日志',
|
||
|
onClick: handleApiLogAlarm.bind(null, record),
|
||
|
},
|
||
|
]
|
||
|
}
|
||
|
|
||
|
// 抄电表
|
||
|
async function handleRead(record: Recordable) {
|
||
|
const params = {
|
||
|
'sn' : record.sn,
|
||
|
};
|
||
|
await updateDeviceRealTime(params);
|
||
|
handleSuccess()
|
||
|
}
|
||
|
|
||
|
function handleInsert(){
|
||
|
let record = {};
|
||
|
record["isUpdate"] = false;
|
||
|
openDrawer(true, {
|
||
|
isUpdate: false,
|
||
|
showFooter: true,
|
||
|
tenantSaas: false,
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// 编辑
|
||
|
async function handleEdit(record: Recordable) {
|
||
|
record["isUpdate"] = true;
|
||
|
console.log(record);
|
||
|
openDrawer(true, {
|
||
|
record,
|
||
|
isUpdate: true,
|
||
|
showFooter: true,
|
||
|
tenantSaas: false,
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// 删除
|
||
|
async function handleDelete(record: Recordable) {
|
||
|
const params = {
|
||
|
'sn' : record.sn,
|
||
|
};
|
||
|
await deleteDevice(params);
|
||
|
handleSuccess();
|
||
|
}
|
||
|
|
||
|
function handleApiLogAlarm(record){
|
||
|
apiLogAlarmModal.value.disableSubmit = true;
|
||
|
apiLogAlarmModal.value.showLogAlarm(record);
|
||
|
}
|
||
|
|
||
|
</script>
|