fix(editor): 优化代码逻辑

This commit is contained in:
parisma 2022-10-26 19:00:46 +08:00
parent 49c0ec9dd9
commit f8d7eaea5e

View File

@ -78,19 +78,19 @@ const selectConfig = computed(() => {
const fieldKey = ref('');
const multiple = ref(true);
let lastTagSnapshot = cloneDeep(props.model[props.name]) || [];
let shouldWatch = true;
// editorshouldWatchlastTagSnapshot
// editorsetTimeoutlastTagSnapshot
watch(
() => props.model[props.name],
(selectValue) => {
if (shouldWatch) {
setTimeout(() => {
lastTagSnapshot = cloneDeep(selectValue) || [];
}
});
},
);
watchEffect(async () => {
if (!props.model[props.name]) return;
const combineNames = await Promise.all(
props.model[props.name].map(async (id: string) => {
const { name = '' } = (await services?.codeBlockService.getCodeContentById(id)) || {};
@ -101,11 +101,9 @@ watchEffect(async () => {
});
const changeHandler = async (value: any) => {
shouldWatch = false;
let codeIds = value;
if (typeof value === 'string') {
multiple.value = false;
lastTagSnapshot = [lastTagSnapshot];
codeIds = value ? [value] : [];
}
await setCombineRelation(codeIds);
@ -124,11 +122,8 @@ const setCombineRelation = async (codeIds: string[]) => {
opFlag = codeIds.length < lastTagSnapshot.length ? CodeSelectOp.DELETE : CodeSelectOp.ADD;
diffValues = xor(codeIds, lastTagSnapshot) as string[];
}
//
await services?.codeBlockService.setCombineRelation(id, diffValues, opFlag, props.prop);
lastTagSnapshot = codeIds;
shouldWatch = true;
};
const viewHandler = async () => {