智能大气腐蚀检测平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

213 lines
7.8 KiB

<template>
<SearchBar @search="onSearch" />
<div class="my-3">
<el-button type="primary" @click="deviceCreate.show()">
<i class="el-icon-plus mr-2"></i>
添加设备
</el-button>
</div>
<template v-if="devicesAll && devicesAll.data">
<el-table :data="devicesAll.data" :max-height="contentHeight" border stripe style="width: 100%">
<el-table-column type="expand">
<template #default="props">
<el-row :gutter="20" class="px-6 text-gray-400">
<el-col :span="9">链路地址:{{ props.row.linkAddress }}</el-col>
<el-col :span="9">探头编号:{{ props.row.probNo }}</el-col>
<el-col :span="9">设备朝向:{{ props.row.deviceDirection }}</el-col>
<el-col :span="9">试样:{{ props.row.simple }}</el-col>
<el-col :span="9">安装位置:{{ props.row.installLocation }}</el-col>
<el-col :span="9">sim1:{{ props.row.sim1 }}</el-col>
<el-col :span="9">协议版本:{{ props.row.protocolVersion }}</el-col>
<el-col :span="9">产品类型:{{ ASDU_TYPE[props.row.type].text }}</el-col>
<el-col :span="9">与主站后台联调情况:{{ props.row.joint }}</el-col>
<el-col :span="9">备注:{{ props.row.remark }}</el-col>
<el-col :span="9">维修记录{{ props.row.operationRecord }}</el-col>
</el-row>
</template>
</el-table-column>
<el-table-column align="center" label="设备ID" min-width="100" prop="deviceId" />
<el-table-column align="center" label="设备完整ID" min-width="150" prop="deviceFullId" />
<el-table-column align="left" header-align="center" label="站点" min-width="150" prop="address" />
<el-table-column align="left" header-align="center" label="地区" min-width="120" prop="area" />
<el-table-column align="center" label="状态" min-width="70">
<template #default="scope">
<el-tag v-if="scope.row.status" :color="STATUS_COLOR[scope.row.status].color" style="color: #fff">
{{ STATUS_COLOR[scope.row.status].text }}
</el-tag>
</template>
</el-table-column>
<el-table-column align="center" label="联系人" min-width="100" prop="contact" />
<el-table-column align="center" label="联系电话" min-width="150" prop="phone" />
<el-table-column align="center" label="安装时间" min-width="200" prop="installTime" />
<el-table-column align="center" label="正式运行时间" min-width="200" prop="runTime" />
<el-table-column align="center" fixed="right" label="操作" min-width="180">
<template #default="props">
<el-tooltip class="item" content="参数配置" effect="dark" placement="top">
<i class="el-icon-set-up text-base text-yellow-600 mx-1" @click="openPage(props.row, 'config')"></i>
</el-tooltip>
<el-tooltip class="item" content="实时数据" effect="dark" placement="top">
<i class="el-icon-odometer text-base text-green-600 mx-1" @click="openPage(props.row, 'data-realtime')"></i>
</el-tooltip>
<el-tooltip class="item" content="历史数据" effect="dark" placement="top">
<i class="el-icon-document-copy text-base text-green-600 mx-1" @click="openPage(props.row, 'history')"></i>
</el-tooltip>
<el-tooltip class="item" content="数据统计" effect="dark" placement="top">
<i class="el-icon-data-line text-base text-green-600 mx-1" @click="openPage(props.row, 'statistical')"></i>
</el-tooltip>
<el-popconfirm title="确定要删除此设备吗?" @confirm="handleDelete(props.row.deviceId)">
<template #reference>
<i class="el-icon-delete text-base text-red-600 mx-1"></i>
<!-- <el-button type="text" plain size="mini" icon="el-icon-delete"></el-button> -->
</template>
</el-popconfirm>
<el-tooltip class="item" content="编辑设备信息" effect="dark" placement="top">
<i class="el-icon-edit text-base text-blue-600 mx-1" @click="handleEdit(props.row)"></i>
</el-tooltip>
</template>
</el-table-column>
</el-table>
<el-pagination
:current-page="devicesAll.page.page"
:default-page-size="50"
:page-count="devicesAll.page.count"
:page-size="devicesAll.page.size"
:page-sizes="[1, 10, 20, 50, 100]"
:total="devicesAll.page.total"
background
class="my-3 float-right"
layout="total, sizes, prev, pager, next, jumper"
@size-change="onSizeChange"
@current-change="onCurrentPageChange"
></el-pagination>
</template>
<!-- 编辑设备信息 -->
<DeviceEdit :show="editing" @toggle-mdoal="editing = false" />
<el-dialog v-model="deviceCreate.display" title="添加设备" top="30px" width="80%">
<DeviceCreate @on-hide="deviceCreate.hide()" />
</el-dialog>
</template>
<script setup>
import { computed, onMounted, reactive, ref } from 'vue';
import { useStore } from 'vuex';
import { useRoute, useRouter } from 'vue-router';
import { deleteDevice } from 'apis';
import { ElMessage } from 'element-plus';
import SearchBar from 'components/realtime/search-bar.vue';
import DeviceEdit from 'components/device/device-edit.vue';
import DeviceCreate from 'components/device/device-create.vue';
import useDeviceCreate from '@/hooks/useDeviceCreate';
import { STATUS_COLOR } from '@/config/config';
import { ASDU_TYPE } from '@/config/log';
let timer = null;
const store = useStore();
const router = useRouter();
const route = useRoute();
const token = computed(() => store.getters['user/token']);
const devicesAll = computed(() => {
return store.state.device.devicesAll;
});
const currentDeviceId = computed(() => store.state.device.currentDeviceId);
const contentHeight = ref(600);
const editing = ref(false);
const { show, display, hide } = useDeviceCreate();
const deviceCreate = reactive({
show,
display,
hide,
}); // 设备添加hook
// 获取设备完整信息列表
const getDevicesAllData = () => {
try {
if (token && token.value) {
store.dispatch('device/getDevicesAll');
timer && clearTimeout(timer);
timer = null;
} else {
timer = setTimeout(() => {
getDevicesAllData();
});
}
} catch (error) {
ElMessage.error(error);
throw new Error(error);
}
};
getDevicesAllData();
// 设置表格高度
onMounted(() => {
const winHeight = document.documentElement.clientHeight;
contentHeight.value = winHeight - 250;
});
/**
* 删除
* @param {number} page 页码
* @param {number} size 每页条数
*/
function onSearch(page, size = 50) {
const deviceId = currentDeviceId.value;
const params = {
deviceId,
page,
size,
};
store.dispatch('device/getDevicesAll', params);
}
// 当前页码变化
const onCurrentPageChange = page => {
onSearch(page, devicesAll.value.page.size || 50);
};
// 每页条数变化
const onSizeChange = size => {
onSearch(1, size);
};
/**
* 删除某设备
* @param {string} deviceId 设备id
*/
const handleDelete = async deviceId => {
try {
await deleteDevice(deviceId);
store.commit('device/deleteDevice', deviceId);
ElMessage.success('删除成功');
store.dispatch('device/getDevices'); // 更新站点列表
} catch (error) {
ElMessage.error('删除失败, 请稍后重试');
throw new Error(error);
}
};
// 编辑设备信息
const handleEdit = item => {
store.commit('device/setCurrentDeviceId', item.deviceId);
editing.value = true;
};
/**
* 打开页面
* @param {object} item 设备对象
* @param {string} pageName 页面name
*/
const openPage = (item, pageName) => {
item && store.commit('device/setCurrentDeviceId', item.deviceId);
router.push({
path: `/corrosion/${pageName}`,
query: route.query,
});
};
</script>