|
1 | | -export const useStyleStore = defineStore('style', () => { |
| 1 | +export const useStyleStore = defineStore("style", () => { |
2 | 2 | const color = reactive({ |
3 | 3 | green: "green", red: "red", grey: "grey", |
4 | 4 | topButton: "white", orange: "orange", orange_light: "orange", |
5 | 5 | }); |
6 | 6 | const viewportHeight = ref(800); |
| 7 | + const topbarHeight = ref(800); |
| 8 | + const restHeight = computed(() => viewportHeight.value - topbarHeight.value); |
7 | 9 |
|
8 | 10 | onMounted(() => { |
9 | | - // 获取元素的计算后的样式 |
| 11 | + // Get styles after computation. |
10 | 12 | const styles = window.getComputedStyle(document.documentElement); |
11 | 13 |
|
12 | | - // 获取CSS变量的值 |
13 | | - color.green = styles.getPropertyValue('--p-emerald-500').trim(); |
14 | | - color.red = styles.getPropertyValue('--p-red-500').trim(); |
15 | | - color.grey = styles.getPropertyValue('--p-gray-400').trim(); |
16 | | - color.topButton = styles.getPropertyValue('--p-button-primary-background').trim(); |
17 | | - color.orange_light = styles.getPropertyValue('--p-orange-400').trim(); |
18 | | - color.orange = styles.getPropertyValue('--p-orange-500').trim(); |
| 14 | + // Set color shortcuts. |
| 15 | + color.green = styles.getPropertyValue("--p-emerald-500").trim(); |
| 16 | + color.red = styles.getPropertyValue("--p-red-500").trim(); |
| 17 | + color.grey = styles.getPropertyValue("--p-gray-400").trim(); |
| 18 | + color.topButton = styles.getPropertyValue("--p-button-primary-background").trim(); |
| 19 | + color.orange_light = styles.getPropertyValue("--p-orange-400").trim(); |
| 20 | + color.orange = styles.getPropertyValue("--p-orange-500").trim(); |
19 | 21 |
|
20 | | - // 视窗高度 |
| 22 | + // Get heights |
21 | 23 | viewportHeight.value = window.innerHeight; |
22 | | - window.addEventListener('resize', () => { |
| 24 | + topbarHeight.value = document.getElementById("topbar")?.offsetHeight ?? 800; |
| 25 | + window.addEventListener("resize", () => { |
23 | 26 | viewportHeight.value = window.innerHeight; |
| 27 | + topbarHeight.value = document.getElementById("topbar")?.offsetHeight ?? 800; |
24 | 28 | }); |
| 29 | + |
25 | 30 | }); |
26 | 31 |
|
27 | | - return { color, viewportHeight } |
| 32 | + return { color, viewportHeight, topbarHeight, restHeight } |
28 | 33 | }); |
29 | 34 |
|
0 commit comments