index.uvue
2.7 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<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>