修复定时刷新折叠的bug

This commit is contained in:
xu_yanfeng 2024-12-28 16:23:52 +08:00
parent 1000b60f20
commit 8f5db59b63

View File

@ -58,25 +58,40 @@ export default defineComponent({
const expand = ref(false); const expand = ref(false);
onMounted(() => { onMounted(() => {
expand.value = false; expand.value = false;
if (props.value.isArray()) { freshSubData(props.value);
subData.value = props.value.data;
} else {
subData.value = null;
}
}); });
watch( watch(
() => props.value, () => props.value,
(v) => { (newData, oldData) => {
if (newData.id !== oldData.id) {
// id
expand.value = false; expand.value = false;
if (v.isArray()) {
subData.value = v.data;
} else {
subData.value = null;
} }
freshSubData(newData);
} }
); );
const subData = ref<Array<Property> | null>(null); const subData = ref<Array<Property> | null>(null);
function freshSubData(data: Info) {
const rawExpand = toRaw(expand.value);
if (!rawExpand) {
return;
}
const rawSubData = toRaw(subData.value);
if (rawSubData !== null) {
return;
}
const rawValue = toRaw(data);
if (!rawValue) {
return;
}
if (rawValue.isArray()) {
subData.value = data.data;
} else if (rawValue.isObject()) {
Bus.emit(BusMsg.RequestObjectData, rawValue, (info: Property[]) => {
subData.value = info;
});
}
}
return { return {
expand, expand,
subData, subData,
@ -122,18 +137,7 @@ export default defineComponent({
} }
}, },
onClickFold(v: boolean) { onClickFold(v: boolean) {
if (props.value.isArray()) { freshSubData(props.value);
return;
}
const s = toRaw(subData.value);
const e = toRaw(expand.value);
const rawValue = toRaw(props.value);
if (rawValue && rawValue.isObject() && s === null && e === true) {
// objectitem
Bus.emit(BusMsg.RequestObjectData, rawValue, (info: Property[]) => {
subData.value = info;
});
}
}, },
onChangeValue() { onChangeValue() {
if (!props.value.readonly) { if (!props.value.readonly) {