useLayout.uts 1.05 KB
/**
 * 布局 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'))
  }
}