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
| <template>
| <view class="tn-landscape-class tn-landscape">
| <view v-if="showValue" class="tn-landscape__container" :style="[containerStyle]">
| <slot></slot>
| <view
| v-if="closeBtn"
| class="tn-landscape__icon tn-icon-close-fill"
| :class="[{
| 'tn-landscape__icon--left-top': closePosition === 'leftTop',
| 'tn-landscape__icon--right-top': closePosition === 'rightTop',
| 'tn-landscape__icon--bottom': closePosition === 'bottom'
| }]"
| :style="[closeBtnStyle]"
| @tap="close"
| ></view>
| </view>
| <view
| v-if="mask"
| class="tn-landscape__mask"
| :class="[{'tn-landscape__mask--show': showValue}]"
| :style="[maskStyle]"
| @tap="closeMask"
| ></view>
| </view>
| </template>
|
| <script>
| export default {
| name: 'tn-landscape',
| props: {
| // 显示
| show: {
| type: Boolean,
| default: false
| },
| // 显示关闭图标
| closeBtn: {
| type: Boolean,
| default: true
| },
| // 关闭图标颜色
| closeColor: {
| type: String,
| default: ''
| },
| // 关闭图标大小,单位rpx
| closeSize: {
| type: Number,
| default: 0
| },
| // 关闭图标位置
| // leftTop -> 左上角 rightTop -> 右上角 bottom -> 底部
| closePosition: {
| type: String,
| default: 'rightTop'
| },
| // 关闭图标top值,单位rpx
| // 当关闭图标在leftTop或者rightTop时生效
| closeTop: {
| type: Number,
| default: 0
| },
| // 关闭图标right值,单位rpx
| // 当关闭图标在RightTop时生效
| closeRight: {
| type: Number,
| default: 0
| },
| // 关闭图标bottom值,单位rpx
| // 当关闭图标在bottom时生效
| closeBottom: {
| type: Number,
| default: 0
| },
| // 关闭图标left值,单位rpx
| // 当关闭图标在leftTop时生效
| closeLeft: {
| type: Number,
| default: 0
| },
| // 显示遮罩
| mask: {
| type: Boolean,
| default: true
| },
| // 点击遮罩可以关闭
| maskCloseable: {
| type: Boolean,
| default: true
| },
| // zIndex
| zIndex: {
| type: Number,
| default: 0
| }
| },
| computed: {
| containerStyle() {
| let style = {}
| style.zIndex = this.zIndex ? this.zIndex : this.$t.zIndex.landsacpe
| return style
| },
| closeBtnStyle() {
| let style = {}
| if (this.closePosition === 'leftTop') {
| if (this.closeTop) {
| style.top = this.closeTop + 'rpx'
| }
| if (this.closeLeft) {
| style.left = this.closeLeft + 'rpx'
| }
| } else if (this.closePosition === 'rightTop') {
| if (this.closeTop) {
| style.top = this.closeTop + 'rpx'
| }
| if (this.closeRight) {
| style.right = this.closeRight + 'rpx'
| }
| } else if (this.closePosition === 'bottom') {
| if (this.closeBottom) {
| style.bottom = this.closeBottom + 'rpx'
| }
| }
| if (this.closeSize) {
| style.fontSize = this.closeSize + 'rpx'
| }
| if (this.closeColor) {
| style.color = this.closeColor
| }
| return style
| },
| maskStyle() {
| let style = {}
| style.zIndex = this.zIndex ? this.zIndex - 1 : this.$t.zIndex.landsacpe - 1
| return style
| }
| },
| watch: {
| show: {
| handler(val) {
| this.showValue = val
| },
| immediate: true
| }
| },
| data() {
| return {
| showValue: false
| }
| },
| methods: {
| // 关闭压屏窗
| close() {
| this.showValue = false
| this.$emit('close')
| },
| // 点击遮罩关闭
| closeMask() {
| if (!this.maskCloseable) return
| this.close()
| }
| }
| }
| </script>
|
| <style lang="scss" scoped>
| .tn-landscape {
| width: 100%;
| overflow: hidden;
|
| &__container {
| max-width: 100%;
| position: fixed;
| display: inline-flex;
| flex-direction: column;
| align-items: center;
| justify-content: center;
| left: 50%;
| top: 50%;
| transform: translate(-50%, -50%);
| }
|
| &__icon {
| position: absolute;
| text-align: center;
| font-size: 50rpx;
| color: #FFFFFF;
|
| &--left-top {
| top: -40rpx;
| left: 20rpx;
| }
|
| &--right-top {
| top: -40rpx;
| right: 40rpx;
| }
|
| &--bottom {
| left: 50%;
| bottom: -40rpx;
| transform: translateX(-50%);
| }
| }
|
| &__mask {
| position: fixed;
| width: 100%;
| height: 100%;
| background-color: $tn-mask-bg-color;
| top: 0;
| right: 0;
| bottom: 0;
| left: 0;
| opacity: 0;
| transform: scale3d(1, 1, 0);
| transition: all 0.25s ease-in;
|
| &--show {
| opacity: 1 !important;
| transform: scale3d(1, 1, 1);
| }
| }
| }
| </style>
|
|