index.uvue 2.7 KB
<template>
  <un-page class="layout-root" :style="styleObject">
		<slot></slot>
  </un-page>
</template>

<script setup lang="uts">
import { computed, onMounted, onUnmounted, type Ref, ref, provide } from 'vue'
// import { useLayout } from '@/composables/useLayout'
// import { cssClassRef, updateResolutionConfig, useResolutionConfig } from '@/services/adapter'
import { updateOrientation, useScreenVars } from '@/services/adapter/hooks/index.uts'
// import { layoutService } from '@/services/LayoutService.uts'
const props = defineProps<{
  pageVars?: UTSJSONObject | null
}>()

// 通过 provide 注入 pageVars,供子组件使用
provide('PAGE_VARS', props.pageVars ?? null)
// const layout = useLayout()
// const rawCssVars = (layout as UTSJSONObject)['cssVars'] as Ref<UTSJSONObject> | null
// onResize(() => {
// console.log('layout-------onResize',1112321321321321)
//   updateOrientation()
// })
// const styleObj = computed((): UTSJSONObject => {
//   const r = rawCssVars
//   if (r == null) return {}
//   const v = r.value
//   return v != null ? v : {}
// })

// // useResolutionConfig()
// const LAYOUT_ROOT_POLL_MS = 350
// let layoutRootPollId: number | null = null
// let lastLayoutW = 0
// let lastLayoutH = 0

// function syncLayoutRootResolution(): void {
//   const info = uni.getWindowInfo()
//   let w = info.windowWidth
//   let h = info.windowHeight
//   if (w == 0 && info.screenWidth > 0) {
//     w = info.screenWidth
//     if (info.screenHeight > 0) {
//       h = info.screenHeight
//     }
//   }
//   if (w == 0 || h == 0) {
//     return
//   }
//   if (w == lastLayoutW && h == lastLayoutH) {
//     return
//   }
//   lastLayoutW = w
//   lastLayoutH = h
//   layoutService.refreshScreenInfo()
//   updateResolutionConfig()
// }
const styleObject = useScreenVars(props.pageVars ?? null)
// screenVarsHook 已经是 ComputedRef<UTSJSONObject>,直接使用,无需再包 computed
// const adapterClass = computed((): string => {
//   const cls = cssClassRef.value
//   return cls != null ? (cls as string) : ''
// })

// const modeClass = computed((): string => {
//   const modeRef = layoutService.getCurrentMode()
//   const m = modeRef.value
//   return m == 'portrait' ? 'mode-portrait' : 'mode-landscape'
// })

// const resolutionClass = computed((): string => {
//   const bucket = layoutService.getResolutionBucket()
//   return `res-${bucket}`
// })

onMounted(() => {
	// 无需在此调用 updateOrientation,useScreenVars 已处理
});

onUnmounted(() => {
//   const tid = layoutRootPollId
//   if (tid != null) {
//     clearInterval(tid)
//     layoutRootPollId = null
//   }
})
</script>

<style>
.layout-root {
  width: 100%;
  height: 100%;
  padding: 0;
  padding-top: var(--status-bar-height);
}
</style>