mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-06 03:57:56 +08:00
Merge branch 'bugfix/parisma_codeBlock' into 'master' (merge request !4)
fix(editor): 修复管理端和pg表现不一致的问题,删除冗余逻辑
This commit is contained in:
commit
baedcaba05
@ -33,7 +33,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, defineEmits, defineProps, inject, ref, watchEffect } from 'vue';
|
import { computed, defineEmits, defineProps, inject, ref, watch, watchEffect } from 'vue';
|
||||||
import { cloneDeep, map, xor } from 'lodash-es';
|
import { cloneDeep, map, xor } from 'lodash-es';
|
||||||
|
|
||||||
import { TMagicCard, tMagicMessage, TMagicTooltip } from '@tmagic/design';
|
import { TMagicCard, tMagicMessage, TMagicTooltip } from '@tmagic/design';
|
||||||
@ -77,12 +77,22 @@ const selectConfig = computed(() => {
|
|||||||
});
|
});
|
||||||
const fieldKey = ref('');
|
const fieldKey = ref('');
|
||||||
const multiple = ref(true);
|
const multiple = ref(true);
|
||||||
const combineIds = ref<string[]>([]);
|
|
||||||
let lastTagSnapshot = cloneDeep(props.model[props.name]) || [];
|
let lastTagSnapshot = cloneDeep(props.model[props.name]) || [];
|
||||||
|
let shouldWatch = true;
|
||||||
|
|
||||||
|
// 管理端和editor有表现不一致的地方,管理端切换组件表单不会重新渲染,因此增加shouldWatch控制lastTagSnapshot的记录
|
||||||
|
watch(
|
||||||
|
() => props.model[props.name],
|
||||||
|
(selectValue) => {
|
||||||
|
if (shouldWatch) {
|
||||||
|
lastTagSnapshot = cloneDeep(selectValue) || [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
watchEffect(async () => {
|
watchEffect(async () => {
|
||||||
const combineNames = await Promise.all(
|
const combineNames = await Promise.all(
|
||||||
combineIds.value.map(async (id) => {
|
props.model[props.name].map(async (id: string) => {
|
||||||
const { name = '' } = (await services?.codeBlockService.getCodeContentById(id)) || {};
|
const { name = '' } = (await services?.codeBlockService.getCodeContentById(id)) || {};
|
||||||
return name;
|
return name;
|
||||||
}),
|
}),
|
||||||
@ -91,6 +101,7 @@ 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;
|
||||||
@ -117,13 +128,7 @@ const setCombineRelation = async (codeIds: string[]) => {
|
|||||||
// 记录绑定关系
|
// 记录绑定关系
|
||||||
await services?.codeBlockService.setCombineRelation(id, diffValues, opFlag, props.prop);
|
await services?.codeBlockService.setCombineRelation(id, diffValues, opFlag, props.prop);
|
||||||
lastTagSnapshot = codeIds;
|
lastTagSnapshot = codeIds;
|
||||||
await setCombineIds(codeIds);
|
shouldWatch = true;
|
||||||
};
|
|
||||||
|
|
||||||
// 记录当前已被绑定的代码块,为查看弹窗的展示内容
|
|
||||||
const setCombineIds = async (codeIds: string[]) => {
|
|
||||||
combineIds.value = codeIds;
|
|
||||||
await services?.codeBlockService.setCombineIds(codeIds);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const viewHandler = async () => {
|
const viewHandler = async () => {
|
||||||
@ -132,8 +137,8 @@ const viewHandler = async () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 记录当前已被绑定的代码块,为查看弹窗的展示内容
|
// 记录当前已被绑定的代码块,为查看弹窗的展示内容
|
||||||
await setCombineIds(props.model[props.name]);
|
await services?.codeBlockService.setCombineIds(props.model[props.name]);
|
||||||
await services?.codeBlockService.setMode(CodeEditorMode.LIST);
|
await services?.codeBlockService.setMode(CodeEditorMode.LIST);
|
||||||
services?.codeBlockService.setCodeEditorContent(true, combineIds.value[0]);
|
services?.codeBlockService.setCodeEditorContent(true, props.model[props.name][0]);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user