|
@@ -76,6 +76,17 @@ const gridLayoutRef = ref<{
|
|
|
} | null>(null);
|
|
} | null>(null);
|
|
|
const localLayout = ref<ModuleGridItem[]>(props.layout.map((item) => ({ ...item })));
|
|
const localLayout = ref<ModuleGridItem[]>(props.layout.map((item) => ({ ...item })));
|
|
|
|
|
|
|
|
|
|
+function isLayoutEqual(a: ModuleGridItem[], b: ModuleGridItem[]): boolean {
|
|
|
|
|
+ if (a.length !== b.length) return false;
|
|
|
|
|
+ const map = new Map(b.map((item) => [item.i, item]));
|
|
|
|
|
+ for (const ai of a) {
|
|
|
|
|
+ const bi = map.get(ai.i);
|
|
|
|
|
+ if (!bi) return false;
|
|
|
|
|
+ if (ai.x !== bi.x || ai.y !== bi.y || ai.w !== bi.w || ai.h !== bi.h) return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function syncGridWidth() {
|
|
function syncGridWidth() {
|
|
|
const vm = gridLayoutRef.value;
|
|
const vm = gridLayoutRef.value;
|
|
|
const el = containerRef.value;
|
|
const el = containerRef.value;
|
|
@@ -112,6 +123,7 @@ function scheduleGridSync() {
|
|
|
watch(
|
|
watch(
|
|
|
() => props.layout,
|
|
() => props.layout,
|
|
|
(val) => {
|
|
(val) => {
|
|
|
|
|
+ if (isLayoutEqual(val, localLayout.value)) return;
|
|
|
localLayout.value = val.map((item) => ({ ...item }));
|
|
localLayout.value = val.map((item) => ({ ...item }));
|
|
|
},
|
|
},
|
|
|
{ deep: true },
|
|
{ deep: true },
|
|
@@ -135,6 +147,7 @@ watch(
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
function onLayoutUpdated(newLayout: ModuleGridItem[]) {
|
|
function onLayoutUpdated(newLayout: ModuleGridItem[]) {
|
|
|
|
|
+ if (isLayoutEqual(newLayout, props.layout)) return;
|
|
|
emit('update:layout', newLayout.map((item) => ({ ...item })));
|
|
emit('update:layout', newLayout.map((item) => ({ ...item })));
|
|
|
}
|
|
}
|
|
|
|
|
|