Commit d44551fb authored by 裴文涛's avatar 裴文涛

增加表单检验规则及保存限制

parent b0a1bfb4
This diff is collapsed.
......@@ -10,9 +10,7 @@ import {
} from '@/api/scheduling.js'
import AddWindow from "./weatherManageSub/AddWindow.vue";
import {ElMessage, ElMessageBox} from "element-plus";
import store from "@/store/index.js";
import cloneDeep from 'lodash/cloneDeep'
import {vFloatNumber} from "@/utils/directives.js";
const data = ref()
const dataBackup = ref([]);
......@@ -30,7 +28,6 @@ const isAutoSearchKey = ref() // 手自动模式查询
const supplySearchKey = ref() // 供热站查询
const organizationStructure = ref([]) // 组织结构数据
const supplyData = ref([]) // 供热站数据
const transferStructData = ref([]) // 换热站结构数据,每个供热站和一定数量的换热站对应
function search() {
if(!isAutoSearchKey.value && !supplySearchKey.value){
......@@ -144,15 +141,14 @@ function handleAddWinOpenClose(){
addWindowOpen.value = false
}
function handleAdd(val){
console.log("新增数据",val)
alterWeatherMagData(val).then(res=>{
if(res.success){
ElMessage({
message: res.message,
type: 'success',
})
getData()
addWindowOpen.value = false
getData()
}else {
ElMessage({
message: res.message,
......@@ -190,31 +186,10 @@ function getSupply() {
})
})
} // 根据组织结构获取供热站数据
function getAllTransfer() {
organizationStructure.value[0].serviceCenterList.forEach(serviceCenter => { // 共有两个服务中心
let supplyList = serviceCenter.supplyList // 供热站列表,每个服务中心对应一定的供热站
supplyList.forEach(supply => { // 供热站
transferStructData.value.push(
{
supplyId: supply.supplyId,
supplyName: supply.supplyName,
transferList: supply.transferList
}
)
})
transferStructData.value.forEach(item=>{
item.transferList.forEach((unit)=>{
unit.isUsed = false
unit.customizeId = ''
})
})
})
} // 根据组织结构获取换热站结构数据
function getOrganizationStructure() {
getOrganizationStructureInterface().then(res => {
organizationStructure.value = res.data
getSupply()
getAllTransfer()
}).catch(err => {
ElMessage.error('接口异常,获取数据失败.')
})
......@@ -296,8 +271,6 @@ function resetSearch(){
:open="bindWindowOpen"
:data="dependentSub"
:supply="supplyData"
:transfer="transferStructData"
:all-weather-mag-data="dataBackup"
@onCancel="onCancelBind"
@onConfirm="confirmBind"></BindWindow>
</div>
......
......@@ -36,6 +36,11 @@ const formRef = ref()
//校验规则
const rules = reactive({
windTemp: [
{
required: true,
message: '请输入正确的对应温度',
trigger: "blur"
},
{
pattern: /^(-?\d{1,11})(\.[0-9]{1,4})?$/,
message: "请输入正确的对应温度",
......@@ -46,11 +51,13 @@ const rules = reactive({
function add() {
addWindowOpen.value = true;
formRef.value.resetFields()
} // 新增按钮单击事件
function revise(val) {
reviseForm.value = { ...val };
reviseForm.value.windLevel = Number(reviseForm.value.windLevel);
reviseWindowOpen.value = true;
formRef.value.resetFields()
} // 修改按钮单击事件
function omit(val) {
let param = {
......@@ -99,54 +106,62 @@ function handleClose() {
resetInput();
} // 关闭弹窗
function onReviseSubmit() {
alterWind(reviseForm.value)
.then((res) => {
if (res.success) {
getData();
handleClose();
ElMessage({
message: "修改成功.",
type: "success",
});
} else {
ElMessage({
message: "修改失败.",
type: "error",
});
}
})
.catch((err) => {
ElMessage({
message: "修改失败.",
type: "error",
});
});
formRef.value.validate(valid=>{
if(valid){
alterWind(reviseForm.value)
.then((res) => {
if (res.success) {
getData();
handleClose();
ElMessage({
message: "修改成功.",
type: "success",
});
} else {
ElMessage({
message: res.message,
type: "error",
});
}
})
.catch((err) => {
ElMessage({
message: "修改失败.",
type: "error",
});
});
}
})
} // 修改表单提交
function onAddSubmit() {
addWind(addForm.value)
.then((res) => {
if (res.success) {
getData();
handleClose();
ElMessage({
message: "新增成功.",
type: "success",
});
} else {
ElMessage({
message: "新增失败.",
type: "error",
});
}
formRef.value.validate(valid=>{
if(valid){
addWind(addForm.value)
.then((res) => {
if (res.success) {
getData();
handleClose();
ElMessage({
message: "新增成功.",
type: "success",
});
} else {
ElMessage({
message: res.message,
type: "error",
});
}
})
.catch((err) => [
ElMessage({
message: "新增失败.",
type: "error",
}),
]);
}
})
})
.catch((err) => [
ElMessage({
message: "新增失败.",
type: "error",
}),
]);
} // 新增表单提交
onMounted(() => {
......
......@@ -36,9 +36,13 @@ function handleClose() {
emit('onCancel')
}
function handleConfirm() {
addData.value.operateTime = getCurrentDateTime()
emit('onConfirm', addData.value)
resetInput()
formRef.value.validate(valid=>{
if(valid){
addData.value.operateTime = getCurrentDateTime()
emit('onConfirm', addData.value)
resetInput()
}
})
}
function getCurrentDateTime() {
const now = new Date();
......@@ -53,6 +57,7 @@ function getCurrentDateTime() {
} // 生成时间
function onOpen() {
resetInput()
formRef.value.resetFields()
}
function resetInput() {
addData.value = {
......@@ -90,10 +95,11 @@ const rules = reactive({
{ pattern: /^(\d{1,11})$/, "message": "排序必须是1-11位正整数", trigger: "blur" }
],
timeoutMin: [
{ pattern: /^(\d{1,11})(\.[0-9]{1,4})?$/, "message": "判断时间必须是1-10位实数", trigger: "blur" }
{ pattern: /^(\d{1,11})(\.[0-9]{1,4})?$/, "message": "判断时间必须是1-11位实数", trigger: "blur" }
],
temperature: [
{ pattern: /^(-?\d{1,11})(\.[0-9]{1,4})?$/, message: "请输入正确的调节温度", trigger: "blur" }
{required: true, message: '请输入正确的温度'},
{ pattern: /^(-?\d{1,11})(\.[0-9]{1,4})?$/, message: "请输入正确的温度", trigger: "blur" }
]
});
</script>
......
......@@ -3,10 +3,10 @@ import {
ref,
defineProps,
defineEmits,
watchEffect
watchEffect, reactive
} from "vue";
import {getTransferInterface, getWeatherMagData} from "@/api/scheduling.js"
import {ElLoading} from 'element-plus'
import {ElLoading, ElMessage} from 'element-plus'
import cloneDeep from 'lodash/cloneDeep'
const props = defineProps({
......@@ -24,7 +24,8 @@ const props = defineProps({
type: Array,
default: [],
required: true
}})
}
})
const emit = defineEmits({
onCancel: null,
onConfirm: ({}) => {
......@@ -53,19 +54,25 @@ watchEffect(() => {
function onSubmit() {
supplyData.value.forEach(item => {
if (item.supplyId === bindData.value.supplyId) {
bindData.value.supplyName = item.supplyName
if (bindData.value.hasOwnProperty('supplyId')) {
if (bindData.value.supplyId) {
supplyData.value.forEach(item => {
if (item.supplyId === bindData.value.supplyId) {
bindData.value.supplyName = item.supplyName
}
})
selectedTransfer.value.forEach(item => {
bindData.value.transfers.push({
customizeId: bindData.value.customizeId,
unitId: item,
updateNullFields: ''
})
})
emit('onConfirm', bindData.value)
}else {
ElMessage.error('请选择供热站')
}
})
selectedTransfer.value.forEach(item=>{
bindData.value.transfers.push({
customizeId: bindData.value.customizeId,
unitId: item,
updateNullFields: ''
})
})
emit('onConfirm', bindData.value)
}
} // 点击保存按钮
/**
* 获取换热站数据
......@@ -103,9 +110,9 @@ async function getTransfer(supplyId, isAvailable = true) {
function onOpen() {
loadingInstance = ElLoading.service({target: '#bind-dialog'})
selectedTransfer.value.length = 0 // 清空已选择的换热站
transferData.value.length = 0 // 清空显示的换热站
loadingInstance = ElLoading.service({target: '.el-dialog'})
if (bindData.value.hasOwnProperty('supplyId')) {
if (bindData.value.supplyId) {
optional = bindData.value.supplyId
......@@ -121,14 +128,14 @@ function onOpen() {
* @param val supplyId
*/
function selectChange(val) {
loadingInstance = ElLoading.service({target: '.el-dialog'})
if (selectedTransfer.value.length === 0) {
getTransfer(val)
} else if(bindData.value.supplyId === optional){
getTransfer(val)
}else {
getTransfer(val, false)
}
loadingInstance = ElLoading.service({target: '#bind-dialog'})
if (selectedTransfer.value.length === 0) {
getTransfer(val)
} else if (bindData.value.supplyId === optional) {
getTransfer(val)
} else {
getTransfer(val, false)
}
loadingInstance.close()
}
......@@ -142,6 +149,7 @@ function checkboxChange(val) {
</script>
<template>
<el-dialog
id="bind-dialog"
v-model="props.open"
width="1000px"
title="换热站绑定"
......@@ -158,6 +166,7 @@ function checkboxChange(val) {
<el-row class="not-select-row">
<el-col :span="8" class="content-col-label">供热站:</el-col>
<el-col :span="16" class="content-col-value">
<el-select
v-model="bindData.supplyId"
@change="selectChange"
......@@ -168,6 +177,7 @@ function checkboxChange(val) {
<el-option v-for="item in supplyData" :key="item.supplyId" :label="item.supplyName"
:value="item.supplyId"/>
</el-select>
</el-col>
</el-row>
<el-row class="select-row">
......@@ -185,6 +195,7 @@ function checkboxChange(val) {
</el-col>
</el-row>
</div>
</template>
<template #footer>
<div class="dialog-footer">
......
<script setup>
import { ref, defineProps, defineEmits, computed, isRef, onMounted, watchEffect, reactive } from "vue";
import {ref, defineProps, defineEmits, computed, isRef, onMounted, watchEffect, reactive} from "vue";
import cloneDeep from 'lodash/cloneDeep'
import { vFloatNumber } from "@/utils/directives.js";
import {vFloatNumber} from "@/utils/directives.js";
import {getTransferInterface} from "@/api/scheduling.js";
const props = defineProps({
......@@ -30,22 +30,23 @@ const formRef = ref()
//校验规则
const rules = reactive({
diffPercentage: [
{ pattern: /^([0-9]\d{0,1}|100$)(\.\d{1,4})?$/, "message": "请输入正确的百分比格式", trigger: "blur" }
{pattern: /^([0-9]\d{0,1}|100$)(\.\d{1,4})?$/, "message": "请输入正确的百分比格式", trigger: "blur"}
],
wind: [
{ pattern: /^(\d{1,11})(\.[0-9]{1,4})?$/, "message": "风速必须是1-11位实数", trigger: "blur" }
{pattern: /^(\d{1,11})(\.[0-9]{1,4})?$/, "message": "风速必须是1-11位实数", trigger: "blur"}
],
illumination: [
{ pattern: /^(\d{1,11})(\.[0-9]{1,4})?$/, "message": "光照必须是1-11位实数", trigger: "blur" }
{pattern: /^(\d{1,11})(\.[0-9]{1,4})?$/, "message": "光照必须是1-11位实数", trigger: "blur"}
],
sort: [
{ pattern: /^(\d{1,11})$/, "message": "排序必须是1-11位正整数", trigger: "blur" }
{pattern: /^(\d{1,11})$/, "message": "排序必须是1-11位正整数", trigger: "blur"}
],
timeoutMin: [
{ pattern: /^(\d{1,11})(\.[0-9]{1,4})?$/, "message": "判断时间必须是1-10位实数", trigger: "blur" }
{pattern: /^(\d{1,11})(\.[0-9]{1,4})?$/, "message": "判断时间必须是1-10位实数", trigger: "blur"}
],
temperature: [
{ pattern: /^(-?\d{1,11})(\.[0-9]{1,4})?$/, message: "请输入正确的调节温度", trigger: "blur" }
{required: true, message: '请输入正确的温度', trigger: 'blur'},
{pattern: /^(-?\d{1,11})(\.[0-9]{1,4})?$/, message: "请输入正确的温度", trigger: "blur"}
]
});
watchEffect(() => {
......@@ -71,8 +72,29 @@ const switchingisAuto = computed({
}
}) // 可写计算属性,手动、自动模式切换
function onOpen() {
// console.log('props.data数据',props.data)
// console.log('修改弹窗接收到的数据',reviseData.value)
formRef.value.resetFields()
}
async function handleConfirm() {
if (reviseData.value.hasOwnProperty('supplyId')) {
if (reviseData.value.supplyId) {
const result = await getTransferInterface(param)
for (let item of result.data) {
reviseData.value.transfers.push(
{
customizeId: reviseData.value.customizeId,
unitId: item.transferId,
updateNullFields: ''
}
)
}
}
}
formRef.value.validate(valid => {
if (valid) {
emit('onConfirm', reviseData.value)
}
})
}
</script>
......@@ -85,7 +107,7 @@ function onOpen() {
<el-col :span="8" class="content-col-label">自定义名称:</el-col>
<el-col :span="16" class="content-col-value">
<el-input maxlength="11" :input-style="inputStyle" v-model="reviseData.customizeName"
style="width: 510px" />
style="width: 510px"/>
</el-col>
</el-row>
<el-row>
......@@ -102,7 +124,7 @@ function onOpen() {
<el-col :span="16" class="content-col-value">
<el-form-item prop="temperature" style="padding: 0;margin: 0;">
<el-input maxlength="11" :input-style="inputStyle" v-model="reviseData.temperature"
style="width: 510px" />
style="width: 510px"/>
</el-form-item>
</el-col>
</el-row>
......@@ -110,7 +132,7 @@ function onOpen() {
<el-col :span="8" class="content-col-label">风速:</el-col>
<el-col :span="16" class="content-col-value">
<el-form-item prop="wind" style="padding: 0;margin: 0;">
<el-input :input-style="inputStyle" maxlength="11" v-model="reviseData.wind" style="width: 510px" />
<el-input :input-style="inputStyle" maxlength="11" v-model="reviseData.wind" style="width: 510px"/>
</el-form-item>
</el-col>
</el-row>
......@@ -119,7 +141,7 @@ function onOpen() {
<el-col :span="16" class="content-col-value">
<el-form-item prop="illumination" style="padding: 0;margin: 0;">
<el-input :input-style="inputStyle" maxlength="11" v-model="reviseData.illumination"
style="width: 510px" />
style="width: 510px"/>
</el-form-item>
</el-col>
</el-row>
......@@ -127,20 +149,20 @@ function onOpen() {
<el-col :span="8" class="content-col-label">排序:</el-col>
<el-col :span="16" class="content-col-value">
<el-form-item prop="sort" style="padding: 0;margin: 0;">
<el-input :input-style="inputStyle" maxlength="11" v-model="reviseData.sort" style="width: 510px" />
<el-input :input-style="inputStyle" maxlength="11" v-model="reviseData.sort" style="width: 510px"/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="5" class="content-col-label">切换自动模式:</el-col>
<el-col :span="7" class="content-col-value">
<el-checkbox :style="{ marginLeft: '10px' }" v-model="switchingisAuto" label="自动模式" />
<el-checkbox :style="{ marginLeft: '10px' }" v-model="switchingisAuto" label="自动模式"/>
</el-col>
<el-col :span="5" class="content-col-label">自动偏差百分比(%d):</el-col>
<el-col :span="7" class="content-col-value">
<el-form-item prop="diffPercentage" style="padding: 0;margin: 0;">
<el-input v-float-number :input-style="inputStyle" maxlength="11" v-model="reviseData.diffPercentage"
style="width: 240px" />
style="width: 240px"/>
</el-form-item>
</el-col>
</el-row>
......@@ -149,14 +171,14 @@ function onOpen() {
<el-col :span="7" class="content-col-value">
<el-form-item prop="timeoutMin" style="padding: 0;margin: 0;">
<el-input v-float-number :input-style="inputStyle" maxlength="11" v-model="reviseData.timeoutMin"
style="width: 240px" />
style="width: 240px"/>
</el-form-item>
</el-col>
<el-col :span="5" class="content-col-label">自动调节温度(℃):</el-col>
<el-col :span="7" class="content-col-value">
<el-form-item prop="tempRegulation" style="padding: 0;margin: 0;">
<el-input :input-style="inputStyle" maxlength="11" v-model="reviseData.tempRegulation"
style="width: 240px" />
style="width: 240px"/>
</el-form-item>
</el-col>
</el-row>
......@@ -166,7 +188,7 @@ function onOpen() {
</template>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="emit('onConfirm', reviseData)">保存</el-button>
<el-button type="primary" @click="handleConfirm">保存</el-button>
<el-button type="primary" @click="emit('onCancel')">关闭</el-button>
</div>
</template>
......
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