fix: 优化场景联动-执行动作删除校验

This commit is contained in:
xieyonghong 2023-05-08 18:01:19 +08:00
parent 07c249fdf4
commit d9ac1d456c
3 changed files with 12 additions and 33 deletions

View File

@ -36,11 +36,11 @@ const sub = ref()
const rules = [{ const rules = [{
validator(_: any, v?: ActionsType) { validator(_: any, v?: ActionsType) {
console.log('validator',v)
if (v?.executor === 'device') { if (v?.executor === 'device') {
if( if(
!v.device?.productId || // !v.device?.productId || //
!v.device?.selectorValues // !v.device?.selectorValues || //
(v.device.source === 'upper' && !v.device?.upperKey)
) { ) {
return Promise.reject(new Error('该数据已发生变更,请重新配置')) return Promise.reject(new Error('该数据已发生变更,请重新配置'))
} }
@ -73,14 +73,16 @@ const checkDeviceDelete = async () => {
return return
} }
} }
console.log(item!.source, props.name)
if (item!.source === 'upper') { // id if (item!.source === 'upper') { // id
if (props.name === 0) { if (props.name === 0) {
_data.value.branches![props.branchesName].then[props.thenName].actions[props.name].device!.upperKey = undefined
formTouchOff() formTouchOff()
return return
} else { } else {
const prevItem = _data.value.branches![props.branchesName].then[props.thenName].actions[props.name - 1].device const prevItem = _data.value.branches![props.branchesName].then[props.thenName].actions[props.name - 1].device
if (prevItem?.productId !== item?.productId) { if (prevItem?.productId !== item?.productId) {
_data.value.branches![props.branchesName].then[props.thenName].actions[props.name].device!.upperKey = undefined
formTouchOff() formTouchOff()
return return
} }
@ -116,41 +118,18 @@ const check = () => {
} }
} }
const checkPrevData = (data: any) => { const subscribe = () => {
console.log(data) // action
const _executor = _data.value.branches![props.branchesName].then[props.thenName].actions[props.name]?.executor
if (_executor === 'device' && _data.value.branches![props.branchesName].then[props.thenName].actions[props.name]?.device) { //
//
// id
} else if (_executor === 'notify' && _data.value.branches![props.branchesName].then[props.thenName].actions[props.name]?.notify) {
//
}
}
const subscribe = (newName: number, oldName: number) => {
const _key = EventSubscribeKeys({ const _key = EventSubscribeKeys({
branch: props.branchesName, branch: props.branchesName,
branchGroup: props.thenName, branchGroup: props.thenName,
action: props.name - 1 action: props.name
}) })
if (sub.value) { sub.value = EventEmitter.subscribe(_key, check)
const oldKey = EventSubscribeKeys({
branch: props.branchesName,
branchGroup: props.thenName,
action: oldName - 1
})
sub.value.unSubscribe(oldKey, checkPrevData)
}
sub.value = EventEmitter.subscribe(_key, checkPrevData)
} }
watch(() => props.name, (newName, oldName) => { subscribe()
// subscribe(newName, oldName || 0)
}, { immediate: true })
check() check()

View File

@ -76,7 +76,7 @@ export const EventSubscribeKeys = (params: Params): string[] => {
keys.push(DeviceEmitterKey) keys.push(DeviceEmitterKey)
} }
for (let i = 0; i <= params.action; i++) { for (let i = 0; i <= params.action - 1; i++) {
let key = sceneStore.data.branches?.[params.branch].then[params.branchGroup].actions[i]?.key let key = sceneStore.data.branches?.[params.branch].then[params.branchGroup].actions[i]?.key
if (!key) { if (!key) {
const _b = `branches_${params.branch}` // branchesName const _b = `branches_${params.branch}` // branchesName

View File

@ -92,7 +92,7 @@ export default defineConfig(({ mode}) => {
proxy: { proxy: {
[env.VITE_APP_BASE_API]: { [env.VITE_APP_BASE_API]: {
// target: 'http://192.168.32.70:8844', // target: 'http://192.168.32.226:8844',
// target: 'http://192.168.32.244:8881', // target: 'http://192.168.32.244:8881',
target: 'http://120.77.179.54:8844', // 120测试 target: 'http://120.77.179.54:8844', // 120测试
// target: 'http://192.168.33.46:8844', // 本地开发环境 // target: 'http://192.168.33.46:8844', // 本地开发环境