|
15 | 15 | const ctl = controllerStore(); |
16 | 16 |
|
17 | 17 | const root = ref<HTMLElement | null>(null); |
18 | | - // const resizeObserver = ref<ResizeObserver | null>(null); |
| 18 | + const resizeObserver = ref<ResizeObserver | null>(null); |
19 | 19 |
|
20 | 20 | onMounted(() => { |
21 | | - // 判断设备类型(手机、平板、PC) |
22 | | - const userAgent = navigator.userAgent; |
23 | | - if (userAgent.match(/Android/i) || userAgent.match(/webOS/i) || userAgent.match(/iPhone/i) || userAgent.match(/iPad/i) || userAgent.match(/iPod/i) || userAgent.match(/BlackBerry/i) || userAgent.match(/Windows Phone/i)) { |
24 | | - // 移动端 |
25 | | - const htmlEl = document.documentElement; |
26 | | - htmlEl.style.setProperty('font-size', '12px'); |
27 | | - ctl.allowDrag = false; |
28 | | - ctl.articleFullscreen = true; |
29 | | - ctl.hideLeftSidebar = true; |
30 | | - ctl.hideRightSidebar = true; |
31 | | - ctl.hideActionBar = true; |
32 | | - ctl.hideHeaderTopNav = true; |
33 | | - ctl.hidePaths = true; |
34 | | - ctl.hideCopyright = true; |
35 | | - } else { |
36 | | - // PC端 |
37 | | - const htmlEl = document.documentElement; |
38 | | - htmlEl.style.setProperty('font-size', '16px'); |
39 | | - ctl.allowDrag = true; |
40 | | - ctl.articleFullscreen = false; |
41 | | - ctl.hideLeftSidebar = false; |
42 | | - ctl.hideRightSidebar = false; |
43 | | - ctl.hideActionBar = false; |
44 | | - ctl.hideHeaderTopNav = false; |
45 | | - ctl.hidePaths = false; |
46 | | - ctl.hideCopyright = false; |
47 | | - } |
48 | | -
|
49 | | - /* resizeObserver.value = new ResizeObserver((entries: ResizeObserverEntry[]) => { |
| 21 | + resizeObserver.value = new ResizeObserver((entries: ResizeObserverEntry[]) => { |
50 | 22 | const htmlEl = document.documentElement; |
51 | 23 | for (const entry of entries) { |
52 | 24 | const { target } = entry; |
53 | 25 | const { clientWidth } = target as HTMLElement; |
54 | | - if (clientWidth >= 2560) { |
55 | | - htmlEl.style.setProperty('font-size', '18px'); |
56 | | - ctl.allowDrag = true; |
57 | | - ctl.articleFullscreen = false; |
58 | | - ctl.hideLeftSidebar = false; |
59 | | - ctl.hideRightSidebar = false; |
60 | | - ctl.hideActionBar = false; |
61 | | - ctl.hideHeaderTopNav = false; |
62 | | - ctl.hidePaths = false; |
63 | | - ctl.hideCopyright = false; |
64 | | - } else if (clientWidth >= 1920) { |
65 | | - htmlEl.style.setProperty('font-size', '16px'); |
66 | | - ctl.allowDrag = true; |
67 | | - ctl.articleFullscreen = false; |
68 | | - ctl.hideLeftSidebar = false; |
69 | | - ctl.hideRightSidebar = false; |
70 | | - ctl.hideActionBar = false; |
71 | | - ctl.hideHeaderTopNav = false; |
72 | | - ctl.hidePaths = false; |
73 | | - ctl.hideCopyright = false; |
74 | | - } else if (clientWidth >= 1280) { |
75 | | - htmlEl.style.setProperty('font-size', '14px'); |
76 | | - ctl.allowDrag = false; |
77 | | - ctl.articleFullscreen = false; |
78 | | - ctl.hideLeftSidebar = false; |
79 | | - ctl.hideRightSidebar = false; |
80 | | - ctl.hideActionBar = false; |
81 | | - ctl.hideHeaderTopNav = false; |
82 | | - ctl.hidePaths = false; |
83 | | - ctl.hideCopyright = false; |
84 | | - } else { |
85 | | - htmlEl.style.setProperty('font-size', '12px'); |
86 | | - ctl.allowDrag = false; |
87 | | - ctl.articleFullscreen = true; |
88 | | - ctl.hideLeftSidebar = true; |
89 | | - ctl.hideRightSidebar = true; |
90 | | - ctl.hideActionBar = true; |
91 | | - ctl.hideHeaderTopNav = true; |
92 | | - ctl.hidePaths = true; |
93 | | - ctl.hideCopyright = true; |
94 | | - } |
| 26 | + setTimeout(() => { |
| 27 | + if (clientWidth >= 2560) { |
| 28 | + htmlEl.style.setProperty('font-size', '18px'); |
| 29 | + ctl.allowDrag = true; |
| 30 | + ctl.articleFullscreen = false; |
| 31 | + ctl.hideLeftSidebar = false; |
| 32 | + ctl.hideRightSidebar = false; |
| 33 | + ctl.hideActionBar = false; |
| 34 | + ctl.hideHeaderTopNav = false; |
| 35 | + ctl.hidePaths = false; |
| 36 | + ctl.hideCopyright = false; |
| 37 | + } else if (clientWidth >= 1920) { |
| 38 | + htmlEl.style.setProperty('font-size', '16px'); |
| 39 | + ctl.allowDrag = true; |
| 40 | + ctl.articleFullscreen = false; |
| 41 | + ctl.hideLeftSidebar = false; |
| 42 | + ctl.hideRightSidebar = false; |
| 43 | + ctl.hideActionBar = false; |
| 44 | + ctl.hideHeaderTopNav = false; |
| 45 | + ctl.hidePaths = false; |
| 46 | + ctl.hideCopyright = false; |
| 47 | + } else if (clientWidth >= 1280) { |
| 48 | + htmlEl.style.setProperty('font-size', '14px'); |
| 49 | + ctl.allowDrag = false; |
| 50 | + ctl.articleFullscreen = false; |
| 51 | + ctl.hideLeftSidebar = false; |
| 52 | + ctl.hideRightSidebar = false; |
| 53 | + ctl.hideActionBar = false; |
| 54 | + ctl.hideHeaderTopNav = false; |
| 55 | + ctl.hidePaths = false; |
| 56 | + ctl.hideCopyright = false; |
| 57 | + } else { |
| 58 | + htmlEl.style.setProperty('font-size', '12px'); |
| 59 | + ctl.allowDrag = false; |
| 60 | + ctl.articleFullscreen = true; |
| 61 | + ctl.hideLeftSidebar = true; |
| 62 | + ctl.hideRightSidebar = true; |
| 63 | + ctl.hideActionBar = true; |
| 64 | + ctl.hideHeaderTopNav = true; |
| 65 | + ctl.hidePaths = true; |
| 66 | + ctl.hideCopyright = true; |
| 67 | + } |
| 68 | + }, 100); |
95 | 69 | } |
96 | 70 | }); |
97 | | - resizeObserver.value.observe(root.value as HTMLElement); */ |
| 71 | + resizeObserver.value.observe(root.value as HTMLElement); |
98 | 72 | }); |
99 | 73 |
|
100 | 74 | onBeforeUnmount(() => { |
101 | | - // resizeObserver.value?.disconnect(); |
| 75 | + resizeObserver.value?.disconnect(); |
102 | 76 | }); |
103 | 77 | </script> |
104 | 78 |
|
|
0 commit comments