-
zhangwei
2024-08-22 d5eb1ecff5d0236359c744b334cf30fcfdad1132
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
<template>
    <!--本文件由FirstUI授权予四川政采招投标咨询有限公司(会员ID: 1 63,营业执照号:9 1   5101      31  33200 6   19 3K)专用,请尊重知识产权,勿私下传播,违者追究法律责任。-->
    <view class="fui-safe__area-wrap" :class="{'fui-safe__area-weex':iphonex}" :style="{background:background}"></view>
</template>
 
<script>
    export default {
        name: "fui-safe-area",
        props: {
            //背景颜色
            background: {
                type: String,
                default: '#FFFFFF'
            }
        },
        created() {
            // #ifdef APP-NVUE || MP-TOUTIAO
            this.iphonex = this.isPhoneX();
            // #endif
        },
        data() {
            return {
                iphonex: false
            };
        },
        methods: {
            // #ifdef APP-NVUE || MP-TOUTIAO
            isPhoneX() {
                //34px
                const res = uni.getSystemInfoSync();
                let iphonex = false;
                let models = ['iphonex', 'iphonexr', 'iphonexsmax']
                for (let i = 11; i < 21; i++) {
                    models.push(`iphone${i}`)
                    models.push(`iphone${i}mini`)
                    models.push(`iphone${i}pro`)
                    models.push(`iphone${i}promax`)
                }
                const model = res.model.replace(/\s/g, "").toLowerCase()
                const newModel = model.split('<')[0]
                if (models.includes(model) || models.includes(newModel) || (res.safeAreaInsets && res.safeAreaInsets
                        .bottom > 0)) {
                    iphonex = true;
                }
                return iphonex;
            }
            // #endif
        }
    }
</script>
 
<style scoped>
    .fui-safe__area-wrap {
        /* #ifndef APP-NVUE */
        width: 100%;
        display: flex;
        /* #endif */
 
        /* #ifndef APP-NVUE || MP-TOUTIAO */
        padding-bottom: constant(safe-area-inset-bottom);
        padding-bottom: env(safe-area-inset-bottom);
        /* #endif */
        flex: 1;
        flex-direction: row;
    }
 
    /* #ifdef APP-NVUE || MP-TOUTIAO */
    .fui-safe__area-weex {
        padding-bottom: 34px;
    }
 
    /* #endif */
</style>