zhangxiaoxu123456
2021-12-20 301289e539c417995f95f5cb91fd1f6043bb7cfd
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<template>
    <view class="">
        <u-navbar title-color="#fff" back-icon-color="#ffffff" 
            :is-fixed="isFixed" :is-back="isBack" 
            :background="background" 
            :back-text-style="{color: '#fff'}" :title="title" 
            :back-icon-name="backIconName" :back-text="backText"
        >
            <view class="slot-wrap" v-if="useSlot">
                <view class="search-wrap" v-if="search">
                    <!-- 如果使用u-search组件,必须要给v-model绑定一个变量 -->
                    <u-search v-model="keyword" :show-action="showAction" height="56" :action-style="{color: '#fff'}"></u-search>
                </view>
                <view class="navbar-right" v-if="rightSlot">
                    <view class="message-box right-item">
                        <u-icon name="chat" size="38"></u-icon>
                        <u-badge count="18" size="mini" :offset="[-15, -15]"></u-badge>
                    </view>
                    <view class="dot-box right-item">
                        <u-icon name="calendar-fill" size="38"></u-icon>
                        <u-badge size="mini" :is-dot="true" :offset="[-6, -6]"></u-badge>
                    </view>
                </view>
                <view class="map-wrap" v-if="custom">
                    <u-icon name="map" color="#ffffff" size="24"></u-icon>
                    <text class="map-wrap-text">轻舟已过万重山</text>
                    <u-icon name="arrow-down-fill" color="#ffffff" size="22"></u-icon>
                </view>
            </view>
            <view class="navbar-right" slot="right" v-if="slotRight">
                <view class="message-box right-item">
                    <u-icon name="chat" size="38"></u-icon>
                    <u-badge count="18" size="mini" :offset="[-15, -15]"></u-badge>
                </view>
                <view class="dot-box right-item">
                    <u-icon name="calendar-fill" size="38"></u-icon>
                    <u-badge size="mini" :is-dot="true" :offset="[-6, -6]"></u-badge>
                </view>
            </view>
        </u-navbar>
        <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="u-no-demo-here">查看顶部导航栏效果</view>
                </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="['短', '中', '长']" @change="titleChange"></u-subsection>
                </view>
                <view class="u-config-item">
                    <view class="u-item-title">隐藏左侧返回区域</view>
                    <u-subsection current="1" :list="['是', '否']" @change="backChange"></u-subsection>
                </view>
                <view class="u-config-item">
                    <view class="u-item-title">自定义左侧内容</view>
                    <u-subsection current="1" :list="['是', '否']" @change="leftChange"></u-subsection>
                </view>
                <view class="u-config-item">
                    <view class="u-item-title">自定义右侧内容</view>
                    <u-subsection :current="slotRightCurrent" :list="['是', '否']" @change="rightChange"></u-subsection>
                </view>
                <view class="u-config-item">
                    <view class="u-item-title">传入整体slot</view>
                    <u-subsection :list="['无', '搜索框', '搜索+按钮', '搜索+图标']" @change="searchChange"></u-subsection>
                </view>
                <view class="u-config-item">
                    <view class="u-item-title">完全自定义传入内容</view>
                    <u-subsection current="1" :list="['是', '否']" @change="customChange"></u-subsection>
                </view>
                <view class="u-config-item">
                    <view class="u-item-title">背景色</view>
                    <u-subsection :list="['渐变', '#39CCCC', '#B471CC', '#001f3f']" @change="bgColorChange"></u-subsection>
                </view>
            </view>
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                title: '新闻',
                backText: '返回',
                backIconName: 'nav-back',
                right: false,
                showAction: false,
                rightSlot: false,
                useSlot: false,
                background: {
                    'background-image': 'linear-gradient(45deg, rgb(28, 187, 180), rgb(141, 198, 63))'
                },
                isBack: true,
                search: false,
                custom: false,
                isFixed: true,
                keyword: '',
                // #ifdef MP
                slotRight: false,
                // #endif
                // #ifndef MP
                slotRight: true
                // #endif
            }
        },
        computed: {
            slotRightCurrent() {
                return this.slotRight ? 0 : 1;
            }
        },
        methods: {
            titleChange(index) {
                this.useSlot = false;
                this.title = index == 0 ? '新闻' : index == 1 ? '新闻列表' : '雨打梨花深闭门,忘了青春,误了青春';
            },
            leftChange(index) {
                if(index == 0) {
                    this.backText = '';
                    this.backIconName = 'arrow-leftward';
                } else {
                    this.backText = '返回';
                    this.backIconName = 'arrow-left';
                }
            },
            searchChange(index) {
                this.title = null;
                this.useSlot = true;
                this.search = false;
                this.custom = false;
                if(index == 0) {
                    this.title = '新闻';
                    this.useSlot = false;
                    this.rightSlot = false;
                } else if(index == 1) {
                    this.showAction = false;
                    this.useSlot = true;
                    this.rightSlot = false;
                    this.search = true;
                    this.slotRight = false;
                } else if(index == 2) {
                    this.useSlot = true;
                    this.showAction = true;
                    this.rightSlot = false;
                    this.search = true;
                    this.slotRight = false;
                } else {
                    this.useSlot = true;
                    this.search = true;
                    this.showAction = false;
                    this.rightSlot = true;
                    this.slotRight = false;
                }
            },
            backChange(index) {
                this.isBack = !!index;
            },
            bgColorChange(index) {
                this.background = {};
                if(index == 0) {
                    this.background = {
                        'background-image': 'linear-gradient(45deg, rgb(28, 187, 180), rgb(141, 198, 63))'
                    }
                } else {
                    let color = index == 1 ? '#39CCCC' : index == 2 ? '#B471CC' : '#001f3f';
                    this.background = {
                        background: color
                    }
                }
                
            },
            rightChange(index) {
                if(index == 0) {
                    this.slotRight = true;
                    this.useSlot = false;
                } else {
                    this.slotRight = false;
                }
            },
            customChange(index) {
                this.search = false;
                this.rightSlot = false;
                if(index == 0) {
                    this.custom = true;
                    this.title = null;
                    this.isBack = false;
                    this.useSlot = true;
                } else {
                    this.useSlot = false;
                    this.title = '新闻';
                    this.isBack = true;
                }
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .u-demo {
        //height: 200vh;
        height: calc(100% - 44px);
        height: calc(100% - 44px - constant(safe-area-inset-top));
        height: calc(100% - 44px - env(safe-area-inset-top));
    }
    
    .wrap {
        padding: 24rpx;
    }
    
    .navbar-right {
        margin-right: 24rpx;
        display: flex;
    }
    
    .search-wrap {
        margin: 0 20rpx;
        flex: 1;
    }
    
    .right-item {
        margin: 0 12rpx;
        position: relative;
        color: #ffffff;
        display: flex;
    }
    
    .message-box {
        
    }
    
    .slot-wrap {
        display: flex;
        align-items: center;
        flex: 1;
    }
    
    .map-wrap {
        display: flex;
        align-items: center;
        padding: 4px 6px;
        background-color: rgba(240,240, 240, 0.35);
        color: #fff;
        font-size: 22rpx;
        border-radius: 100rpx;
        margin-left: 30rpx;
    }
    
    .map-wrap-text {
        padding: 0 6rpx;
    }
</style>