mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-06-16 01:49:25 +08:00
fix(editor): 优化代码逻辑
This commit is contained in:
parent
49c0ec9dd9
commit
f8d7eaea5e
@ -78,19 +78,19 @@ const selectConfig = computed(() => {
|
|||||||
const fieldKey = ref('');
|
const fieldKey = ref('');
|
||||||
const multiple = ref(true);
|
const multiple = ref(true);
|
||||||
let lastTagSnapshot = cloneDeep(props.model[props.name]) || [];
|
let lastTagSnapshot = cloneDeep(props.model[props.name]) || [];
|
||||||
let shouldWatch = true;
|
|
||||||
|
|
||||||
// 管理端和editor有表现不一致的地方,管理端切换组件表单不会重新渲染,因此增加shouldWatch控制lastTagSnapshot的记录
|
// 管理端和editor有表现不一致的地方,管理端切换组件表单不会重新渲染,通过setTimeout确保lastTagSnapshot的准确性
|
||||||
watch(
|
watch(
|
||||||
() => props.model[props.name],
|
() => props.model[props.name],
|
||||||
(selectValue) => {
|
(selectValue) => {
|
||||||
if (shouldWatch) {
|
setTimeout(() => {
|
||||||
lastTagSnapshot = cloneDeep(selectValue) || [];
|
lastTagSnapshot = cloneDeep(selectValue) || [];
|
||||||
}
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
watchEffect(async () => {
|
watchEffect(async () => {
|
||||||
|
if (!props.model[props.name]) return;
|
||||||
const combineNames = await Promise.all(
|
const combineNames = await Promise.all(
|
||||||
props.model[props.name].map(async (id: string) => {
|
props.model[props.name].map(async (id: string) => {
|
||||||
const { name = '' } = (await services?.codeBlockService.getCodeContentById(id)) || {};
|
const { name = '' } = (await services?.codeBlockService.getCodeContentById(id)) || {};
|
||||||
@ -101,11 +101,9 @@ watchEffect(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const changeHandler = async (value: any) => {
|
const changeHandler = async (value: any) => {
|
||||||
shouldWatch = false;
|
|
||||||
let codeIds = value;
|
let codeIds = value;
|
||||||
if (typeof value === 'string') {
|
if (typeof value === 'string') {
|
||||||
multiple.value = false;
|
multiple.value = false;
|
||||||
lastTagSnapshot = [lastTagSnapshot];
|
|
||||||
codeIds = value ? [value] : [];
|
codeIds = value ? [value] : [];
|
||||||
}
|
}
|
||||||
await setCombineRelation(codeIds);
|
await setCombineRelation(codeIds);
|
||||||
@ -124,11 +122,8 @@ const setCombineRelation = async (codeIds: string[]) => {
|
|||||||
opFlag = codeIds.length < lastTagSnapshot.length ? CodeSelectOp.DELETE : CodeSelectOp.ADD;
|
opFlag = codeIds.length < lastTagSnapshot.length ? CodeSelectOp.DELETE : CodeSelectOp.ADD;
|
||||||
diffValues = xor(codeIds, lastTagSnapshot) as string[];
|
diffValues = xor(codeIds, lastTagSnapshot) as string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 记录绑定关系
|
// 记录绑定关系
|
||||||
await services?.codeBlockService.setCombineRelation(id, diffValues, opFlag, props.prop);
|
await services?.codeBlockService.setCombineRelation(id, diffValues, opFlag, props.prop);
|
||||||
lastTagSnapshot = codeIds;
|
|
||||||
shouldWatch = true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const viewHandler = async () => {
|
const viewHandler = async () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user