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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
| <template>
| <view class="cl-footer__wrap">
| <view
| class="cl-footer__placeholder"
| :style="{ height, padding: parseRpx(padding) }"
| v-if="fixed && visible"
| ></view>
|
| <view
| class="cl-footer"
| :class="{
| 'is-border': border,
| 'is-fixed': fixed,
| }"
| :style="{
| backgroundColor,
| backdropFilter,
| visibility: visible ? 'visible' : 'hidden',
| bottom: parseRpx(bottom),
| zIndex,
| }"
| >
| <view
| class="cl-footer__wrap"
| :style="{
| padding: parseRpx(padding),
| }"
| >
| <view
| class="cl-footer__inner"
| :class="{
| 'is-flex': flex,
| }"
| >
| <slot> </slot>
| </view>
| </view>
| </view>
| </view>
| </template>
|
| <script lang="ts">
| import {
| computed,
| defineComponent,
| getCurrentInstance,
| nextTick,
| onMounted,
| ref,
| watch,
| } from "vue";
| import { parseRpx, sleep } from "/@/cool/utils";
|
| export default defineComponent({
| name: "cl-footer",
|
| props: {
| // 背景色
| backgroundColor: {
| type: String,
| default: "#fff",
| },
| // 背景模糊
| backdropFilter: String,
| // 內间距
| padding: {
| type: [String, Number],
| default: "24rpx 36rpx",
| },
| // 固定高
| height: [String, Number],
| // 层级
| zIndex: {
| type: Number,
| default: 99,
| },
| // 距离底部多少
| bottom: {
| type: [String, Number],
| default: 0,
| },
| // 是否带上边框
| border: Boolean,
| // 是否固定底部定位
| fixed: {
| type: Boolean,
| default: true,
| },
| // 是否 flex 布局
| flex: {
| type: Boolean,
| default: true,
| },
| // 延迟获取
| delay: {
| type: Number,
| default: 0,
| },
| // 监听对象
| vt: null,
| },
|
| setup(props) {
| const instance = getCurrentInstance();
|
| // 底部高度
| const height = ref();
|
| // 是否可见
| const visible = computed(() => {
| return parseInt(height.value) != 0;
| });
|
| // 重新计算
| async function update() {
| if (props.height) {
| height.value = parseRpx(props.height);
| return false;
| }
|
| await sleep(props.delay);
| await nextTick();
|
| uni.createSelectorQuery()
| .in(instance?.proxy)
| .select(".cl-footer__inner")
| .boundingClientRect((rect) => {
| if (rect) {
| height.value = Math.floor(rect.height || 0) + "px";
| }
| })
| .exec();
| }
|
| watch(
| () => props.vt,
| () => {
| update();
| },
| {
| deep: true,
| },
| );
|
| onMounted(() => {
| update();
| });
|
| return {
| height,
| visible,
| update,
| parseRpx,
| };
| },
| });
| </script>
|
|