Commit 326b1c15 authored by xuke's avatar xuke

表单校验

parent 10e2e52a
This diff is collapsed.
...@@ -110,9 +110,14 @@ const timeFormat = (time) => { ...@@ -110,9 +110,14 @@ const timeFormat = (time) => {
const rules = reactive({ const rules = reactive({
supplyId: [{ required: true, message: "名称是必填项", trigger: "blur" }], supplyId: [{ required: true, message: "名称是必填项", trigger: "blur" }],
energyType: [ energyType: [
{ required: true, message: "能源类型是必填项", trigger: "blur" }, { required: true, message: "能源类型是必填项", trigger: "blur" }
],
record: [
{ required: true, message: "能源用度是必选项", trigger: "blur" },
{ pattern: /^(-?[0-9]+(\.[0-9]+)?){1,10}$/, message: "能源用度必须输入1-10位数字", trigger: "blur" },
{ min: 1, max: 10, message: '能源用度必须是 1-10位的数字', trigger: 'blur' }
], ],
record: [{ required: true, message: "能源用度是必选项", trigger: "blur" }],
recordDate: [{ required: true, message: "日期是必选项" }], recordDate: [{ required: true, message: "日期是必选项" }],
}); });
...@@ -125,15 +130,19 @@ const handleDelete = (row) => { ...@@ -125,15 +130,19 @@ const handleDelete = (row) => {
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning', type: 'warning',
confirmButtonClass: 'ExitConfirmButton' confirmButtonClass: 'ExitConfirmButton'
}).then(() => {
http.post("api/energy/Delete", { id: row.energyId }, false).then(res => {
if (res.success) {
ElMessage.success(res.message)
getEnergyData();
} else {
ElMessage.error("删除失败");
}
})
}).catch(() => {
ElMessage.success("取消删除操作");
}) })
http.post("api/energy/Delete", { id: row.energyId }, false).then(res => {
if (res.success) {
ElMessage.success(res.message)
getEnergyData();
} else {
ElMessage.error("删除失败");
}
})
}; };
...@@ -317,9 +326,8 @@ onMounted(() => { ...@@ -317,9 +326,8 @@ onMounted(() => {
<table cellpadding="0" cellspacing="0"> <table cellpadding="0" cellspacing="0">
<tr> <tr>
<td style="text-align: left"> <td style="text-align: left">
<el-form-item prop="supplyName" style="margin: 0; padding: 0; width: 100%"> <el-form-item prop="supplyName" style="margin: 0; padding: 0; width: 100%;">
<el-select v-model="formEnergy.supplyId" placeholder="" style="width: 210px;" class="custom-select" <el-select v-model="formEnergy.supplyId" placeholder="请选择">
size="small">
<el-option v-for="item in supplyData" :key="item.supplyId" :label="item.supplyName" <el-option v-for="item in supplyData" :key="item.supplyId" :label="item.supplyName"
:value="item.supplyId" /> :value="item.supplyId" />
</el-select> </el-select>
......
...@@ -5,76 +5,85 @@ ...@@ -5,76 +5,85 @@
<div class="card-header"> <div class="card-header">
<span>瞬时热量对比配置</span> <span>瞬时热量对比配置</span>
</div> </div>
<table v-loading="loading" cellpadding="0" cellspacing="1"> <el-form ref="formRef" :rules="rules" :model="List" label-width="auto">
<tr> <table v-loading="loading" cellpadding="0" cellspacing="1">
<th style="width: 25%">计划名称:</th> <tr>
<td style="width: 60%; margin:0; padding: 0"> <th style="width: 25%">计划名称:</th>
<table cellpadding="0" cellspacing="0"> <td style="width: 60%; margin:0; padding: 0">
<tr> <table cellpadding="0" cellspacing="0">
<td style="text-align: left"> <tr>
<el-input style="width: 80%" v-model="List.planName"></el-input> <td style="text-align: left">
</td> <el-input style="width: 80%" v-model="List.planName"></el-input>
</tr> </td>
</table> </tr>
</td> </table>
</tr> </td>
<tr> </tr>
<th style="width: 25%">偏差百分比 (%):</th> <tr>
<td style="width: 60%; margin: 0; padding: 0"> <th style="width: 25%">偏差百分比 (%):</th>
<table cellpadding="0" cellspacing="0"> <td style="width: 60%; margin: 0; padding: 0">
<tr> <table cellpadding="0" cellspacing="0">
<td style="text-align: left"> <tr>
<el-input v-float-number style="width: 80%" v-model="List.diffPercentage"></el-input> <td style="text-align: left">
</td> <el-form-item prop="diffPercentage" style="padding: 0;margin: 0;">
</tr> <el-input v-float-number style="width: 80%" v-model="List.diffPercentage"></el-input>
</table> </el-form-item>
</td> </td>
</tr> </tr>
</table>
</td>
<tr> </tr>
<th style="width: 25%">判断时间 (分):</th>
<td style="width: 60%; margin: 0; padding: 0">
<table cellpadding="0" cellspacing="0"> <tr>
<tr> <th style="width: 25%">判断时间 (分):</th>
<td style="text-align: left"> <td style="width: 60%; margin: 0; padding: 0">
<el-input style="width: 80%" v-model="List.timeoutMin"></el-input> <table cellpadding="0" cellspacing="0">
</td> <tr>
</tr> <td style="text-align: left">
</table> <el-form-item prop="timeoutMin" style="padding: 0;margin: 0;">
</td> <el-input style="width: 80%" v-model="List.timeoutMin"></el-input>
</tr> </el-form-item>
</td>
</tr>
<tr> </table>
<th style="width: 25%">调节温度 (℃)</th> </td>
<td style="width: 60%; margin: 0; padding: 0"> </tr>
<table cellpadding="0" cellspacing="0">
<tr>
<td style="text-align: left"> <tr>
<el-input v-float-number style="width: 80%" v-model="List.tempRegulation"></el-input> <th style="width: 25%">调节温度 (℃)</th>
</td> <td style="width: 60%; margin: 0; padding: 0">
</tr> <table cellpadding="0" cellspacing="0">
</table> <tr>
</td> <td style="text-align: left">
</tr> <el-form-item prop="tempRegulation" style="padding: 0;margin: 0;">
<el-input v-float-number style="width: 80%" v-model="List.tempRegulation"></el-input>
</el-form-item>
<tr> </td>
<th style="width: 25%">备注</th> </tr>
<td style="width: 60%; margin: 0; padding: 0"> </table>
<table cellpadding="0" cellspacing="0"> </td>
<tr> </tr>
<td style="text-align: left">
<el-input style="width: 80%" type="textarea" rows="6" v-model="List.description"></el-input>
</td> <tr>
</tr> <th style="width: 25%">备注</th>
</table> <td style="width: 60%; margin: 0; padding: 0">
</td> <table cellpadding="0" cellspacing="0">
</tr> <tr>
<td style="text-align: left">
<el-input style="width: 80%" type="textarea" rows="6" v-model="List.description"></el-input>
</table> </td>
</tr>
</table>
</td>
</tr>
</table>
</el-form>
<div class="btngrounp"> <div class="btngrounp">
<el-button type="primary" @click="onSave">保存</el-button> <el-button type="primary" @click="onSave">保存</el-button>
<el-button type="primary" style="margin: 0 0 0 5px" @click="onCancel">关闭</el-button> <el-button type="primary" style="margin: 0 0 0 5px" @click="onCancel">关闭</el-button>
...@@ -92,7 +101,7 @@ import { ElMessage } from "element-plus"; ...@@ -92,7 +101,7 @@ import { ElMessage } from "element-plus";
import http from "../../api/http"; import http from "../../api/http";
import { vFloatNumber } from "@/utils/directives.js"; import { vFloatNumber } from "@/utils/directives.js";
const loading = ref(false) const loading = ref(false)
const formRef = ref()
const List = ref( const List = ref(
{ {
...@@ -105,7 +114,24 @@ const List = ref( ...@@ -105,7 +114,24 @@ const List = ref(
"isActive": '' "isActive": ''
} }
) )
//校验规则
const rules = reactive({
diffPercentage: [
{ required: true, message: "偏差百分比是必填项", trigger: "blur" },
{ pattern: /^(-?[0-9]+(\.[0-9]+)?){1,10}$/, "message": "偏差百分比输入不合法", trigger: 'blur' },
{ min: 1, max: 10, message: '偏差百分比必须是 1-10位的数字', trigger: 'blur' }
],
timeoutMin: [
{ required: true, message: "判断时间是必填项", trigger: "blur" },
{ pattern: /^[0-9]\d{1,10}$/, "message": "判断时间必须是 1-10位的数字", trigger: 'blur' }
],
tempRegulation: [
{ required: true, message: "调节温度是必选项", trigger: "blur" },
{ pattern: /^(-?[0-9]+(\.[0-9]+)?)$/, "message": "调节温度输入不合法", trigger: 'blur' },
{ min: 1, max: 10, message: '调节温度必须是 1-10位的数字', trigger: 'blur' }
]
});
const getInstanceHeat = () => { const getInstanceHeat = () => {
loading.value = true loading.value = true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment