提交: 优化 场景控制 表单的 触发器以及执行动作 的验证判断,以及一部分问题点。
This commit is contained in:
parent
1a50a55dc7
commit
c91691c16f
|
@ -91,3 +91,12 @@ export function isArray(arg) {
|
|||
}
|
||||
return Array.isArray(arg)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} str
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
export function validCode(str) {
|
||||
const reg = /^[A-Za-z0-9]+$/
|
||||
return reg.test(str)
|
||||
}
|
|
@ -55,7 +55,7 @@
|
|||
<el-col
|
||||
:span="comdlistOption.length === 1 ? 24 : 12"
|
||||
v-for="paramsItem in comdlistOption"
|
||||
:key="paramsItem.funId"
|
||||
:key="paramsItem.funId || getGuid()"
|
||||
>
|
||||
<el-form-item
|
||||
:label="paramsItem.funName + ':'"
|
||||
|
@ -70,7 +70,7 @@
|
|||
>
|
||||
<el-option
|
||||
v-for="(keys, valus) in strtoJson(paramsItem.funObj)"
|
||||
:key="valus"
|
||||
:key="getGuid()"
|
||||
:label="keys"
|
||||
:value="valus"
|
||||
></el-option>
|
||||
|
@ -200,12 +200,12 @@ export default {
|
|||
},
|
||||
deep: true,
|
||||
},
|
||||
paramsDevcie: {
|
||||
handler(val, oldVal) {
|
||||
this.form = this.paramsDevcie;
|
||||
},
|
||||
deep: true,
|
||||
}
|
||||
// paramsDevcie: {
|
||||
// handler(val, oldVal) {
|
||||
// this.form = this.paramsDevcie;
|
||||
// },
|
||||
// deep: true,
|
||||
// }
|
||||
},
|
||||
created() {
|
||||
this.form = this.paramsDevcie;
|
||||
|
@ -269,7 +269,6 @@ export default {
|
|||
cmdType: "2",
|
||||
};
|
||||
getDeviceCmdList(params).then((res) => {
|
||||
debugger
|
||||
this.cmdListOption = res.data;
|
||||
if (this.form.cmdKey) {
|
||||
this.cmdChange(this.form.cmdKey);
|
||||
|
@ -409,6 +408,15 @@ export default {
|
|||
this.$forceUpdate();
|
||||
});
|
||||
},
|
||||
getGuid() {
|
||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(
|
||||
c
|
||||
) {
|
||||
var r = (Math.random() * 16) | 0,
|
||||
v = c == "x" ? r : (r & 0x3) | 0x8;
|
||||
return v.toString(16);
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
v-for="(lable, val) in relationOptions"
|
||||
:label="lable"
|
||||
:value="val"
|
||||
:key="val"
|
||||
:key="val + getGuid()"
|
||||
></el-option>
|
||||
</el-select>
|
||||
<span style="margin: 0px 8px">类型:</span>
|
||||
|
@ -27,7 +27,7 @@
|
|||
v-for="opt in propertyList"
|
||||
:label="opt.funName"
|
||||
:value="opt.funKey"
|
||||
:key="opt.funKey"
|
||||
:key="opt.funKey + getGuid()"
|
||||
></el-option>
|
||||
</el-select>
|
||||
<span style="margin: 0px 8px"> 条件:</span>
|
||||
|
@ -42,7 +42,7 @@
|
|||
v-for="(proVal, proName) in trigCondEnumOptions"
|
||||
:label="proVal"
|
||||
:value="proName"
|
||||
:key="proVal"
|
||||
:key="proVal + getGuid()"
|
||||
>{{ proVal }}</el-option
|
||||
>
|
||||
</el-select>
|
||||
|
@ -165,6 +165,15 @@ export default {
|
|||
this.triggerMinInput = true;
|
||||
}
|
||||
},
|
||||
getGuid() {
|
||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(
|
||||
c
|
||||
) {
|
||||
var r = (Math.random() * 16) | 0,
|
||||
v = c == "x" ? r : (r & 0x3) | 0x8;
|
||||
return v.toString(16);
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
|
@ -93,7 +93,8 @@
|
|||
type="text"
|
||||
icon="el-icon-delete"
|
||||
@click="handleDelete(scope.row)"
|
||||
>删除</el-button>
|
||||
>删除</el-button
|
||||
>
|
||||
|
||||
<!-- <el-button size="mini" type="text" icon="el-icon-search"
|
||||
>详情</el-button
|
||||
|
@ -165,7 +166,7 @@
|
|||
<e-tag-card
|
||||
style="margin-top: 5px"
|
||||
v-for="(item, idx) in form.triggers"
|
||||
:key="idx"
|
||||
:key="item.guid || getGuid()"
|
||||
type="info"
|
||||
>
|
||||
<e-scene-triggers
|
||||
|
@ -211,7 +212,7 @@
|
|||
<e-tag-card
|
||||
style="margin-top: 5px"
|
||||
v-for="(item, idx) in form.actions"
|
||||
:key="idx"
|
||||
:key="item.guid || getGuid()"
|
||||
type="info"
|
||||
>
|
||||
<e-scene-action
|
||||
|
@ -248,6 +249,7 @@
|
|||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { strAndNumber } from "@/utils/validate";
|
||||
import {
|
||||
projectSceneList,
|
||||
projectSceneAdd,
|
||||
|
@ -308,6 +310,9 @@ export default {
|
|||
sceneName: [
|
||||
{ required: true, message: "场景名称不能为空", trigger: "change" },
|
||||
],
|
||||
sceneCode: [
|
||||
{ required: true, validator: this.chenking_sceneCode, trigger: "change" },
|
||||
],
|
||||
},
|
||||
};
|
||||
},
|
||||
|
@ -334,6 +339,16 @@ export default {
|
|||
this.init();
|
||||
},
|
||||
methods: {
|
||||
chenking_sceneCode(rule, value, callback) {
|
||||
const isExp = /^[A-Z a-z 0-9 _ - $]{0,36}$/;
|
||||
if (!this.form.sceneCode || this.form.sceneCode.length <= 0) {
|
||||
callback(new Error("场景编码不能为空!"));
|
||||
} else if (this.form.sceneCode && !isExp.test(this.form.sceneCode)) {
|
||||
callback(new Error("格式不正确(数字,英文字母大小写,36个字符)!"));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
},
|
||||
handleAddAction() {
|
||||
let obj = {
|
||||
orderBy: this.form.actions.length + 1 || 1,
|
||||
|
@ -347,12 +362,14 @@ export default {
|
|||
};
|
||||
this.form.actions.push(obj);
|
||||
},
|
||||
// 获取标记
|
||||
handleAddTrigger() {
|
||||
let triggersPop = [...this.form.triggers].pop();
|
||||
let obj = {
|
||||
orderBy: this.form.triggers.length + 1 || 1,
|
||||
orderBy: triggersPop ? triggersPop.orderBy + 1: 1,
|
||||
method: "",
|
||||
conditions: [],
|
||||
intervalVal: 61,
|
||||
intervalVal: '',
|
||||
intervalUnit: "SECONDS",
|
||||
sceneTriggerDevices: [],
|
||||
};
|
||||
|
@ -364,13 +381,18 @@ export default {
|
|||
this.msgError("至少有一条触发器!");
|
||||
return false;
|
||||
}
|
||||
var isTrue = true;
|
||||
this.form.triggers.forEach(e => {
|
||||
if (!e.method) {
|
||||
this.msgError("设备触发__至少选择一种类型!");
|
||||
isTrue = false;
|
||||
}
|
||||
if (e.method === 'DEVICE' && (!e.conditions || e.conditions.length <= 0 )) {
|
||||
this.msgError("设备触发__至少选择一条设备以及触发条件!");
|
||||
return false;
|
||||
isTrue = false;
|
||||
}
|
||||
})
|
||||
return true;
|
||||
return isTrue && this.validateAction();
|
||||
},
|
||||
// 验证 执行条件
|
||||
validateAction() {
|
||||
|
@ -378,25 +400,26 @@ export default {
|
|||
this.msgError("至少有一执行条件!");
|
||||
return false;
|
||||
}
|
||||
var isTrue = true;
|
||||
this.form.actions.forEach(e => {
|
||||
if (e.actionType === 'DEVOUTPUT' && (
|
||||
e.sceneActionDevices[0] && (!e.sceneActionDevices[0]['cmdKey'] || !e.sceneActionDevices[0]['deviceKey'] )
|
||||
)) {
|
||||
this.msgError("执行条件中有条件未选择设备或者分组!");
|
||||
return false;
|
||||
isTrue = false;
|
||||
}
|
||||
if (e.actionType === 'NOTIFIER' &&
|
||||
(!e.sceneActionNotifierContacts[0] || !e.sceneActionNotifierContacts[0]['contactsRelList'])) {
|
||||
this.msgError("执行条件中有条件未选择联系人!");
|
||||
return false;
|
||||
isTrue = false;
|
||||
}
|
||||
})
|
||||
return true
|
||||
return isTrue;
|
||||
},
|
||||
submitForm() {
|
||||
console.log("submit---", this.form);
|
||||
this.$refs["form"].validate((valid) => {
|
||||
if (valid && this.validateTrigger() && this.validateAction()) {
|
||||
if (valid && this.validateTrigger()) {
|
||||
if (this.form.recordId != null) {
|
||||
projectSceneUpdate(this.form).then((response) => {
|
||||
this.msgSuccess("修改成功");
|
||||
|
@ -487,6 +510,15 @@ export default {
|
|||
this.total = res.total;
|
||||
});
|
||||
},
|
||||
getGuid() {
|
||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(
|
||||
c
|
||||
) {
|
||||
var r = (Math.random() * 16) | 0,
|
||||
v = c == "x" ? r : (r & 0x3) | 0x8;
|
||||
return v.toString(16);
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue