Skip to content

Commit 844490b

Browse files
committed
Update: 优化拖拽性能
1 parent 323b2de commit 844490b

File tree

6 files changed

+50
-36
lines changed

6 files changed

+50
-36
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"overlayscrollbars": "^2.10.1",
2222
"overlayscrollbars-vue": "^0.5.9",
2323
"pinia": "^2.3.0",
24-
"pinia-plugin-persistedstate": "^3.2.3",
24+
"pinia-plugin-persistedstate": "3.2.3",
2525
"uuid": "^11.0.3",
2626
"viewerjs": "^1.11.7",
2727
"vitepress": "^1.5.0",

package/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
:style="{ backgroundImage: `url(${ bgList[0] })` }"
66
>
77
<slot name="homePage">
8-
<div class="w-80vw max-w-800px mb-12vh h-a flex-center flex-col rounded-xl py-10">
8+
<div class="w-80vw max-w-800px mb-12vh h-a flex-center flex-col py-10">
99
<div
1010
class="relative w-60 h-60 max-w-80vw max-h-80vw"
1111
style="filter: drop-shadow(0 0 16px rgba(0,0,0,.36));"

package/components/NanoBody/index.vue

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<template>
22
<div ref="container" class="relative grow flex items-stretch min-h-0">
33
<NanoLeftActionBar v-if="!ctl.hideLeftActionBar" ref="leftActionBar"/>
4-
<NanoLeftSidebar v-if="!ctl.hideLeftSidebar" ref="leftSidebar" :style="layout.leftSidebarLayout">
4+
<NanoLeftSidebar v-if="!ctl.hideLeftSidebar" ref="leftSidebar" :style="leftSidebarLayout">
55
<!--draggable line-->
66
<div
77
ref="leftDraggableLine"
88
class="absolute z-4 right--2 top-0 h-full w-2 bg-transparent cursor-col-resize"
99
/>
1010
</NanoLeftSidebar>
1111
<NanoMain ref="main"/>
12-
<NanoRightSidebar v-if="!ctl.hideRightSidebar" ref="rightSidebar" :style="layout.rightSidebarLayout">
12+
<NanoRightSidebar v-if="!ctl.hideRightSidebar" ref="rightSidebar" :style="rightSidebarLayout">
1313
<!--draggable line-->
1414
<div
1515
ref="rightDraggableLine"
16-
class="absolute z-4 left--2 top-0 h-full w-2 bg-transparent cursor-col-resize"
16+
class="absolute z-4 left-0 top-0 h-full w-2 bg-transparent cursor-col-resize"
1717
/>
1818
</NanoRightSidebar>
1919
<NanoRightActionBar v-if="!ctl.hideRightActionBar" ref="rightActionBar"/>
@@ -27,14 +27,24 @@
2727
import NanoLeftActionBar from '@NanoUI/NanoLeftActionBar/index.vue';
2828
import NanoRightActionBar from '@NanoUI/NanoRightActionBar/index.vue';
2929
import { controllerStore } from '@store/controller';
30-
import { onMounted, ref } from 'vue';
30+
import { onMounted, ref, watch } from 'vue';
3131
import { drag } from '../../utils/drag';
3232
import { contentLayoutStore } from '@store/contentLayout';
33+
import { debounce } from 'lodash-es';
3334
3435
const ctl = controllerStore();
35-
3636
const layout = contentLayoutStore();
3737
38+
const leftSidebarLayout = ref(layout.leftSidebarLayout);
39+
const rightSidebarLayout = ref(layout.rightSidebarLayout);
40+
41+
watch(leftSidebarLayout, debounce((val) => {
42+
layout.setLeftSidebarLayout(val);
43+
}, 200), { deep: true });
44+
watch(rightSidebarLayout, debounce((val) => {
45+
layout.setRightSidebarLayout(val);
46+
}, 200), { deep: true });
47+
3848
const container = ref<HTMLElement | null>(null);
3949
const leftActionBar = ref<InstanceType<typeof NanoLeftActionBar> | null>();
4050
const leftSidebar = ref<InstanceType<typeof NanoLeftSidebar> | null>();
@@ -80,9 +90,7 @@
8090
if (newWidth < 120) {
8191
return;
8292
}
83-
layout.setLeftSidebarLayout({
84-
width: newWidth / cw * 100 + '%'
85-
});
93+
leftSidebarLayout.value = { width: newWidth / cw * 100 + '%' };
8694
}
8795
});
8896
drag<OriginalDataType>({
@@ -97,9 +105,7 @@
97105
if (newWidth < 120) {
98106
return;
99107
}
100-
layout.setRightSidebarLayout({
101-
width: newWidth / cw * 100 + '%'
102-
});
108+
rightSidebarLayout.value = { width: newWidth / cw * 100 + '%' };
103109
}
104110
});
105111
}

package/components/NanoContainer/index.vue

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<div
33
ref="container"
44
class="nano-theme absolute"
5-
:style="{ ...layout.containerLayout, ...animation }"
5+
:style="{ ...containerLayout, ...animation }"
66
>
77
<div v-show="!loading" class="relative w-full h-full flex flex-col">
8-
<NanoHeader ref="header" @dblclick="ctl.fullscreen = !ctl.fullscreen"/>
8+
<NanoHeader ref="header" @dblclick.self="ctl.fullscreen = !ctl.fullscreen"/>
99
<NanoBody/>
1010
<NanoFooter/>
1111
</div>
@@ -25,10 +25,11 @@
2525
import NanoBackdrop from '@NanoUI/NanoBackdrop/index.vue';
2626
import NanoNavModal from '@NanoUI/NanoNavModal/index.vue';
2727
import NanoSidebarDirModal from '@NanoUI/NanoSidebarDirModal/index.vue';
28-
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
28+
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
2929
import { controllerStore } from '@store/controller';
30-
import { contentLayoutStore, getWidthFromString } from '@store/contentLayout';
30+
import { contentLayoutStore, getWidthFromString, LayoutBaseInfo } from '@store/contentLayout';
3131
import { drag } from '../../utils/drag';
32+
import { debounce } from 'lodash-es';
3233
3334
const ctl = controllerStore();
3435
const layout = contentLayoutStore();
@@ -47,6 +48,13 @@
4748
};
4849
});
4950
51+
const containerLayout = ref<LayoutBaseInfo>(layout.containerLayout);
52+
53+
watch(containerLayout, debounce((val) => {
54+
// console.log('containerLayout changed', val);
55+
layout.setContainerLayout(val);
56+
}, 200), { deep: true });
57+
5058
onMounted(() => {
5159
const containerEl = container.value!;
5260
resizeObserver.value = new ResizeObserver((entries: ResizeObserverEntry[]) => {
@@ -81,7 +89,7 @@
8189
}, 1200);
8290
}
8391
});
84-
resizeObserver.value.observe(containerEl!);
92+
resizeObserver.value.observe(containerEl);
8593
8694
type OriginLayout = {
8795
isFullscreen: boolean;
@@ -107,26 +115,26 @@
107115
top: offsetTop
108116
};
109117
},
110-
handlerFn: ({ x, y, originalData: { isFullscreen, notFullScreenWidth, screenWidth, screenHeight, left, top }, pointerWelt, initial }) => {
118+
handlerFn: ({
119+
x,
120+
y,
121+
originalData: { isFullscreen, notFullScreenWidth, screenWidth, screenHeight, left, top },
122+
pointerWelt,
123+
initial
124+
}) => {
111125
let newLeft = left + x;
112126
const newTop = top + y;
113127
if (isFullscreen) {
114128
ctl.fullscreen = false;
115129
newLeft = initial.x - (initial.x / screenWidth) * notFullScreenWidth + x;
116130
}
117131
if (!pointerWelt.top && !pointerWelt.bottom && newTop > 0) {
118-
layout.setContainerLayout({
119-
top: newTop / screenHeight * 100 + '%'
120-
});
132+
containerLayout.value.top = newTop / screenHeight * 100 + '%';
121133
} else {
122-
layout.setContainerLayout({
123-
top: pointerWelt.bottom ? '98%' : '0'
124-
});
134+
containerLayout.value.top = pointerWelt.bottom ? '98%' : '0';
125135
}
126136
if (!pointerWelt.left && !pointerWelt.right) {
127-
layout.setContainerLayout({
128-
left: newLeft / screenWidth * 100 + '%'
129-
});
137+
containerLayout.value.left = newLeft / screenWidth * 100 + '%';
130138
}
131139
},
132140
beforeFn: () => enableAnimation.value = false,

package/components/NanoLogo/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="relative flex-center px-[calc(var(--s)*0.25)] whitespace-nowrap pointer-events-none">
2+
<div class="relative flex-center px-[calc(var(--s)*0.25)] whitespace-nowrap pointer-events-none select-none">
33
<img
44
class="w-[calc(var(--s)*0.72)] h-[calc(var(--s)*0.72)] rounded-[calc(var(--s)*.1)]"
55
:src="theme.logo"

package/store/contentLayout.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { merge } from 'lodash-es';
33
import { controllerStore } from '@store/controller';
44

55
export type LayoutBaseInfo = {
6-
top?: string;
7-
left?: string;
6+
top?: string | number;
7+
left?: string | number;
88
width?: string;
99
height?: string;
10-
} | undefined;
10+
};
1111

1212
export const contentLayoutStore = defineStore('contentLayout', {
1313
state: () => ({
@@ -18,25 +18,25 @@ export const contentLayoutStore = defineStore('contentLayout', {
1818
width: '90vw',
1919
height: '90vh'
2020
} as LayoutBaseInfo,
21-
changed: undefined as LayoutBaseInfo
21+
changed: undefined as LayoutBaseInfo | undefined
2222
},
2323
leftSidebar: {
2424
default: {
2525
width: '20%',
2626
height: undefined
2727
} as LayoutBaseInfo,
28-
changed: undefined as LayoutBaseInfo
28+
changed: undefined as LayoutBaseInfo | undefined
2929
},
3030
rightSidebar: {
3131
default: {
3232
width: '20%',
3333
height: undefined
3434
} as LayoutBaseInfo,
35-
changed: undefined as LayoutBaseInfo
35+
changed: undefined as LayoutBaseInfo | undefined
3636
}
3737
}),
3838
getters: {
39-
containerLayout: (state) => {
39+
containerLayout: (state): LayoutBaseInfo => {
4040
const ctl = controllerStore();
4141
return !ctl.onlyFullscreen && !ctl.fullscreen ?
4242
merge({}, state.container.default, state.container.changed) :

0 commit comments

Comments
 (0)