Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
28b5d22
commit b2a4ddf
Showing
34 changed files
with
1,244 additions
and
967 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './system'; | ||
export * from './router'; | ||
export * from './theme'; | ||
export * from './layout'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { watch, onUnmounted } from 'vue'; | ||
import { useOsTheme } from 'naive-ui'; | ||
import { useElementSize } from '@vueuse/core'; | ||
import { useThemeStore } from '@/store'; | ||
|
||
export function useTheme() { | ||
const osTheme = useOsTheme(); | ||
const theme = useThemeStore(); | ||
const { width } = useElementSize(document.documentElement); | ||
|
||
/** 监听操作系统主题模式 */ | ||
const stopHandle = watch( | ||
osTheme, | ||
newValue => { | ||
const isDark = newValue === 'dark'; | ||
theme.setDarkMode(isDark); | ||
}, | ||
{ immediate: true } | ||
); | ||
|
||
/** | ||
* 禁用横向滚动 | ||
* @description 页面切换时,过渡动画会产生水平方向的滚动条, 小于最小宽度时,不禁止 | ||
*/ | ||
const anotherStopHandle = watch(width, newValue => { | ||
if (newValue < theme.layout.minWidth) { | ||
document.documentElement.style.overflowX = 'auto'; | ||
} else { | ||
document.documentElement.style.overflowX = 'hidden'; | ||
} | ||
}); | ||
|
||
onUnmounted(() => { | ||
stopHandle(); | ||
anotherStopHandle(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
interface ScrollBodyStyle { | ||
overflow: string; | ||
paddingRight: string; | ||
} | ||
|
||
/** | ||
* body标签滚动 | ||
* @param duration - 显示滚动条的延迟时间 | ||
*/ | ||
export default function useBodyScroll(duration = 300) { | ||
const defaultStyle: ScrollBodyStyle = { | ||
overflow: '', | ||
paddingRight: '' | ||
}; | ||
function getInitBodyStyle() { | ||
const { overflow, paddingRight } = document.body.style; | ||
Object.assign(defaultStyle, { overflow, paddingRight }); | ||
} | ||
function setScrollBodyStyle() { | ||
document.body.style.paddingRight = `${window.innerWidth - document.body.clientWidth}px`; | ||
document.body.style.overflow = 'hidden'; | ||
} | ||
function resetScrollBodyStyle() { | ||
document.body.style.overflow = defaultStyle.overflow; | ||
document.body.style.paddingRight = defaultStyle.paddingRight; | ||
} | ||
|
||
/** | ||
* 处理body的滚动条 | ||
* @param hideScroll - 禁止滚动 | ||
*/ | ||
function scrollBodyHandler(hideScroll: boolean) { | ||
if (hideScroll) { | ||
setScrollBodyStyle(); | ||
} else { | ||
setTimeout(() => { | ||
resetScrollBodyStyle(); | ||
}, duration); | ||
} | ||
} | ||
|
||
getInitBodyStyle(); | ||
|
||
return { | ||
scrollBodyHandler | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,33 @@ | ||
import { computed, watch, onUnmounted } from 'vue'; | ||
import type { ComputedRef } from 'vue'; | ||
import { watch, onUnmounted } from 'vue'; | ||
import useBoolean from './useBoolean'; | ||
|
||
interface ScrollBodyStyle { | ||
overflow: string; | ||
paddingRight: string; | ||
} | ||
import useBodyScroll from './useBodyScroll'; | ||
|
||
/** | ||
* 使用弹窗 | ||
* @param hideScroll - 关闭html滚动条 | ||
* @param duration - 显示滚动条的延迟时间 | ||
*/ | ||
export default function useModalVisible(hideScroll = true, duration = 300) { | ||
export default function useModalVisible(hideScroll = true) { | ||
const { bool: visible, setTrue: openModal, setFalse: closeModal, toggle: toggleModal } = useBoolean(); | ||
const { scrollBodyHandler } = useBodyScroll(); | ||
|
||
const defaultStyle: ScrollBodyStyle = { | ||
overflow: '', | ||
paddingRight: '' | ||
}; | ||
function getInitBodyStyle() { | ||
if (hideScroll) { | ||
const { overflow, paddingRight } = document.body.style; | ||
Object.assign(defaultStyle, { overflow, paddingRight }); | ||
} | ||
} | ||
function setScrollBodyStyle() { | ||
document.body.style.paddingRight = `${window.innerWidth - document.body.clientWidth}px`; | ||
document.body.style.overflow = 'hidden'; | ||
} | ||
function resetScrollBodyStyle() { | ||
document.body.style.overflow = defaultStyle.overflow; | ||
document.body.style.paddingRight = defaultStyle.paddingRight; | ||
} | ||
|
||
function modalVisibleWatcher(visible: ComputedRef<boolean>) { | ||
function modalVisibleWatcher() { | ||
const stopHandle = watch(visible, async newValue => { | ||
if (hideScroll) { | ||
if (newValue) { | ||
setScrollBodyStyle(); | ||
} else { | ||
setTimeout(() => { | ||
resetScrollBodyStyle(); | ||
}, duration); | ||
} | ||
} | ||
scrollBodyHandler(newValue); | ||
}); | ||
|
||
onUnmounted(() => { | ||
stopHandle(); | ||
}); | ||
} | ||
|
||
function init() { | ||
getInitBodyStyle(); | ||
modalVisibleWatcher(computed(() => visible.value)); | ||
if (hideScroll) { | ||
modalVisibleWatcher(); | ||
} | ||
|
||
init(); | ||
|
||
return { | ||
visible, | ||
openModal, | ||
closeModal, | ||
toggleModal, | ||
modalVisibleWatcher | ||
toggleModal | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.