物模型:表单添加加载状态

历史数据:原始数据限制单设备查询
This commit is contained in:
高云鹏 2025-01-22 09:00:59 +08:00
parent c0993b0398
commit 8b4cbb1ede
2 changed files with 61 additions and 33 deletions

View File

@ -32,7 +32,7 @@
</el-form-item>
</el-form>
<template #footer v-if="modelDialogState !== ModelDialogTitleStateType['detail']">
<el-button type="primary" @click="submitModelForm">保存</el-button>
<el-button type="primary" @click="submitModelForm" :loading="submitModelLoading">保存</el-button>
<el-button @click="cancelModelForm">取消</el-button>
</template>
</el-dialog>
@ -285,7 +285,7 @@
</el-form-item>
</el-form>
<template #footer>
<el-button type="primary" @click="submitAttributeForm">保存</el-button>
<el-button type="primary" @click="submitAttributeForm" :loading="submitAttributeLoading">保存</el-button>
<el-button @click="closeAttributeForm">取消</el-button>
</template>
</el-dialog>
@ -308,7 +308,7 @@
</el-form-item>
</el-form>
<template #footer>
<el-button type="primary" @click="submitServiceForm">保存</el-button>
<el-button type="primary" @click="submitServiceForm" :loading="submitServiceLoading">保存</el-button>
<el-button @click="closeServiceForm">取消</el-button>
</template>
</el-dialog>
@ -441,7 +441,11 @@ const modelFormRules = {
iotModelCode: [{ required: true, message: '请输入物模型编码', trigger: 'blur' }],
objectType: [{ required: true, message: '请选择物模型类型', trigger: 'blur' }],
}
const submitModelLoading = ref(false)
const submitModelForm = () => {
modelFormRef.value?.validate((valid) => {
if (valid) {
submitModelLoading.value = true
if (modelDialogState.value === ModelDialogTitleStateType['add']) {
addModelReq(modelForm.value)
.then((res) => {
@ -456,6 +460,9 @@ const submitModelForm = () => {
.catch((err) => {
ElMessage.error(err?.response?.data?.msg ?? '新增失败')
})
.finally(() => {
submitModelLoading.value = false
})
} else if (modelDialogState.value === ModelDialogTitleStateType['edit']) {
updateModelReq(modelForm.value)
.then((res) => {
@ -470,7 +477,12 @@ const submitModelForm = () => {
.catch((err) => {
ElMessage.error(err?.response?.data?.msg ?? '修改失败')
})
.finally(() => {
submitModelLoading.value = false
})
}
}
})
}
const getModelList = (name?: string) => {
return new Promise((resolve) => {
@ -837,9 +849,11 @@ const closeAttributeForm = () => {
attributeForm.value = JSON.parse(JSON.stringify(originAttributeForm))
attributeFormRef.value?.resetFields()
}
const submitAttributeLoading = ref(false)
const submitAttributeForm = () => {
attributeFormRef.value?.validate((valid: boolean) => {
if (valid) {
submitAttributeLoading.value = true
const copyFormData = JSON.parse(JSON.stringify(attributeForm.value))
copyFormData.highSpeed = copyFormData.highSpeed ? 1 : 0
copyFormData.visible = copyFormData.visible ? 1 : 0
@ -864,6 +878,9 @@ const submitAttributeForm = () => {
.catch((err) => {
ElMessage.error(err?.response?.data?.msg ?? '新增失败')
})
.finally(() => {
submitAttributeLoading.value = false
})
} else if (attributeFormTitle.value === AttributeDialogTitleStateType['edit']) {
updateModelAttributeReq(copyFormData)
.then((res) => {
@ -878,6 +895,9 @@ const submitAttributeForm = () => {
.catch((err) => {
ElMessage.error(err?.response?.data?.msg ?? '修改失败')
})
.finally(() => {
submitAttributeLoading.value = false
})
}
}
})
@ -905,9 +925,11 @@ const closeServiceForm = () => {
serviceForm.value = JSON.parse(JSON.stringify(originServiceForm))
serviceFormRef.value?.resetFields()
}
const submitServiceLoading = ref(false)
const submitServiceForm = () => {
serviceFormRef.value?.validate((valid: boolean) => {
if (valid) {
submitServiceLoading.value = true
if (serviceFormTitle.value === serviceDialogTitleStateType['add']) {
serviceForm.value.iotModelId = curContextMenuTreeData.value!.id!
addModelServiceReq(serviceForm.value)
@ -923,6 +945,9 @@ const submitServiceForm = () => {
.catch((err) => {
ElMessage.error(err?.response?.data?.msg ?? '新增失败')
})
.finally(() => {
submitServiceLoading.value = false
})
} else if (serviceFormTitle.value === serviceDialogTitleStateType['edit']) {
updateModelServiceReq(serviceForm.value)
.then((res) => {
@ -937,6 +962,9 @@ const submitServiceForm = () => {
.catch((err) => {
ElMessage.error(err?.response?.data?.msg ?? '修改失败')
})
.finally(() => {
submitServiceLoading.value = false
})
}
}
})

View File

@ -67,7 +67,7 @@
<div class="pointDialogColTitle">风机列表</div>
<div class="pointDialogColContent">
<el-scrollbar>
<el-checkbox-group v-model="selectWindBlower">
<el-checkbox-group v-model="selectWindBlower" :max="searchData.interval === 'NONE' ? 1 : 99">
<el-checkbox
v-for="v in windBlowerOptions"
:key="v.value"