JavaProjectRepo/business-css/frontend/src/views/business/database/device/index.vue

628 lines
18 KiB
Vue
Raw Normal View History

2025-12-24 16:36:15 +08:00
<script lang="ts">
export default {
name: "Device",
};
</script>
<script setup lang="ts">
import { onMounted, ref, nextTick } from "vue";
import { ElForm, ElMessage, ElMessageBox } from "element-plus";
import { searchDevicesPage,addDevices,updateDevices,deleteDevices,deleteBatchDevices,sizeSchemaAll,
exportAllExports} from "@/api/business/database/device";
2025-12-24 16:36:15 +08:00
import { getDictItemById } from '@/api/dict';
import Page from '@/components/Pagination/page.vue'
import { getToken } from '@/utils/auth'
const url = import.meta.env.VITE_APP_BASE_API;
// 搜索框
const queryParams:any = ref({
current: 1,
size: 10,
type: ''
});
//分页 总条数
const total = ref()
//定义表格数据
const tableData: any = ref([]);
const multipleSelection = ref([]);
2026-05-13 09:31:46 +08:00
//获取所有项目列表
const sizeSchemaInfo:any = ref({});
async function getSizeSchemaList(){
let result = await sizeSchemaAll({})
sizeSchemaInfo.value = result
}
2025-12-24 16:36:15 +08:00
// 表格加载
const loading = ref(false)
function gettableData() {
let params = {
name: input.value,
type: queryParams.value.type,
pageNum: queryParams.value.current,
pageSize: queryParams.value.size,
};
loading.value = true;
searchDevicesPage(params).then((result:any) => {
2026-01-16 10:12:14 +08:00
result.records.forEach((item:any) => {
2026-05-13 09:31:46 +08:00
item.size = JSON.parse(item.size)
2026-01-16 10:12:14 +08:00
})
2025-12-24 16:36:15 +08:00
tableData.value = result.records;
total.value = result.total;
loading.value = false;
}).catch((err) => {
loading.value = false;
});
}
//表格多选事件
function handleSelectionChange(val: any) {
multipleSelection.value = val;
}
const menuData:any = ref([])
// 查询字典项
function menuInit() {
let params = {
dictId: 'fe2c3418b8998f4e64d56ab46bfe0fed',
size:99,
current:1
}
getDictItemById(params).then((result: any) => {
menuData.value = result.data.records;
queryParams.value.type = menuData.value[0].itemCode
2026-05-13 09:31:46 +08:00
sourceTempData.value = sizeSchemaInfo.value[queryParams.value.type].fields
2025-12-24 16:36:15 +08:00
gettableData();
}).catch((err: any) => {
});
}
function handleMenu(row:any) {
queryParams.value.type = row.itemCode
2026-05-13 09:31:46 +08:00
sourceTempData.value = sizeSchemaInfo.value[queryParams.value.type].fields
2025-12-24 16:36:15 +08:00
gettableData()
}
const infoForm = ref();
//搜索内容及点击搜索按钮
const input = ref("");
//新建设备
const title = ref("");
const info: any = ref({
name: "",
code: "",
type: null,
size: null,
volume: null,
flowRate: null,
pulseVelocity: null
});
const dialogVisible = ref(false);
2026-05-13 09:31:46 +08:00
const sourceTempData:any = ref([])
2025-12-24 16:36:15 +08:00
function addClick() {
title.value = "新增设备";
info.value = {
name: "",
code: "",
type: queryParams.value.type,
2026-05-13 09:31:46 +08:00
size: {},
2025-12-24 16:36:15 +08:00
volume: null,
flowRate: null,
pulseVelocity: null
};
2026-05-13 09:31:46 +08:00
sourceTempData.value = sizeSchemaInfo.value[queryParams.value.type].fields
2026-05-19 15:23:21 +08:00
let rulesTemp:any = ref({})
sourceTempData.value.forEach((item:any) => {
info.value.size[item.key] = null
rulesTemp.value['size.' + item.key] = [{
validator: validator1,
trigger: 'blur'
}]
})
2026-05-13 09:31:46 +08:00
2026-05-19 15:23:21 +08:00
rules.value = {...rulesInfo.value,...rulesTemp.value}
2026-05-13 09:31:46 +08:00
2025-12-24 16:36:15 +08:00
dialogVisible.value = true;
}
//新建设备-确认按钮/修改按钮
function confirmClick(formEl: any) {
formEl.validate((valid: any) => {
if (valid) {
2025-12-24 17:14:19 +08:00
if (!info.value.deviceId) {
2025-12-24 16:36:15 +08:00
const params = {
projectId: -1,
...info.value,
2026-05-13 09:31:46 +08:00
size: JSON.stringify( info.value.size)
2025-12-24 16:36:15 +08:00
}
addDevices(params).then((res) => {
gettableData();
dialogVisible.value = false;
});
2025-12-24 17:14:19 +08:00
} else if (info.value.deviceId) {
2025-12-24 16:36:15 +08:00
const params = {
projectId: -1,
...info.value,
2026-05-13 09:31:46 +08:00
size: JSON.stringify( info.value.size)
2025-12-24 16:36:15 +08:00
}
updateDevices(params).then((res) => {
gettableData();
dialogVisible.value = false;
});
} else {
return false;
}
}
});
}
//新建角色-取消按钮
function handleClose() {
dialogVisible.value = false;
if (infoForm.value != null) infoForm.value.resetFields();
}
2026-05-19 15:23:21 +08:00
const validator1 = (rule: any, value: any, callback: any) => { // 校验数字是否大于0
if (value == null || value === '') {
callback();
return;
}
if (!/^\d+(\.\d+)?$/.test(value)) {
callback(new Error('请输入有效的数字或小数'));
} else if (parseFloat(value) <= 0) {
callback(new Error('数字必须大于 0'));
} else {
callback();
}
}
const rulesInfo = ref({
2025-12-24 16:36:15 +08:00
name: [{ required: true, message: "请输入设备名称", trigger: "blur" }],
code: [{ required: true, message: "请输入设备编码", trigger: "blur" }],
2026-05-19 15:23:21 +08:00
volume: [
{
validator: validator1,
trigger: 'blur'
}
],
flowRate: [
{
validator: validator1,
trigger: 'blur'
}
],
pulseVelocity: [
{
validator: validator1,
trigger: 'blur'
}
],
})
//新建设备
const rules = ref({...rulesInfo.value});
2025-12-24 16:36:15 +08:00
//修改设备
function editClick(row: any) {
title.value = "修改设备";
info.value = JSON.parse(JSON.stringify(row));
2026-05-13 09:31:46 +08:00
sourceTempData.value = sizeSchemaInfo.value[queryParams.value.type].fields
if(row.size == null || "object" != typeof row.size){
info.value.size = {}
sourceTempData.value.forEach((item:any) => {
info.value.size[item.key] = null
})
2025-12-24 16:36:15 +08:00
}
2026-05-19 15:23:21 +08:00
let rulesTemp:any = ref({})
sourceTempData.value.forEach((item:any) => {
rulesTemp.value['size.' + item.key] = [{
validator: validator1,
trigger: 'blur'
}]
})
rules.value = {...rulesInfo.value,...rulesTemp.value}
2025-12-24 16:36:15 +08:00
dialogVisible.value = true;
}
//删除设备
function delAloneClick(row: any) {
ElMessageBox.confirm("确定删除此设备吗?", "删除提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
let params = {
id: row.deviceId,
};
deleteDevices(params).then(() => {
gettableData();
ElMessage({
type: "success",
message: "删除成功",
});
});
})
}
// 多选删除?
function delClick() {
2026-01-21 09:57:53 +08:00
ElMessageBox.confirm("确定删除已选择设备吗?", "删除提示", {
2025-12-24 16:36:15 +08:00
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}).then(() => {
let id = [] as any[];
multipleSelection.value.forEach((item: any) => {
id.push(item.deviceId)
})
let params = {
ids: id,
};
deleteBatchDevices(params.ids).then(() => {
gettableData();
ElMessage({
message: "删除成功",
type: "success",
});
});
});
}
function dateFormat(row: any) {
const daterc = row;
if (daterc != null) {
var date = new Date(daterc);
var year = date.getFullYear();
var month =
date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
// 拼接
return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
}
}
function handlePreview(){
// loadingtext.value = "正在导入数据,请耐心等待!"
loading.value = true
}
const upload:any = ref(null)
function handlesSuccess(file: any) {
if(file !== false){
ElMessage({
message: "导入成功!",
type: "success",
});
}else{
ElMessage({
message: "导入失败!",
type: "error",
});
}
gettableData()
upload.value.clearFiles()
}
function handleError(file: any){
loading.value = false
ElMessage({
message: "导入失败!",
type: "error",
});
upload.value.clearFiles()
}
const josnInfo:any = ref({})
onMounted(() => {
2026-05-13 09:31:46 +08:00
getSizeSchemaList()
2025-12-24 16:36:15 +08:00
menuInit()
});
2026-04-15 10:55:14 +08:00
function exportExportsClick(){
exportAllExports(queryParams.value.type).then((response:any) => {
downloadFile(response, '设备数据' , 'xlsx')
});
}
function downloadFile(obj :any, name :any, suffix :any) {
const url = window.URL.createObjectURL(new Blob([obj]))
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
const fileName = name.trim() + '.' + suffix
link.setAttribute('download', fileName)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
2025-12-24 16:36:15 +08:00
</script>
<template>
<div class="Device-box">
<div class="conductproject-bg-leftBox">
<div class="menu-title">
设备类型
</div>
<div v-for="(item,index) in menuData"
:key="index" :class="{'menu-list-active': item.itemCode == queryParams.type }" class="menu-list"
@click="handleMenu(item)">
{{ item.dictName }}
</div>
</div>
<div class="conductproject-bg-box">
<div
style="display: flex;display: -webkit-flex; justify-content: space-between; -webkit-justify-content: space-between;margin-bottom: 10px">
<div style="display: flex;display: -webkit-flex;">
<el-input v-model="input" placeholder="请输入设备名称" @keyup.enter="gettableData" style="width: 200px" clearable />
<el-button type="primary" style="margin-left: 10px" @click="gettableData">搜索</el-button>
</div>
<div style="display: flex;display: -webkit-flex;">
2026-04-02 16:09:18 +08:00
<el-button type="primary" @click="addClick" v-hasPerm="['device:add']">
2025-12-24 16:36:15 +08:00
新增</el-button>
<el-upload
ref="upload"
2026-04-02 16:09:18 +08:00
accept=".xlsx,.xls" v-hasPerm="['device:import']"
2025-12-24 16:36:15 +08:00
class="upload-demo"
:data="{deviceType: queryParams.type}"
:action=" url + '/devices/v2/import' "
2025-12-24 16:36:15 +08:00
:headers="{ token: getToken() }"
:show-file-list="false"
:before-upload="handlePreview"
:on-success="handlesSuccess"
:on-error="handleError">
<el-button type="primary" style="margin: 0 10px;">导入</el-button>
</el-upload>
<el-button type="primary" @click="exportExportsClick">导出</el-button>
2026-04-15 14:36:18 +08:00
<el-button :type="multipleSelection.length > 0 ? 'primary' : ''" v-hasPerm="['device:del']"
2025-12-24 16:36:15 +08:00
:disabled="multipleSelection.length <= 0" @click="delClick">删除</el-button>
</div>
</div>
<el-table v-loading="loading" :data="tableData" style="width: 100%; height: calc(100vh - 260px);margin-bottom: 10px;" border
@selection-change="handleSelectionChange"
:header-cell-style="{ background: 'rgb(250 250 250)', color: '#383838', height: '50px' }">
<el-table-column type="selection" width="50" align="center"></el-table-column>
<el-table-column type="index" label="序号" width="70" align="center"></el-table-column>
<el-table-column prop="name" label="设备名称" min-width="180"></el-table-column>
2026-01-16 10:12:14 +08:00
2026-05-13 09:31:46 +08:00
<el-table-column v-for="(item,index) in sourceTempData" :label="item.label" min-width="100">
<template #default="scope">
{{ scope.row.size[item.key] }}
</template>
</el-table-column>
2026-01-16 10:12:14 +08:00
<el-table-column prop="volume" label="容量(L)" width="120"></el-table-column>
<el-table-column prop="flowRate" label="流量(m³/h)" width="120"></el-table-column>
<el-table-column prop="pulseVelocity" label="脉冲速度(Hz)" width="120"></el-table-column>
2025-12-24 16:36:15 +08:00
<el-table-column prop="modifier" label="创建人" width="120"></el-table-column>
2026-01-21 13:39:59 +08:00
<el-table-column prop="createdAt" label="创建时间" width="200">
2025-12-24 16:36:15 +08:00
<template #default="scope">
2026-01-21 13:39:59 +08:00
{{ dateFormat(scope.row.createdAt) }}
2025-12-24 16:36:15 +08:00
</template>
</el-table-column>
<el-table-column fixed="right" label="操作" width="80" align="center">
<template #default="scope">
<span
style="display: flex;display: -webkit-flex; justify-content: space-around;-webkit-justify-content: space-around; ">
2026-04-02 16:09:18 +08:00
<img src="@/assets/table/edit.png" alt="" title="修改" v-hasPerm="['device:update']"
2025-12-24 16:36:15 +08:00
@click="editClick(scope.row)" style="cursor: pointer; ">
<img src="@/assets/table/del.png" alt="" title="删除"
2026-04-15 14:36:18 +08:00
@click="delAloneClick(scope.row)" style="cursor: pointer; " v-hasPerm="['device:del']">
2025-12-24 16:36:15 +08:00
</span>
</template>
</el-table-column>
</el-table>
<Page :total="total" v-model:size="queryParams.size" v-model:current="queryParams.current" @pagination="gettableData()" ></Page>
</div>
<el-dialog v-model="dialogVisible" :close-on-click-modal="false"
:modal="false" draggable :before-close="handleClose" :title="title"
2026-05-13 09:31:46 +08:00
append-to-body width="677px">
2025-12-24 16:36:15 +08:00
2026-05-13 09:31:46 +08:00
<el-form ref="infoForm" :model="info" :rules="rules" label-width="120px" v-if="dialogVisible == true"
style="max-height: calc(100vh - 120px);overflow: auto;">
2025-12-24 16:36:15 +08:00
<el-form-item label="设备编号" prop="code" style="width: 100%;">
<el-input v-model="info.code" style="width: 100%" placeholder="请输入设备编号"></el-input>
</el-form-item>
<el-form-item label="设备名称" prop="name" style="width: 100%;">
<el-input v-model="info.name" style="width: 100%" placeholder="请输入设备名称"></el-input>
</el-form-item>
2026-05-19 15:23:21 +08:00
<el-form-item :label="item.label" style="width: 100%;" v-for="item in sourceTempData" :prop="'size.' + item.key">
2026-05-13 09:31:46 +08:00
<el-input-number
placeholder="请输入长度"
v-model="info.size[item.key]"
:min="0"
align="left"
:controls="false"
style="width: 100%"
>
<template #suffix>{{item.unit}}</template>
</el-input-number>
</el-form-item>
2026-05-19 15:23:21 +08:00
<el-form-item label="容量" style="width: 100%;" prop="volume">
2026-04-15 10:55:14 +08:00
<el-input-number
placeholder="请输入容量"
v-model="info.volume"
:min="0"
align="left"
:controls="false"
style="width: 100%"
>
<template #suffix>L</template>
</el-input-number>
2025-12-24 16:36:15 +08:00
</el-form-item>
2026-05-19 15:23:21 +08:00
<el-form-item label="流量" style="width: 100%;" prop="flowRate">
2026-04-15 10:55:14 +08:00
<el-input-number
placeholder="请输入流量"
v-model="info.flowRate"
:min="0"
align="left"
:controls="false"
style="width: 100%"
>
<template #suffix>/h</template>
</el-input-number>
2025-12-24 16:36:15 +08:00
</el-form-item>
2026-05-19 15:23:21 +08:00
<el-form-item label="脉冲速度" style="width: 100%;" prop="pulseVelocity">
2026-04-15 10:55:14 +08:00
<el-input-number
placeholder="请输入脉冲速度"
v-model="info.pulseVelocity"
:min="0"
align="left"
:controls="false"
style="width: 100%"
>
<template #suffix>Hz</template>
</el-input-number>
2025-12-24 16:36:15 +08:00
</el-form-item>
<span class="dialog-footer"
style="display: flex;display: -webkit-flex; justify-content: flex-end;-webkit-justify-content: flex-end;">
<el-button @click="handleClose"> </el-button>
<el-button type="primary" @click="confirmClick(infoForm)"> </el-button>
</span>
</el-form>
</el-dialog>
</div>
</template>
<style scoped>
.Device-box {
padding-right: 10px;
display: flex;
justify-content: space-between;
}
.dialog-footer {
display: block;
margin-top: 20px;
}
.conductproject-bg-leftBox{
width: 240px;
height: calc(100vh - 130px);
overflow: auto;
padding: 0px 0px;
background-color: rgba(255, 255, 255, 1);
border: none;
border-radius: 3px;
box-sizing: border-box;
}
.menu-list{
width: 220px;
height: 40px;
line-height: 40px;
box-sizing: border-box;
padding-left: 30px;
font-family: 'Arial Normal', 'Arial', sans-serif;
font-weight: 400;
font-style: normal;
font-size: 14px;
letter-spacing: normal;
color: #333333;
margin-left: 10px;
cursor: pointer;
}
.menu-list:hover{
background-color: #f9f9f9;
}
.menu-list-active{
background-color: #eaf1ff !important;
color: rgb(38, 111, 255) ;
}
.conductproject-bg-box {
padding: 20px;
width: calc(100% - 255px);
height: calc(100vh - 130px);
overflow: auto;
background-color: rgba(255, 255, 255, 1);
border: none;
border-radius: 3px;
box-sizing: border-box;
}
.menu-title{
width: 100%;
height: 50px;
line-height: 50px;
border-bottom: 1px solid rgba(242, 242, 242, 1);
font-family: 'Arial Negreta', 'Arial Normal', 'Arial', sans-serif;
font-weight: 700;
font-style: normal;
font-size: 15px;
color: #363636;
padding-left: 20px;
}
</style>
<style>
.el-dialog {
padding: 0 !important;
border-radius: 10px !important;
border: 1px solid #363636 !important;
2026-05-13 09:31:46 +08:00
margin-top: 20px !important;
2025-12-24 16:36:15 +08:00
}
.el-dialog .el-dialog__header{
display: flex;
display: -webkit-flex;
justify-content: flex-start;-webkit-justify-content: flex-start;
align-items: center;-webkit-align-items: center;
padding: 10px 20px;
background-color: #f1f3f8 !important;
font-family: 'Arial Negreta', 'Arial Normal', 'Arial', sans-serif;
font-weight: 700;
font-style: normal;
font-size: 16px;
color: #1B1B1B;
text-align: left;
border-radius: 10px 10px 0 0;
height: 50px;
}
.el-dialog .el-dialog__close{
font-size: 22px;
color: rgb(80, 80, 80);
}
.el-dialog .el-dialog__headerbtn{
display: flex;
align-items: center;
}
.el-dialog .el-dialog__body{
padding: 20px 40px !important;
}
.el-dialog .el-input{
--el-input-inner-height: 38px
}
.Device-box .el-button{
height: 36px;
}
2025-12-24 16:36:15 +08:00
.el-dialog .el-button{
height: 40px;
}
2025-12-24 16:36:15 +08:00
.el-input-group__append {
background-color: transparent !important;
border: none !important;
}
2026-04-15 10:55:14 +08:00
2025-12-24 16:36:15 +08:00
</style>