fix(iot): 修复场景联动动作类型切换 + 数据规则弹窗 4 处 bug
- B50 动作类型切换清理失效:updateActionType 先调 onActionTypeChange (此时 action.type 仍是旧值)再赋新值;onActionTypeChange 内恒真的 type !== action.type 简化为 if (action.identifier) - B16 新增弹窗不重置主表单:onOpenChange 关闭分支补 formApi.resetForm() - B17 允许空数据源提交:source-config-form.validate() 补空数组校验 - B18 子表单校验 reject 未处理(弹窗关闭不掉):onConfirm 内 try/catch 包子表单校验,失败 return 中止提交pull/345/head
parent
f8c869f1ff
commit
152964395d
|
|
@ -47,7 +47,11 @@ const [Modal, modalApi] = useVbenModal({
|
|||
return;
|
||||
}
|
||||
// 校验数据源配置
|
||||
await sourceConfigRef.value?.validate();
|
||||
try {
|
||||
await sourceConfigRef.value?.validate();
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as DataRuleApi.DataRule;
|
||||
|
|
@ -65,6 +69,7 @@ const [Modal, modalApi] = useVbenModal({
|
|||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
await formApi.resetForm();
|
||||
sourceConfigRef.value?.setData([]);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,6 +154,10 @@ async function handleDelete(rowIndex: number) {
|
|||
|
||||
/** 校验全部行;返回 Promise,失败时 reject 第一条错误信息 */
|
||||
function validate() {
|
||||
if (formData.value.length === 0) {
|
||||
message.error('请至少添加一条数据源配置');
|
||||
return Promise.reject(new Error('数据源配置不能为空'));
|
||||
}
|
||||
for (let i = 0; i < formData.value.length; i++) {
|
||||
const row = formData.value[i];
|
||||
if (!row.productId) {
|
||||
|
|
|
|||
|
|
@ -99,8 +99,9 @@ function removeAction(index: number) {
|
|||
* @param type 执行器类型
|
||||
*/
|
||||
function updateActionType(index: number, type: number) {
|
||||
actions.value[index]!.type = type;
|
||||
onActionTypeChange(actions.value[index] as RuleSceneApi.Action, type);
|
||||
const action = actions.value[index] as RuleSceneApi.Action;
|
||||
onActionTypeChange(action, type); // 须在赋新值前调用 ,内部依赖 action.type 旧值
|
||||
action.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -134,7 +135,7 @@ function onActionTypeChange(action: RuleSceneApi.Action, type: number) {
|
|||
action.params = '';
|
||||
}
|
||||
// 切换到设备控制类型时清空 identifier,让用户重新选择
|
||||
if (action.identifier && type !== action.type) {
|
||||
if (action.identifier) {
|
||||
action.identifier = undefined;
|
||||
}
|
||||
} else if (isAlertAction(type)) {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,11 @@ const [Modal, modalApi] = useVbenModal({
|
|||
return;
|
||||
}
|
||||
// 校验数据源配置
|
||||
await sourceConfigRef.value?.validate();
|
||||
try {
|
||||
await sourceConfigRef.value?.validate();
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data = (await formApi.getValues()) as DataRuleApi.DataRule;
|
||||
|
|
@ -65,6 +69,7 @@ const [Modal, modalApi] = useVbenModal({
|
|||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
await formApi.resetForm();
|
||||
sourceConfigRef.value?.setData([]);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,6 +154,10 @@ async function handleDelete(rowIndex: number) {
|
|||
|
||||
/** 校验全部行;返回 Promise,失败时 reject 第一条错误信息 */
|
||||
function validate() {
|
||||
if (formData.value.length === 0) {
|
||||
ElMessage.error('请至少添加一条数据源配置');
|
||||
return Promise.reject(new Error('数据源配置不能为空'));
|
||||
}
|
||||
for (let i = 0; i < formData.value.length; i++) {
|
||||
const row = formData.value[i];
|
||||
if (!row.productId) {
|
||||
|
|
|
|||
|
|
@ -107,8 +107,9 @@ function removeAction(index: number) {
|
|||
* @param type 执行器类型
|
||||
*/
|
||||
function updateActionType(index: number, type: number) {
|
||||
actions.value[index]!.type = type;
|
||||
onActionTypeChange(actions.value[index] as RuleSceneApi.Action, type);
|
||||
const action = actions.value[index] as RuleSceneApi.Action;
|
||||
onActionTypeChange(action, type); // 须在赋新值前调用 ,内部依赖 action.type 旧值
|
||||
action.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -142,7 +143,7 @@ function onActionTypeChange(action: RuleSceneApi.Action, type: number) {
|
|||
action.params = '';
|
||||
}
|
||||
// 切换到设备控制类型时清空 identifier,让用户重新选择
|
||||
if (action.identifier && type !== action.type) {
|
||||
if (action.identifier) {
|
||||
action.identifier = undefined;
|
||||
}
|
||||
} else if (isAlertAction(type)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue