|
1 | 1 | <template> |
2 | | - <div ref="body" class="relative grow flex items-stretch min-h-0"> |
| 2 | + <div ref="container" class="relative grow flex items-stretch min-h-0"> |
3 | 3 | <NanoLeftActionBar v-if="!ctl.hideLeftActionBar" ref="leftActionBar"/> |
4 | | - <NanoLeftSidebar v-if="!ctl.hideLeftSidebar" ref="leftSidebar"> |
| 4 | + <NanoLeftSidebar v-if="!ctl.hideLeftSidebar" ref="leftSidebar" :style="layout.leftSidebarLayout"> |
5 | 5 | <!--draggable line--> |
6 | 6 | <div |
7 | 7 | ref="leftDraggableLine" |
8 | | - class="absolute z-2 right--1 top-0 h-full w-2 bg-transparent cursor-col-resize" |
| 8 | + class="absolute z-4 right--2 top-0 h-full w-2 bg-transparent cursor-col-resize" |
9 | 9 | /> |
10 | 10 | </NanoLeftSidebar> |
11 | 11 | <NanoMain ref="main"/> |
12 | | - <NanoRightSidebar v-if="!ctl.hideRightSidebar" ref="rightSidebar"> |
| 12 | + <NanoRightSidebar v-if="!ctl.hideRightSidebar" ref="rightSidebar" :style="layout.rightSidebarLayout"> |
13 | 13 | <!--draggable line--> |
14 | 14 | <div |
15 | 15 | ref="rightDraggableLine" |
16 | | - class="absolute z-2 left--1 top-0 h-full w-2 bg-transparent cursor-col-resize" |
| 16 | + class="absolute z-4 left--2 top-0 h-full w-2 bg-transparent cursor-col-resize" |
17 | 17 | /> |
18 | 18 | </NanoRightSidebar> |
19 | 19 | <NanoRightActionBar v-if="!ctl.hideRightActionBar" ref="rightActionBar"/> |
|
28 | 28 | import NanoRightActionBar from '@NanoUI/NanoRightActionBar/index.vue'; |
29 | 29 | import { controllerStore } from '@store/controller'; |
30 | 30 | import { onMounted, ref } from 'vue'; |
31 | | - import { dragChangeWidth } from '../../utils/dragChangeWidth'; |
| 31 | + import { drag } from '../../utils/drag'; |
| 32 | + import { contentLayoutStore } from '@store/contentLayout'; |
32 | 33 |
|
33 | 34 | const ctl = controllerStore(); |
34 | 35 |
|
35 | | - const body = ref<HTMLElement | null>(null); |
| 36 | + const layout = contentLayoutStore(); |
| 37 | +
|
| 38 | + const container = ref<HTMLElement | null>(null); |
36 | 39 | const leftActionBar = ref<InstanceType<typeof NanoLeftActionBar> | null>(); |
37 | 40 | const leftSidebar = ref<InstanceType<typeof NanoLeftSidebar> | null>(); |
38 | 41 | const rightSidebar = ref<InstanceType<typeof NanoRightSidebar> | null>(); |
|
41 | 44 | const leftDraggableLine = ref<HTMLDivElement | null>(); |
42 | 45 | const rightDraggableLine = ref<HTMLDivElement | null>(); |
43 | 46 |
|
| 47 | + type OriginalDataType = { |
| 48 | + // container width |
| 49 | + cw: number; |
| 50 | + // left sidebar width |
| 51 | + lsw: number; |
| 52 | + // right sidebar width |
| 53 | + rsw: number; |
| 54 | + // left action bar width |
| 55 | + law: number; |
| 56 | + // right action bar width |
| 57 | + raw: number; |
| 58 | + }; |
| 59 | +
|
44 | 60 | onMounted(() => { |
45 | | - if (body.value && leftSidebar.value && rightSidebar.value && leftActionBar.value && rightActionBar.value) { |
46 | | - dragChangeWidth({ |
47 | | - parentEl: body.value!, |
48 | | - targetEl: leftSidebar.value!.$el, |
49 | | - dragEl: leftDraggableLine.value!, |
50 | | - otherEls: [ rightSidebar.value!.$el, leftActionBar.value!.$el, rightActionBar.value!.$el ] |
| 61 | + if (container.value && leftSidebar.value && rightSidebar.value && leftActionBar.value && rightActionBar.value) { |
| 62 | + const originalData = (): OriginalDataType => { |
| 63 | + return { |
| 64 | + cw: container.value!.clientWidth, |
| 65 | + lsw: leftSidebar.value!.$el.clientWidth, |
| 66 | + rsw: rightSidebar.value!.$el.clientWidth, |
| 67 | + law: leftActionBar.value!.$el.clientWidth, |
| 68 | + raw: rightActionBar.value!.$el.clientWidth |
| 69 | + }; |
| 70 | + }; |
| 71 | + drag<OriginalDataType>({ |
| 72 | + el: leftDraggableLine.value!, |
| 73 | + originalData, |
| 74 | + handlerFn: ({ x, originalData: { cw, law, lsw, rsw, raw } }) => { |
| 75 | + const newWidth = lsw + x; |
| 76 | + const otherElsWidth = law + raw + rsw; |
| 77 | + if (cw - otherElsWidth - 400 < newWidth) { |
| 78 | + return; |
| 79 | + } |
| 80 | + if (newWidth < 120) { |
| 81 | + return; |
| 82 | + } |
| 83 | + layout.setLeftSidebarLayout({ |
| 84 | + width: newWidth / cw * 100 + '%' |
| 85 | + }); |
| 86 | + } |
51 | 87 | }); |
52 | | - dragChangeWidth({ |
53 | | - parentEl: body.value!, |
54 | | - targetEl: rightSidebar.value!.$el, |
55 | | - dragEl: rightDraggableLine.value!, |
56 | | - otherEls: [ leftSidebar.value!.$el, leftActionBar.value!.$el, rightActionBar.value!.$el ], |
57 | | - reverseDirection: true |
| 88 | + drag<OriginalDataType>({ |
| 89 | + el: rightDraggableLine.value!, |
| 90 | + originalData, |
| 91 | + handlerFn: ({ x, originalData: { cw, law, lsw, rsw, raw } }) => { |
| 92 | + const newWidth = rsw - x; |
| 93 | + const otherElsWidth = law + raw + lsw; |
| 94 | + if (cw - otherElsWidth - 400 < newWidth) { |
| 95 | + return; |
| 96 | + } |
| 97 | + if (newWidth < 120) { |
| 98 | + return; |
| 99 | + } |
| 100 | + layout.setRightSidebarLayout({ |
| 101 | + width: newWidth / cw * 100 + '%' |
| 102 | + }); |
| 103 | + } |
58 | 104 | }); |
59 | 105 | } |
60 | 106 | }); |
|
0 commit comments