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
<template>
    <view class="u-demo">
        <view class="u-demo-wrap">
            <view class="u-demo-title">演示效果</view>
            <view class="u-demo-area">
                <u-rate v-model="value" :count="count" @change="change"
                :active-color="activeColor" :inaction-color="inactiveColor"
                :active-icon="activeIcon" :inactive-icon="inactiveIcon"
                :disabled="disabled" :colors="colors" :icons="icons"></u-rate>
            </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 :list="[1, 2, 3, 4]" @change="currentChange"></u-subsection>
            </view>
            <view class="u-config-item">
                <view class="u-item-title">镂空状态</view>
                <u-subsection current="1" :list="['是', '否']" @change="plainChange"></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 class="u-config-item">
                <view class="u-item-title">自定义图标</view>
                <u-subsection current="1" :list="['是', '否']" @change="iconChange"></u-subsection>
            </view>
            <view class="u-config-item">
                <view class="u-item-title">是否分层</view>
                <u-subsection current="1" :list="['是', '否']" @change="decimalChange"></u-subsection>
            </view>
            <view class="u-config-item">
                <view class="u-item-title">是否禁用</view>
                <u-subsection current="1" :list="['是', '否']" @change="disabledChange"></u-subsection>
            </view>
            <view class="u-config-item">
                <view class="u-item-title">星星数量</view>
                <u-subsection current="1" :list="[4, 5, 6]" @change="countChange"></u-subsection>
            </view>
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                // 1.4.5后推荐使用v-model双向绑定,弃用current
                // current: 1,
                activeColor: '#FA3534',
                inactiveColor: '#b2b2b2',
                disabled: false,
                count: 5,
                customIcon: false,
                plain: false,
                value: 0,
                colors: [],
                icons: []
            }
        },
        watch: {
            value(n) {
                // console.log(n);
            }
        },
        computed: {
            activeIcon() {
                let icon = this.customIcon ? 'heart' : 'star';
                return this.plain ? icon : icon + '-fill'
            },
            inactiveIcon() {
                let icon = this.customIcon ? 'heart' : 'star';
                return this.plain ? icon : icon + '-fill'
            }
        },
        methods: {
            currentChange(index) {
                this.value = index == 0 ? 1 : index == 1 ? 2 : index == 2 ? 3 : 4;
            },
            plainChange(index) {
                this.plain = !index;
            },
            disabledChange(index) {
                this.disabled = index == 0 ? true : false;
            },
            countChange(index) {
                this.count = index == 0 ? 4 : index == 1 ? 5 : 6;
            },
            styleChange(index) {
                if(index == 0) {
                    this.activeColor = this.$u.color['primary'];
                    this.inactiveColor = this.$u.color['info'];
                } else {
                    this.activeColor = '#FA3534';
                    this.inactiveColor = '#b2b2b2';
                }
            },
            decimalChange(index) {
                if(index == 0) {
                    this.colors = ['#ffc454', '#ffb409', '#ff9500'];
                    this.icons = ['thumb-down-fill', 'thumb-down-fill', 'thumb-up-fill', 'thumb-up-fill'];
                } else {
                    this.colors = [];
                    this.icons = [];
                }
            },
            iconChange(index) {
                this.customIcon = !index;
            },
            change(val) {
                // console.log(val);
            }
        }
    }
</script>
 
<style scoped lang="scss">
    .u-demo {}
</style>