fix: 场景联动-执行动作-设备输出

This commit is contained in:
100011797 2023-03-09 18:25:10 +08:00
parent 9cd78db1f6
commit 0330a7702f
13 changed files with 527 additions and 165 deletions

View File

@ -1,18 +1,35 @@
<template> <template>
<div> <div>
<Action :thenOptions="data.branches ? data?.branches[0].then : []" :name="0" /> <Action
:thenOptions="data.branches ? data?.branches[0].then : []"
:name="0"
@add="onActionAdd"
@update="onActionUpdate"
/>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { useSceneStore } from '@/store/scene' import { useSceneStore } from '@/store/scene';
import Action from '../action/index.vue' import Action from '../action/index.vue';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import { ActionsType } from '@/components/Table';
const sceneStore = useSceneStore() const sceneStore = useSceneStore();
const { data } = storeToRefs(sceneStore) const { data } = storeToRefs(sceneStore);
const onActionAdd = (_data: ActionsType) => {
console.log(_data)
// if (data?.branches && _data) {
// const newThen = [...data?.branches?.[0].then, data];
// data.branches[0].then = newThen;
// }
};
const onActionUpdate = (_data: ActionsType, type: boolean) => {
console.log(_data, type)
};
</script> </script>
<style scoped> <style scoped>
</style> </style>

View File

@ -8,12 +8,20 @@
> >
<template #bodyCell="{ column, text, record }"> <template #bodyCell="{ column, text, record }">
<div> <div>
<template v-if="['valueType', 'name'].includes(column.dataIndex)"> <template
v-if="['valueType', 'name'].includes(column.dataIndex)"
>
<span>{{ text }}</span> <span>{{ text }}</span>
</template> </template>
<template v-else> <template v-else>
<j-input /> <ParamsDropdown
<!-- TODO --> icon="icon-canshu"
placeholder="请选择"
:options="[]"
:tabsOptions="tabOptions"
:metricOption="upperOptions(record.valueType)"
v-model:value="record.value"
/>
</template> </template>
</div> </div>
</template> </template>
@ -21,7 +29,8 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { PropType } from "vue"; import { PropType } from 'vue';
import ParamsDropdown from '../../../components/ParamsDropdown';
type Emits = { type Emits = {
(e: 'update:modelValue', data: Record<string, any>[]): void; (e: 'update:modelValue', data: Record<string, any>[]): void;
@ -31,9 +40,27 @@ const _emit = defineEmits<Emits>();
const _props = defineProps({ const _props = defineProps({
modelValue: { modelValue: {
type: Array as PropType<Record<string, any>[]>, type: Array as PropType<Record<string, any>[]>,
default: '', default: () => undefined,
} },
builtInList: {
type: Array,
default: () => [],
},
}); });
const tabOptions = [
{
label: '手动输入',
component: 'string',
key: 'fixed',
},
{
label: '内置参数',
component: 'tree',
key: 'upper',
},
];
const columns = [ const columns = [
{ {
title: '参数名称', title: '参数名称',
@ -54,11 +81,31 @@ const columns = [
const dataSource = computed({ const dataSource = computed({
get: () => { get: () => {
return _props.modelValue || [] return _props.modelValue || [];
}, },
set: (val: any) => { set: (val: any) => {
_emit('update:modelValue', val); _emit('update:modelValue', val);
} },
}) });
const filterParamsData = (type?: string, data?: any[]): any[] => {
if (type && data) {
return data.filter((item) => {
if (item.children) {
const _children = filterParamsData(type, item.children);
item.children = _children;
return _children.length ? true : false;
} else if (item.type === type) {
// optionMap.current.set(item.id, item);
return true;
}
return false;
});
}
return data || [];
};
const upperOptions = (_type: string) => {
return filterParamsData(_type, _props?.builtInList) || [];
};
</script> </script>

View File

@ -0,0 +1,140 @@
<template>
<div>
<a-form :layout="'vertical'" ref="formRef" :model="modelRef">
<j-row>
<j-col :span="11">
<j-form-item
:name="['message', 'properties']"
label="读取属性"
:rules="[{ required: true, message: '请选择读取属性' }]"
>
<j-select
showSearch
placeholder="请选择属性"
v-model:value="modelRef.properties"
>
<j-select-option
v-for="item in metadata?.properties || []"
:value="item?.id"
:key="item?.id"
>{{ item?.name }}</j-select-option
>
</j-select>
</j-form-item>
</j-col>
<j-col :span="2"></j-col>
<j-col :span="11">
<j-form-item
:name="['message', 'propertiesValue']"
label="属性值"
:rules="[{ required: true, message: '请选择' }]"
>
<ParamsDropdown
icon="icon-canshu"
placeholder="请选择"
:options="[]"
:tabsOptions="tabOptions"
:metricOption="upperOptions(getType)"
v-model:value="modelRef.propertiesValue"
/>
</j-form-item>
</j-col>
</j-row>
</a-form>
</div>
</template>
<script lang="ts" setup>
const props = defineProps({
value: {
type: Object,
default: () => {},
},
metadata: {
type: Object,
default: () => {
return {
properties: [],
};
},
},
builtInList: {
type: Array,
default: () => []
},
});
const formRef = ref();
const modelRef = reactive({
properties: '',
propertiesValue: '',
source: '',
});
const tabOptions = [
{
label: '手动输入',
component: 'string',
key: 'fixed',
},
{
label: '内置参数',
component: 'tree',
key: 'upper',
},
];
const getType = computed(() => {
return props.metadata.properties.find((item: any) => item.id === modelRef.properties)?.valueType?.type
})
const filterParamsData = (type?: string, data?: any[]): any[] => {
if (type && data) {
return data.filter((item) => {
if (item.children) {
const _children = filterParamsData(type, item.children);
item.children = _children;
return _children.length ? true : false;
} else if (item.type === type) {
// optionMap.current.set(item.id, item);
return true;
}
return false;
});
}
return data || [];
};
const upperOptions = (type: string) => {
return filterParamsData(type, props?.builtInList) || []
}
watch(
() => props.value,
(newVal) => {
const _keys = Object.keys(newVal)?.[0];
if (_keys) {
(modelRef.properties = _keys),
(modelRef.propertiesValue = newVal[_keys]?.value);
modelRef.source = newVal[_keys]?.source;
}
},
{ deep: true, immediate: true },
);
const onFormSave = () => {
return new Promise((resolve, reject) => {
formRef.value
.validate()
.then(async (_data: any) => {
//
resolve(_data);
})
.catch((err: any) => {
reject(err);
});
});
};
defineExpose({ onFormSave });
</script>

View File

@ -9,6 +9,7 @@
<TopCard <TopCard
:typeList="TypeList" :typeList="TypeList"
v-model:value="modelRef.message.messageType" v-model:value="modelRef.message.messageType"
@change="onMessageTypeChange"
/> />
</j-form-item> </j-form-item>
<template v-if="deviceMessageType === 'INVOKE_FUNCTION'"> <template v-if="deviceMessageType === 'INVOKE_FUNCTION'">
@ -21,7 +22,7 @@
showSearch showSearch
placeholder="请选择功能" placeholder="请选择功能"
v-model:value="modelRef.message.functionId" v-model:value="modelRef.message.functionId"
@change="onFunctionChange" @change="(val) => onFunctionChange(val, [])"
> >
<j-select-option <j-select-option
v-for="item in metadata?.functions || []" v-for="item in metadata?.functions || []"
@ -36,7 +37,7 @@
:name="['message', 'inputs']" :name="['message', 'inputs']"
:rules="[{ required: true, message: '请输入功能值' }]" :rules="[{ required: true, message: '请输入功能值' }]"
> >
<EditTable v-model="modelRef.message.inputs" /> <EditTable v-model:modelValue="modelRef.message.inputs" :builtInList="builtInList" />
</j-form-item> </j-form-item>
</template> </template>
<template v-else-if="deviceMessageType === 'READ_PROPERTY'"> <template v-else-if="deviceMessageType === 'READ_PROPERTY'">
@ -60,44 +61,11 @@
</j-form-item> </j-form-item>
</template> </template>
<template v-else-if="deviceMessageType === 'WRITE_PROPERTY'"> <template v-else-if="deviceMessageType === 'WRITE_PROPERTY'">
<j-row> <WriteProperty
<j-col :span="11"> v-model:value="modelRef.message.properties"
<j-form-item :metadata="metadata"
:name="['message', 'properties']" :builtInList="builtInList"
label="读取属性" />
:rules="[
{ required: true, message: '请选择读取属性' },
]"
>
<j-select
showSearch
placeholder="请选择属性"
v-model:value="modelRef.message.properties"
>
<j-select-option
v-for="item in metadata?.properties || []"
:value="item?.id"
:key="item?.id"
>{{ item?.name }}</j-select-option
>
</j-select>
</j-form-item>
</j-col>
<j-col :span="2"></j-col>
<j-col :span="11">
<j-form-item
:name="['message', 'properties']"
label="读取属性"
:rules="[
{ required: true, message: '请选择读取属性' },
]"
>
<j-select placeholder="请选择">
<!-- TODO -->
</j-select>
</j-form-item>
</j-col>
</j-row>
</template> </template>
</a-form> </a-form>
</div> </div>
@ -108,6 +76,13 @@ import { getImage } from '@/utils/comm';
import TopCard from '../device/TopCard.vue'; import TopCard from '../device/TopCard.vue';
import { detail } from '@/api/device/instance'; import { detail } from '@/api/device/instance';
import EditTable from './EditTable.vue'; import EditTable from './EditTable.vue';
import WriteProperty from './WriteProperty.vue';
import { queryBuiltInParams } from '@/api/rule-engine/scene';
import { useSceneStore } from '@/store/scene';
import { storeToRefs } from 'pinia'
const sceneStore = useSceneStore();
const { data } = storeToRefs(sceneStore);
const TypeList = [ const TypeList = [
{ {
@ -172,44 +147,93 @@ const deviceMessageType = computed(() => {
return modelRef.message.messageType; return modelRef.message.messageType;
}); });
const onFunctionChange = (val: string) => { const builtInList = ref<any[]>([]);
const onFunctionChange = (val: string, values?: any[]) => {
const _item = (metadata.value?.functions || []).find((item: any) => { const _item = (metadata.value?.functions || []).find((item: any) => {
return val === item.id; return val === item.id;
}); });
const list = (_item?.inputs || []).map((item: any) => { const list = (_item?.inputs || []).map((item: any) => {
const _a = values?.find((i) => i.name === item.id);
return { return {
id: item.id, id: item.id,
name: item.name, value: _a?.value,
value: undefined,
valueType: item?.valueType?.type, valueType: item?.valueType?.type,
..._a,
name: item.name,
}; };
}); });
modelRef.message.inputs = list; modelRef.message.inputs = list;
}; };
watchEffect(() => { const onMessageTypeChange = (val: string) => {
// console.log(props.values) if (['WRITE_PROPERTY', 'INVOKE_FUNCTION'].includes(val)) {
// console.log(metadata.value) const _params = {
// Object.assign() branch: props.thenName,
}); branchGroup: props.branchGroup,
action: props.name - 1,
};
queryBuiltInParams(unref(data), _params).then((res: any) => {
if (res.status === 200) {
builtInList.value = res.result
}
});
}
};
watch( watch(
() => [props.values?.productDetail, props.values.deviceDetail], () => [
([newVal1, newVal2]) => { props.values?.productDetail,
if (newVal1) { props.values.selectorValues,
if (props.values?.selector === 'fixed') { props.values?.selector,
detail(newVal2.id).then((resp) => { ],
if (resp.status === 200) { ([newVal1, newVal2, newVal3]) => {
metadata.value = JSON.parse( if (newVal1?.id) {
resp.result?.metadata || '{}', if (newVal3?.selector === 'fixed') {
); const id = newVal2?.[0]?.value;
} if (id) {
}); detail(id).then((resp) => {
if (resp.status === 200) {
metadata.value = JSON.parse(
resp.result?.metadata || '{}',
);
}
});
}
} else { } else {
metadata.value = JSON.parse(newVal1?.metadata || '{}'); metadata.value = JSON.parse(newVal1?.metadata || '{}');
} }
} }
}, },
{ immediate: true, deep: true },
);
watch(
() => props.values?.message,
(newVal) => {
if (newVal?.messageType) {
modelRef.message = newVal;
if (newVal.messageType === 'INVOKE_FUNCTION' && newVal.functionId) {
onFunctionChange(newVal.functionId, newVal?.inputs);
}
onMessageTypeChange(newVal.messageType)
}
},
{ deep: true, immediate: true }, { deep: true, immediate: true },
); );
const onFormSave = () => {
return new Promise((resolve, reject) => {
formRef.value
.validate()
.then(async (_data: any) => {
resolve(_data);
})
.catch((err: any) => {
reject(err);
});
});
};
defineExpose({ onFormSave });
</script> </script>

View File

@ -1,11 +1,11 @@
<template> <template>
<!-- <j-advanced-search <j-advanced-search
:columns="columns" :columns="columns"
type="simple" type="simple"
@search="handleSearch" @search="handleSearch"
class="search" class="search"
target="scene-trigger-device-device" target="scene-trigger-device-device"
/> --> />
<a-divider style="margin: 0" /> <a-divider style="margin: 0" />
<j-pro-table <j-pro-table
ref="actionRef" ref="actionRef"

View File

@ -61,6 +61,7 @@
v-model:value="modelRef.selectorValues" v-model:value="modelRef.selectorValues"
placeholder="请选择参数" placeholder="请选择参数"
@select="onVariableChange" @select="onVariableChange"
:fieldNames="{ label: 'name', value: 'id' }"
> >
<template #title="{ name, description }"> <template #title="{ name, description }">
<a-space> <a-space>
@ -108,6 +109,7 @@ const props = defineProps({
}, },
}); });
// savedeviceDetail
const emits = defineEmits(['save', 'cancel']); const emits = defineEmits(['save', 'cancel']);
const sceneStore = useSceneStore(); const sceneStore = useSceneStore();
@ -122,6 +124,7 @@ const modelRef = reactive({
source: '', source: '',
relationName: '', relationName: '',
upperKey: '', upperKey: '',
message: undefined,
}); });
const list = ref<any[]>([]); const list = ref<any[]>([]);
@ -160,7 +163,7 @@ const filterTree = (nodes: any[]) => {
if (!nodes?.length) { if (!nodes?.length) {
return nodes; return nodes;
} }
return nodes.filter((it) => { const arr = nodes.filter((it) => {
if ( if (
it.children.find( it.children.find(
(item: any) => (item: any) =>
@ -173,43 +176,16 @@ const filterTree = (nodes: any[]) => {
} }
return false; return false;
}); });
}; return arr.map((item) => {
if (item.children) {
const treeDataFilter = (arr: any[]) => { }
if (Array.isArray(arr) && arr.length) { return {
const list: any[] = []; ...item,
arr.map((item: any) => { title: item.name,
if (item.children) { value: item.id,
const children = treeDataFilter(item.children); disabled: !!item.children,
if (children.length) { };
list.push({ });
...item,
title: item.name,
value: item.id,
disabled: true,
children,
});
}
} else {
if (
item.children.find(
(item: any) =>
item.id.indexOf(
'deviceId' || 'device_id' || 'device_Id',
) > -1,
) &&
!item.children.find(
(item: any) => item.id.indexOf('bolaen') > -1,
)
) {
list.push(item);
}
}
});
return list;
} else {
return [];
}
}; };
const sourceChangeEvent = async () => { const sourceChangeEvent = async () => {
@ -220,11 +196,9 @@ const sourceChangeEvent = async () => {
}; };
const resp = await queryBuiltInParams(unref(data), _params); const resp = await queryBuiltInParams(unref(data), _params);
if (resp.status === 200) { if (resp.status === 200) {
// const array = filterTree(resp.result as any[]); const array = filterTree(resp.result as any[]);
// //
// if (props.formProductId === DeviceModel.productId)// TODO // if (props.formProductId === DeviceModel.productId)// TODO
console.log(array);
const arr = treeDataFilter(resp.result as any[]);
builtInList.value = array; builtInList.value = array;
} }
}; };
@ -293,6 +267,7 @@ const filterType = async () => {
}; };
const onSelectorChange = (val: string) => { const onSelectorChange = (val: string) => {
modelRef.selectorValues = undefined;
if (val === 'relation') { if (val === 'relation') {
queryRelationList(); queryRelationList();
} }
@ -300,7 +275,17 @@ const onSelectorChange = (val: string) => {
const onDeviceChange = (_detail: any) => { const onDeviceChange = (_detail: any) => {
if (_detail) { if (_detail) {
emits('save', modelRef, _detail); if (_detail.id) {
modelRef.deviceId = _detail.id;
modelRef.selectorValues = [
{ value: _detail.id, name: _detail.name },
] as any;
modelRef.message = {} as any;
} else {
modelRef.deviceId = '';
modelRef.selectorValues = [] as any;
}
emits('save', unref(modelRef), _detail);
} }
}; };
@ -310,7 +295,7 @@ const onRelationChange = (val: any, options: any) => {
modelRef.selectorValues = val; modelRef.selectorValues = val;
modelRef.upperKey = 'scene.deviceId'; modelRef.upperKey = 'scene.deviceId';
modelRef.relationName = options.label; modelRef.relationName = options.label;
emits('save', modelRef, {}); emits('save', unref(modelRef), {});
}; };
const onTagChange = (val: any[], arr: any[]) => { const onTagChange = (val: any[], arr: any[]) => {
@ -321,11 +306,12 @@ const onTagChange = (val: any[], arr: any[]) => {
if (arr) { if (arr) {
tagList.value = arr; tagList.value = arr;
} }
emits('save', unref(modelRef), {});
}; };
const onVariableChange = (val: any, node: any) => { const onVariableChange = (val: any, node: any) => {
modelRef.deviceId = val; modelRef.deviceId = val;
// modelRef.deviceDetail = node; emits('save', unref(modelRef), node);
modelRef.selectorValues = [{ value: val, name: node.description }] as any; modelRef.selectorValues = [{ value: val, name: node.description }] as any;
}; };
@ -348,6 +334,21 @@ watch(
deep: true, deep: true,
}, },
); );
const onFormSave = () => {
return new Promise((resolve, reject) => {
formRef.value
.validate()
.then(async (_data: any) => {
resolve(_data);
})
.catch((err: any) => {
reject(err);
});
});
};
defineExpose({ onFormSave });
</script> </script>
<style scoped lang='less'> <style scoped lang='less'>

View File

@ -33,13 +33,16 @@
:thenName="thenName" :thenName="thenName"
:values="DeviceModel" :values="DeviceModel"
@save="onDeviceSave" @save="onDeviceSave"
ref="deviceRef"
/> />
<Action v-else-if="current === 2" <Action
v-else-if="current === 2"
:name="name" :name="name"
:branchGroup="branchGroup" :branchGroup="branchGroup"
:thenName="thenName" :thenName="thenName"
:values="DeviceModel" :values="DeviceModel"
/> ref="actionRef"
/>
</div> </div>
<template #footer> <template #footer>
<div class="steps-action"> <div class="steps-action">
@ -62,7 +65,13 @@ import Product from './Product.vue';
import Device from './device/index.vue'; import Device from './device/index.vue';
import Action from './actions/index.vue'; import Action from './actions/index.vue';
import { onlyMessage } from '@/utils/comm'; import { onlyMessage } from '@/utils/comm';
import { detail } from '@/api/device/product' import { detail } from '@/api/device/product';
import { useSceneStore } from '@/store/scene';
import { storeToRefs } from 'pinia';
const sceneStore = useSceneStore();
const { data } = storeToRefs(sceneStore);
type Emit = { type Emit = {
(e: 'cancel'): void; (e: 'cancel'): void;
@ -92,6 +101,8 @@ const props = defineProps({
}); });
const current = ref<number>(0); const current = ref<number>(0);
const deviceRef = ref<any>();
const actionRef = ref<any>();
const DeviceModel = reactive<DeviceModelType>({ const DeviceModel = reactive<DeviceModelType>({
productId: '', productId: '',
@ -119,6 +130,71 @@ const onCancel = () => {
emit('cancel'); emit('cancel');
}; };
const onSave = (_data: any) => {
const item: any = {
selector: DeviceModel.selector,
source: DeviceModel.source,
selectorValues: DeviceModel.selectorValues,
productId: DeviceModel.productId,
message: _data.message,
};
//
if (DeviceModel.selector === 'variable') {
item.selector = 'fixed';
}
if (DeviceModel.selector === 'relation') {
item.upperKey = 'scene.deviceId';
}
const _options: any = {
name: '-', //
type: '', //
properties: '', //
propertiesValue: '', //
selector: DeviceModel.selector, //
productName: DeviceModel.productDetail.name,
relationName: DeviceModel.relationName,
triggerName: data.value.options?.trigger?.name || '触发设备',
taglist: [],
columns: [],
otherColumns: [],
};
_options.name = DeviceModel.deviceDetail?.name;
const _type = _data.message.messageType;
if (_type === 'INVOKE_FUNCTION') {
_options.type = '执行';
_options.properties = DeviceModel.propertiesName;
}
if (_type === 'READ_PROPERTY') {
_options.type = '读取';
_options.properties = DeviceModel.propertiesName;
}
if (_type === 'WRITE_PROPERTY') {
_options.type = '设置';
_options.properties = DeviceModel.propertiesName;
_options.propertiesValue =
typeof DeviceModel.propertiesValue === 'object'
? JSON.stringify(DeviceModel.propertiesValue)
: `${DeviceModel.propertiesValue}`;
_options.columns = DeviceModel.columns;
_options.otherColumns = DeviceModel.columns;
const cur: any = Object.values(_data.message.properties)?.[0];
if (cur?.source === 'upper') {
_options.propertiesValue = DeviceModel.actionName;
}
}
if (_options.selector === 'tag') {
_options.taglist = DeviceModel.tagList.map((it) => ({
name: it.column || it.name,
type: it.type ? (it.type === 'and' ? '并且' : '或者') : '',
value: it.value,
}));
}
if (_options.selector === 'variable') {
_options.name = DeviceModel.selectorValues?.[0]?.name;
}
emit('save', item, _options);
};
const save = async (step?: number) => { const save = async (step?: number) => {
let _step = step !== undefined ? step : current.value; let _step = step !== undefined ? step : current.value;
if (_step === 0) { if (_step === 0) {
@ -126,10 +202,15 @@ const save = async (step?: number) => {
? (current.value = 1) ? (current.value = 1)
: onlyMessage('请选择产品', 'error'); : onlyMessage('请选择产品', 'error');
} else if (_step === 1) { } else if (_step === 1) {
DeviceModel.deviceId if (deviceRef.value) {
? (current.value = 2) await deviceRef.value?.onFormSave();
: onlyMessage('请选择设备', 'error'); current.value = 2;
}
} else { } else {
if (actionRef.value) {
const _data = await actionRef.value?.onFormSave();
onSave(_data);
}
} }
}; };
@ -148,24 +229,23 @@ const prev = () => {
const saveClick = () => save(); const saveClick = () => save();
const onDeviceSave = (_data: any, _detail: any) => { const onDeviceSave = (_data: any, _detail: any) => {
Object.assign(DeviceModel, _data) Object.assign(DeviceModel, _data);
DeviceModel.deviceId = _detail.id DeviceModel.deviceDetail = _detail;
DeviceModel.deviceDetail = _detail };
}
watch( watch(
() => props.value, () => props.value,
(newValue) => { (newValue) => {
Object.assign(DeviceModel, newValue); Object.assign(DeviceModel, newValue);
if(newValue?.productId){ if (newValue?.productId) {
detail(newValue.productId).then(resp => { detail(newValue.productId).then((resp) => {
if(resp.status === 200){ if (resp.status === 200) {
DeviceModel.productDetail = resp.result DeviceModel.productDetail = resp.result;
} }
}) });
} }
}, },
{ immediate: true, deep: true }, { immediate: true },
); );
</script> </script>

View File

@ -18,12 +18,13 @@
}, },
]" ]"
> >
<j-card-select <!-- <j-card-select
v-model:value="formModel.type" v-model:value="formModel.type"
:options="options" :options="options"
type="horizontal" type="horizontal"
float="right" float="right"
/> /> -->
<a-radio-group v-model:value="formModel.type" :options="options" />
</a-form-item> </a-form-item>
<ActionTypeComponent <ActionTypeComponent
v-bind="props" v-bind="props"
@ -43,10 +44,9 @@ import Notify from '../Notify/index.vue';
import Device from '../Device/index.vue'; import Device from '../Device/index.vue';
import { PropType } from 'vue'; import { PropType } from 'vue';
import { ActionsType } from '../../../typings'; import { ActionsType } from '../../../typings';
import ActionTypeComponent from './ActionTypeComponent.vue' import ActionTypeComponent from './ActionTypeComponent.vue';
import { randomString } from '@/utils/utils'; import { randomString } from '@/utils/utils';
const props = defineProps({ const props = defineProps({
branchesName: { branchesName: {
type: Number, type: Number,
@ -63,8 +63,8 @@ const props = defineProps({
data: { data: {
type: Object as PropType<ActionsType>, type: Object as PropType<ActionsType>,
default: () => ({ default: () => ({
key: randomString() key: randomString(),
}) }),
}, },
parallel: { parallel: {
type: Boolean, type: Boolean,
@ -117,7 +117,11 @@ watch(
() => props.data, () => props.data,
(newVal) => { (newVal) => {
if (newVal?.executor) { if (newVal?.executor) {
formModel.type = (newVal?.executor === 'alarm' ? newVal?.alarm?.mode : newVal?.executor) as string formModel.type = (
newVal?.executor === 'alarm'
? newVal?.alarm?.mode
: newVal?.executor
) as string;
} }
}, },
{ {
@ -129,7 +133,15 @@ const onOk = () => {
actionForm.value.validate().then((values: any) => { actionForm.value.validate().then((values: any) => {
actionType.value = values?.type; actionType.value = values?.type;
if (values?.type === 'relieve' || values?.type === 'trigger') { if (values?.type === 'relieve' || values?.type === 'trigger') {
emit('save', { ...props.data, executor: 'alarm', alarm: { mode: values.type } }, {}); emit(
'save',
{
...props.data,
executor: 'alarm',
alarm: { mode: values.type },
},
{},
);
} }
}); });
}; };
@ -140,10 +152,10 @@ const onCancel = () => {
const onPropsOk = (data: any, options?: any) => { const onPropsOk = (data: any, options?: any) => {
emit('save', { ...data, executor: data.type }, options); emit('save', { ...data, executor: data.type }, options);
actionType.value = '' actionType.value = '';
}; };
const onPropsCancel = () => { const onPropsCancel = () => {
actionType.value = '' actionType.value = '';
} };
</script> </script>

View File

@ -1,5 +1,5 @@
<template> <template>
<Search <j-advanced-search
:columns="columns" :columns="columns"
type="simple" type="simple"
target="action-notice-config" target="action-notice-config"

View File

@ -1,5 +1,5 @@
<template> <template>
<Search <j-advanced-search
:columns="columns" :columns="columns"
type="simple" type="simple"
target="action-notice-template" target="action-notice-template"

View File

@ -1,10 +1,11 @@
<template> <template>
<a-spin :spinning="loading"> <a-spin :spinning="loading">
<j-card-select <!-- <j-card-select
v-model:value="notifyType" v-model:value="notifyType"
:options="options" :options="options"
:icon-size="106" :icon-size="106"
/> /> -->
<a-radio-group v-model:value="notifyType" :options="options" @change="onRadioChange" />
</a-spin> </a-spin>
</template> </template>
@ -34,13 +35,17 @@ const notifyType = ref('');
const options = ref<any[]>([]); const options = ref<any[]>([]);
watch( watch(
() => notifyType, () => props.value,
(newVal) => { (newVal) => {
emit('update:value', newVal) notifyType.value = newVal
}, },
{ deep: true, immediate: true }, { deep: true, immediate: true },
); );
const onRadioChange = (e: any) => {
emit('update:value', e.target.value)
}
onMounted(() => { onMounted(() => {
loading.value = true loading.value = true
notice.queryMessageType().then((resp) => { notice.queryMessageType().then((resp) => {

View File

@ -122,7 +122,6 @@ const jumpStep = async (val: number) => {
if (val === 0) { if (val === 0) {
current.value = val; current.value = val;
} else if (val === 1) { } else if (val === 1) {
console.log(formModel)
if (formModel.notifyType) { if (formModel.notifyType) {
current.value = val; current.value = val;
} else { } else {

View File

@ -23,7 +23,11 @@
type="serial" type="serial"
:branchesName="props.name" :branchesName="props.name"
:parallel="false" :parallel="false"
:actions="serialArray.length ? serialArray[0].actions : []" :actions="
serialArray.length ? serialArray[0].actions : []
"
@add="onAdd"
@delete="onDelete"
/> />
</div> </div>
</a-collapse-panel> </a-collapse-panel>
@ -41,7 +45,11 @@
type="parallel" type="parallel"
:branchesName="props.name" :branchesName="props.name"
:parallel="true" :parallel="true"
:actions="parallelArray.length ? parallelArray[0].actions : []" :actions="
parallelArray.length
? parallelArray[0].actions
: []
"
@add="onAdd" @add="onAdd"
@delete="onDelete" @delete="onDelete"
/> />
@ -57,6 +65,7 @@ import ShakeLimit from '../components/ShakeLimit/index.vue';
import { List } from './ListItem'; import { List } from './ListItem';
import { BranchesThen } from '../../typings'; import { BranchesThen } from '../../typings';
import { PropType } from 'vue'; import { PropType } from 'vue';
import { randomString } from '@/utils/utils';
interface ActionsProps { interface ActionsProps {
name: number; name: number;
@ -73,13 +82,15 @@ const props = defineProps({
openShakeLimit: Boolean, openShakeLimit: Boolean,
}); });
const emit = defineEmits(['update', 'add']);
const shakeLimit = ref({ const shakeLimit = ref({
enabled: false enabled: false,
}); });
const activeKeys = ref<string[]>(['1']); const activeKeys = ref<string[]>(['1']);
const parallelArray = ref<BranchesThen[]>([]); const parallelArray = ref<BranchesThen[]>([]);
const serialArray = ref<BranchesThen[]>([]); const serialArray = ref<BranchesThen[]>([]);
const lock = ref<boolean>(false) const lock = ref<boolean>(false);
watch( watch(
() => props.thenOptions, () => props.thenOptions,
@ -96,8 +107,8 @@ watch(
parallelArray.value.length && parallelArray.value.length &&
(!serialArray.value.length || !isSerialActions) (!serialArray.value.length || !isSerialActions)
) { ) {
activeKeys.value = ['2'] activeKeys.value = ['2'];
lock.value = true lock.value = true;
} }
//TODO //TODO
@ -109,11 +120,37 @@ watch(
); );
const onDelete = (_key: string) => { const onDelete = (_key: string) => {
console.log(_key) const aIndex = unref(serialArray)[0].actions?.findIndex(
} (aItem) => aItem.key === _key,
const onAdd = (data: any) => { );
console.log(data) if (aIndex !== -1) {
} serialArray.value[0].actions?.splice(aIndex, 1);
emit('update', serialArray[0], false);
}
};
const onAdd = (actionItem: any) => {
const newParallelArray = [...parallelArray.value];
if (newParallelArray.length) {
const indexOf = newParallelArray[0].actions?.findIndex(
(aItem) => aItem.key === actionItem.key,
);
if (indexOf !== -1) {
newParallelArray[0].actions.splice(indexOf, 1, actionItem);
} else {
newParallelArray[0].actions.push(actionItem);
}
parallelArray.value = [...newParallelArray];
console.log(parallelArray.value);
emit('update', newParallelArray[0], true);
} else {
actionItem.key = randomString();
emit('add', {
parallel: true,
key: randomString(),
actions: [actionItem],
});
}
};
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>