zhangxiaoxu123456
2021-12-17 4d4a844ef624dde8667b314d353599297f6cb8d9
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
<template>
    <view class="u-demo">
        <view class="u-demo-wrap">
            <view class="u-demo-title">演示效果</view>
            <view class="u-demo-area">
                <u-toast ref="uToast"></u-toast>
                <view class="container u-skeleton">
                    <view class="userinfo">
                        <block>
                            <!--u-skeleton-circle 绘制圆形-->
                            <image class="userinfo-avatar u-skeleton-circle" :src="userInfo.avatarUrl"></image>
                            <!--u-skeleton-fillet 绘制圆角矩形-->
                            <text class="u-skeleton-fillet">{{userInfo.nickName}}</text>
                        </block>
                    </view>
                    <view style="margin: 20px 0">
                        <!--u-skeleton-rect 绘制矩形-->
                        <view class="u-skeleton-rect lists" v-for="(item,index) in lists" :key="index">
                            <text>{{item}}</text>
                        </view>
                    </view>
                </view>
                <!--引用组件-->
                <u-skeleton bg-color="rgb(250, 250, 250)" :loading="loading" :animation="animation" 
                :el-color="elColor" :border-radius="borderRadius"></u-skeleton>
            </view>
        </view>
        <view class="u-config-wrap">
            <view class="u-config-title u-border-bottom">
                参数配置
            </view>
            <view class="u-config-item">
                <view class="u-item-title">加载状态</view>
                <u-subsection :current="current" :list="['请求中', '请求结束']" @change="loadingChange"></u-subsection>
            </view>
            <view class="u-config-item">
                <view class="u-item-title">骨架动画</view>
                <u-subsection current="1" :list="['是', '否']" @change="animationChange"></u-subsection>
            </view>
            <view class="u-config-item">
                <view class="u-item-title">自定义样式</view>
                <u-subsection current="1" :list="['是', '否']" @change="styleChange"></u-subsection>
            </view>
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                userInfo: {
                    avatarUrl: 'https://cdn.uviewui.com/uview/common/logo.png',
                    nickName: 'uView'
                },
                lists: [
                    '君不见,黄河之水天上来,奔流到海不复回。君不见,高堂明镜悲白发,朝如青丝暮成雪。',
                    '人生得意须尽欢,莫使金樽空对月',
                    '天生我材必有用,千金散尽还复来',
                ],
                loading: true, // 是否显示骨架屏组件
                animation: false,
                elColor: '#e5e5e5',
                borderRadius: 10,
            }
        },
        computed: {
            current() {
                return this.loading ? 0 : 1;
            },
        },
        onLoad() {
            this.getData();
        },
        methods: {
            animationChange(index) {
                this.animation = index == 0 ? true : false;
                this.getData();
            },
            loadingChange(index) {
                this.loading = index == 0 ? true : false;
                if(index == 0) this.getData();
            },
            styleChange(index) {
                if(index == 0) {
                    this.elColor = this.$u.color['primary'];
                    this.borderRadius = 14;
                } else {
                    this.elColor = '#e5e5e5';
                    this.borderRadius = 10;
                }
                this.getData();
            },
            getData() {
                this.loading = true;
                // 通过延时模拟向后端请求数据,调隐藏骨架屏
                setTimeout(() => {
                    this.loading = false;
                }, 3000)
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .container {
        text-align: left;
        font-size: 28rpx;
        color: $u-content-color;
    }
 
    .userinfo {
        display: flex;
        flex-direction: column;
        align-items: center;
    }
 
    .userinfo-avatar {
        width: 128rpx;
        height: 128rpx;
        margin: 20rpx;
        border-radius: 50%;
    }
 
    .lists {
        margin: 10px 0;
    }
</style>