useLayout.uts
1.05 KB
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
39
/**
* 布局 Composable
* 提供 CSS 变量、缩放方法、模式判断
*/
import { computed } from 'vue'
import { layoutService } from '@/services/LayoutService'
import type { LayoutMode } from '@/config/layout.config.uts'
export function useLayout() {
const cssVars = computed((): UTSJSONObject => {
return layoutService.getCSSVariables()
})
return {
// CSS 变量(用于根元素 :style="cssVars")
cssVars,
// 当前模式
currentMode: layoutService.getCurrentMode(),
// 缩放比例
scaleRatio: layoutService.getScaleRatio(),
// 屏幕信息
screenInfo: layoutService.getScreenInfo(),
// 按设计稿尺寸缩放
scaleSize: (n: number): number => layoutService.scaleSize(n),
// 判断模式
isMode: (mode: LayoutMode): boolean => layoutService.isMode(mode),
// 便捷判断
isPad: computed((): boolean => layoutService.isMode('pad')),
isPortrait: computed((): boolean => layoutService.isMode('portrait')),
isDesktop: computed((): boolean => layoutService.isMode('desktop'))
}
}