-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathhandleResize.ts
38 lines (35 loc) · 1.45 KB
/
handleResize.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* MineAdmin is committed to providing solutions for quickly building web applications
* Please view the LICENSE file that was distributed with this source code,
* For the full copyright and license information.
* Thank you very much for using MineAdmin.
*
* @Author X.Mo<[email protected]>
* @Link https://github.com/mineadmin
*/
import { useMouseInElement, useResizeObserver } from '@vueuse/core'
import type { Ref } from 'vue'
export default function handleResize(el: Ref<HTMLElement>) {
const { setMobileState, setMobileSubmenuState } = useSettingStore()
useResizeObserver(document.body, (entries) => {
const [entry] = entries
const { width, height } = entry.contentRect
const searchPanelNode = document.querySelector('.mine-search-panel-container') as HTMLElement
searchPanelNode.style.top = height < 500 ? '0px' : height < 800 ? 'calc(100% - 50% - 250px)' : 'calc(100% - 50% - 350px)'
setMobileState(width < 1024)
setMobileSubmenuState(!(width < 1024))
checkMobileSubAside(el)
})
}
function checkMobileSubAside(el: Ref<HTMLElement>) {
const { isOutside } = useMouseInElement(el)
const settingStore = useSettingStore()
const listenerEvent = () => {
if (settingStore.getMobileSubmenuState() && isOutside.value) {
settingStore.setMobileSubmenuState(false)
}
}
settingStore.getMobileState()
? document.addEventListener('mousemove', listenerEvent)
: document.removeEventListener('mousemove', listenerEvent)
}