提交: 优化 场景控制 表单的 触发器以及执行动作 的验证判断,以及一部分问题点。

This commit is contained in:
23688nl 2022-09-22 11:11:26 +08:00
parent 1a50a55dc7
commit c91691c16f
4 changed files with 81 additions and 23 deletions

View File

@ -91,3 +91,12 @@ export function isArray(arg) {
} }
return Array.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)
}

View File

@ -55,7 +55,7 @@
<el-col <el-col
:span="comdlistOption.length === 1 ? 24 : 12" :span="comdlistOption.length === 1 ? 24 : 12"
v-for="paramsItem in comdlistOption" v-for="paramsItem in comdlistOption"
:key="paramsItem.funId" :key="paramsItem.funId || getGuid()"
> >
<el-form-item <el-form-item
:label="paramsItem.funName + ''" :label="paramsItem.funName + ''"
@ -70,7 +70,7 @@
> >
<el-option <el-option
v-for="(keys, valus) in strtoJson(paramsItem.funObj)" v-for="(keys, valus) in strtoJson(paramsItem.funObj)"
:key="valus" :key="getGuid()"
:label="keys" :label="keys"
:value="valus" :value="valus"
></el-option> ></el-option>
@ -200,12 +200,12 @@ export default {
}, },
deep: true, deep: true,
}, },
paramsDevcie: { // paramsDevcie: {
handler(val, oldVal) { // handler(val, oldVal) {
this.form = this.paramsDevcie; // this.form = this.paramsDevcie;
}, // },
deep: true, // deep: true,
} // }
}, },
created() { created() {
this.form = this.paramsDevcie; this.form = this.paramsDevcie;
@ -269,7 +269,6 @@ export default {
cmdType: "2", cmdType: "2",
}; };
getDeviceCmdList(params).then((res) => { getDeviceCmdList(params).then((res) => {
debugger
this.cmdListOption = res.data; this.cmdListOption = res.data;
if (this.form.cmdKey) { if (this.form.cmdKey) {
this.cmdChange(this.form.cmdKey); this.cmdChange(this.form.cmdKey);
@ -409,6 +408,15 @@ export default {
this.$forceUpdate(); 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> </script>

View File

@ -12,7 +12,7 @@
v-for="(lable, val) in relationOptions" v-for="(lable, val) in relationOptions"
:label="lable" :label="lable"
:value="val" :value="val"
:key="val" :key="val + getGuid()"
></el-option> ></el-option>
</el-select> </el-select>
<span style="margin: 0px 8px">类型:</span> <span style="margin: 0px 8px">类型:</span>
@ -27,7 +27,7 @@
v-for="opt in propertyList" v-for="opt in propertyList"
:label="opt.funName" :label="opt.funName"
:value="opt.funKey" :value="opt.funKey"
:key="opt.funKey" :key="opt.funKey + getGuid()"
></el-option> ></el-option>
</el-select> </el-select>
<span style="margin: 0px 8px"> 条件:</span> <span style="margin: 0px 8px"> 条件:</span>
@ -42,7 +42,7 @@
v-for="(proVal, proName) in trigCondEnumOptions" v-for="(proVal, proName) in trigCondEnumOptions"
:label="proVal" :label="proVal"
:value="proName" :value="proName"
:key="proVal" :key="proVal + getGuid()"
>{{ proVal }}</el-option >{{ proVal }}</el-option
> >
</el-select> </el-select>
@ -165,6 +165,15 @@ export default {
this.triggerMinInput = true; 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> </script>

View File

@ -93,7 +93,8 @@
type="text" type="text"
icon="el-icon-delete" icon="el-icon-delete"
@click="handleDelete(scope.row)" @click="handleDelete(scope.row)"
>删除</el-button> >删除</el-button
>
<!-- <el-button size="mini" type="text" icon="el-icon-search" <!-- <el-button size="mini" type="text" icon="el-icon-search"
>详情</el-button >详情</el-button
@ -165,7 +166,7 @@
<e-tag-card <e-tag-card
style="margin-top: 5px" style="margin-top: 5px"
v-for="(item, idx) in form.triggers" v-for="(item, idx) in form.triggers"
:key="idx" :key="item.guid || getGuid()"
type="info" type="info"
> >
<e-scene-triggers <e-scene-triggers
@ -211,7 +212,7 @@
<e-tag-card <e-tag-card
style="margin-top: 5px" style="margin-top: 5px"
v-for="(item, idx) in form.actions" v-for="(item, idx) in form.actions"
:key="idx" :key="item.guid || getGuid()"
type="info" type="info"
> >
<e-scene-action <e-scene-action
@ -248,6 +249,7 @@
</div> </div>
</template> </template>
<script> <script>
import { strAndNumber } from "@/utils/validate";
import { import {
projectSceneList, projectSceneList,
projectSceneAdd, projectSceneAdd,
@ -308,6 +310,9 @@ export default {
sceneName: [ sceneName: [
{ required: true, message: "场景名称不能为空", trigger: "change" }, { required: true, message: "场景名称不能为空", trigger: "change" },
], ],
sceneCode: [
{ required: true, validator: this.chenking_sceneCode, trigger: "change" },
],
}, },
}; };
}, },
@ -334,6 +339,16 @@ export default {
this.init(); this.init();
}, },
methods: { 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() { handleAddAction() {
let obj = { let obj = {
orderBy: this.form.actions.length + 1 || 1, orderBy: this.form.actions.length + 1 || 1,
@ -347,12 +362,14 @@ export default {
}; };
this.form.actions.push(obj); this.form.actions.push(obj);
}, },
//
handleAddTrigger() { handleAddTrigger() {
let triggersPop = [...this.form.triggers].pop();
let obj = { let obj = {
orderBy: this.form.triggers.length + 1 || 1, orderBy: triggersPop ? triggersPop.orderBy + 1: 1,
method: "", method: "",
conditions: [], conditions: [],
intervalVal: 61, intervalVal: '',
intervalUnit: "SECONDS", intervalUnit: "SECONDS",
sceneTriggerDevices: [], sceneTriggerDevices: [],
}; };
@ -364,13 +381,18 @@ export default {
this.msgError("至少有一条触发器!"); this.msgError("至少有一条触发器!");
return false; return false;
} }
var isTrue = true;
this.form.triggers.forEach(e => { this.form.triggers.forEach(e => {
if (!e.method) {
this.msgError("设备触发__至少选择一种类型");
isTrue = false;
}
if (e.method === 'DEVICE' && (!e.conditions || e.conditions.length <= 0 )) { if (e.method === 'DEVICE' && (!e.conditions || e.conditions.length <= 0 )) {
this.msgError("设备触发__至少选择一条设备以及触发条件"); this.msgError("设备触发__至少选择一条设备以及触发条件");
return false; isTrue = false;
} }
}) })
return true; return isTrue && this.validateAction();
}, },
// //
validateAction() { validateAction() {
@ -378,25 +400,26 @@ export default {
this.msgError("至少有一执行条件!"); this.msgError("至少有一执行条件!");
return false; return false;
} }
var isTrue = true;
this.form.actions.forEach(e => { this.form.actions.forEach(e => {
if (e.actionType === 'DEVOUTPUT' && ( if (e.actionType === 'DEVOUTPUT' && (
e.sceneActionDevices[0] && (!e.sceneActionDevices[0]['cmdKey'] || !e.sceneActionDevices[0]['deviceKey'] ) e.sceneActionDevices[0] && (!e.sceneActionDevices[0]['cmdKey'] || !e.sceneActionDevices[0]['deviceKey'] )
)) { )) {
this.msgError("执行条件中有条件未选择设备或者分组!"); this.msgError("执行条件中有条件未选择设备或者分组!");
return false; isTrue = false;
} }
if (e.actionType === 'NOTIFIER' && if (e.actionType === 'NOTIFIER' &&
(!e.sceneActionNotifierContacts[0] || !e.sceneActionNotifierContacts[0]['contactsRelList'])) { (!e.sceneActionNotifierContacts[0] || !e.sceneActionNotifierContacts[0]['contactsRelList'])) {
this.msgError("执行条件中有条件未选择联系人!"); this.msgError("执行条件中有条件未选择联系人!");
return false; isTrue = false;
} }
}) })
return true return isTrue;
}, },
submitForm() { submitForm() {
console.log("submit---", this.form); console.log("submit---", this.form);
this.$refs["form"].validate((valid) => { this.$refs["form"].validate((valid) => {
if (valid && this.validateTrigger() && this.validateAction()) { if (valid && this.validateTrigger()) {
if (this.form.recordId != null) { if (this.form.recordId != null) {
projectSceneUpdate(this.form).then((response) => { projectSceneUpdate(this.form).then((response) => {
this.msgSuccess("修改成功"); this.msgSuccess("修改成功");
@ -487,6 +510,15 @@ export default {
this.total = res.total; 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> </script>