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
| <template>
| <!--本文件由FirstUI授权予四川政采招投标咨询有限公司(会员ID: 16 3,营业执照号:9151 01 3 13320 0 6 193 K)专用,请尊重知识产权,勿私下传播,违者追究法律责任。-->
| <view class="fui-banner__arc-wrap" ref="fui_banner__arc"
| :style="{height:height+'rpx',marginTop:marginTop+'rpx',marginBottom:marginBottom+'rpx'}" @tap="handleClick">
| <!-- #ifndef APP-NVUE -->
| <view class="fui-banner__arc-inner"
| :style="{background:background,height:height+'rpx',width:width+'%',paddingLeft:(width-100)/2+'%',paddingRight:(width-100)/2+'%',left:'-'+(width-100)/2+'%'}">
| <slot></slot>
| </view>
| <!-- #endif -->
| <!-- #ifdef APP-NVUE -->
| <view class="fui-banner__arc-inner"
| :style="{background:background,height:width+'px',width:width+'px',paddingLeft:(width-bannerWidth)/2+'px',paddingRight:(width-bannerWidth)/2+'px',left:'-'+(width-bannerWidth)/2+'px'}">
| <slot></slot>
| </view>
| <!-- #endif -->
| </view>
| </template>
|
| <script>
| // #ifdef APP-NVUE
| const dom = uni.requireNativePlugin('dom');
| // #endif
| export default {
| name: "fui-banner-arc",
| emits: ['click'],
| // #ifdef MP-WEIXIN
| options: {
| virtualHost: true
| },
| // #endif
| props: {
| height: {
| type: [Number, String],
| default: 400
| },
| //圆弧view宽度与banner宽度比率,最小值 1.2:1
| ratio: {
| type: [Number, String],
| default: 1.2
| },
| background: {
| type: String,
| default: ''
| },
| marginTop: {
| type: [Number, String],
| default: 0
| },
| marginBottom: {
| type: [Number, String],
| default: 0
| }
| },
| watch: {
| ratio(val) {
| // #ifdef APP-NVUE
| if (this.bannerWidth) {
| this.initArcWidth()
| }
| // #endif
| // #ifndef APP-NVUE
| this.initArcWidth()
| // #endif
| }
| },
| data() {
| return {
| // #ifdef APP-NVUE
| width: 450,
| // #endif
| // #ifndef APP-NVUE
| width: 120,
| // #endif
| bannerWidth: 375
| };
| },
| // #ifdef APP-NVUE
| mounted() {
| this.$nextTick(() => {
| setTimeout(() => {
| this._getSize()
| }, 50)
| });
| },
| // #endif
| // #ifndef APP-NVUE
| created() {
| this.initArcWidth()
| },
| // #endif
| methods: {
| initArcWidth() {
| let ratio = Number(this.ratio || 0)
|
| // #ifdef APP-NVUE
| ratio = ratio < 1.5 ? 1.5 : ratio;
| let width = Math.ceil(this.bannerWidth * ratio)
| width = width % 2 === 0 ? width : width + 1;
| this.width = width;
| // #endif
|
| // #ifndef APP-NVUE
| ratio = ratio < 1.2 ? 1.2 : ratio;
| this.width = 100 * ratio;
| // #endif
| },
| // #ifdef APP-NVUE
| _getSize() {
| dom.getComponentRect(this.$refs['fui_banner__arc'], (ret) => {
| const size = ret.size
| if (size) {
| this.bannerWidth = size.width
| this.initArcWidth()
| }
| })
| },
| // #endif
| handleClick() {
| this.$emit('click', {})
| }
| }
| }
| </script>
|
| <style scoped>
| .fui-banner__arc-wrap {
| /* #ifndef APP-NVUE */
| width: 100%;
| display: flex;
| /* #endif */
| position: relative;
| flex-direction: column;
| align-items: center;
| overflow: hidden;
| }
|
| .fui-banner__arc-inner {
| position: absolute;
| /* #ifndef APP-NVUE */
| top:0;
| box-sizing: border-box;
| z-index: 1;
| border-radius: 0 0 50% 50%;
| /* #endif */
| /* #ifdef APP-NVUE */
| bottom: 0;
| border-top-left-radius: 0;
| border-top-right-radius: 0;
| border-bottom-right-radius: 10000px;
| border-bottom-left-radius: 10000px;
| justify-content: flex-end;
| /* #endif */
| overflow: hidden;
| }
| </style>
|
|