-
zhangwei
2025-01-23 e5a77d6a551d13e4cf74624b31b0fa3e328b304d
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
<template>
    <!--本文件由FirstUI授权予四川政采招投标咨询有限公司(会员ID:16  3,营业执照号: 9151 0   1  3 13 320   0  61 93  K)专用,请尊重知识产权,勿私下传播,违者追究法律责任。-->
    <view class="fui-rotate__verify-wrap" :class="{'fui-rv__wrap-show':isShow}"
        :style="{background:maskBgColor,zIndex:zIndex}" @tap="maskClose" @touchmove.stop.prevent="stop"
        v-if="isShow || !isNvue" ref="fui_rv_ani">
        <view class="fui-rotate__verify" :style="{width:width+'rpx',background:background}" @tap.stop="stop">
            <view class="fui-rv__close" @tap.stop="closeVerify">
                <fui-icon name="close" :color="closeColor"></fui-icon>
            </view>
            <text class="fui-rv__title" :style="{ color: color, fontSize: size + 'rpx' }">{{ title }}</text>
            <text class="fui-rv__descr" :style="{ color: descrColor, fontSize: descrSize + 'rpx' }">拖动滑块,使图片角度为正</text>
            <view class="fui-rv__image-box"
                :style="{ width: imgW + 'px', height: imgW + 'px',borderRadius:isNvue?(imgW+'px'):'50%' }">
                <!-- #ifdef APP-PLUS || MP-WEIXIN || H5 -->
                <image class="fui-rv__image" :src="src"
                    :style="{ width: imgW + 'px', height: imgW + 'px',borderRadius:isNvue?(imgW+'px'):'50%' }"
                    ref="imgRef">
                </image>
                <!-- #endif -->
 
                <!-- #ifndef APP-PLUS || MP-WEIXIN || H5 -->
                <image class="fui-rv__image" :class="{'fui-rv__rest-ani':resetAni}" :src="src"
                    :style="{ width: imgW + 'px', height: imgW + 'px',borderRadius:isNvue?(imgW+'px'):'50%',transform:'rotate('+angle+'deg)' }">
                </image>
                <!-- #endif -->
                <view class="fui-rv__result" v-if="showRes || isPass"
                    :style="{ width: imgW + 'px', height:imgW + 'px',borderRadius:isNvue?(imgW+'px'):'50%' }">
                    <fui-icon :name="isPass?'check':'close'" :size="96" :color="getColor"></fui-icon>
                </view>
            </view>
            <!-- #ifdef APP-VUE || MP-WEIXIN || H5 -->
            <view class="fui-rv__slidebar"
                :style="{width: sliderWidth+'px',height: sliderHeight + 'px', borderColor: borderColor,borderRadius:sliderHeight+'px'}">
                <view class="fui-rv__slider"
                    :style="{ width: sliderHeight + 'px', height: (sliderHeight-2) + 'px', background: sliderBgColor,borderColor: borderColor,borderRadius:isNvue?sliderHeight+'px':'50%'}"
                    :change:prop="parse.slidereset" :prop="resetNum" :data-width="sliderWidth"
                    :data-swidth="sliderHeight" :data-app="isApp" :data-disabled="isPass || disabled || !isShow?1:0"
                    @touchstart="parse.touchstart" @touchmove="parse.touchmove" @touchend="parse.touchend"
                    @mousedown="parse.mousedown">
                    <fui-icon name="slide" :size="60" :color="slideColor"></fui-icon>
                </view>
            </view>
            <!-- #endif -->
 
            <!-- #ifdef APP-NVUE -->
            <view class="fui-rv__slidebar"
                :style="{width: sliderWidth+'px',height: sliderHeight + 'px', borderColor: borderColor,borderRadius:sliderHeight+'px'}">
                <view class="fui-rv__slider"
                    :style="{ width: sliderHeight + 'px', height: (sliderHeight-2) + 'px', background: sliderBgColor,borderColor: borderColor,borderRadius:isNvue?sliderHeight+'px':'50%'}"
                    @touchstart="touchstart" @horizontalpan="touchmove" @touchend="touchend" ref="sliderRef">
                    <fui-icon name="slide" :size="60" :color="slideColor"></fui-icon>
                </view>
            </view>
            <!-- #endif -->
 
            <!-- #ifndef APP-PLUS  || MP-WEIXIN  || H5-->
            <view class="fui-rv__slidebar"
                :style="{width: sliderWidth+'px',height: sliderHeight + 'px', borderColor: borderColor,borderRadius:sliderHeight+'px'}">
                <view class="fui-rv__slider" :class="{'fui-rv__rest-ani':resetAni}"
                    :style="{ width: sliderHeight + 'px', height: (sliderHeight-2) + 'px', background: sliderBgColor,borderColor: borderColor,borderRadius:isNvue?sliderHeight+'px':'50%',transform:transform}"
                    @touchstart="touchstart" @touchmove.stop.prevent="touchmove" @touchend="touchend">
                    <fui-icon name="slide" :size="60" :color="slideColor"></fui-icon>
                </view>
            </view>
            <!-- #endif -->
        </view>
    </view>
</template>
<!-- #ifdef APP-VUE  || MP-WEIXIN  || H5-->
<script src="./index.wxs" module="parse" lang="wxs"></script>
<!-- #endif -->
<script>
    import weex from './weex.js'
    import mpjs from './mpjs.js'
    //非easycom模式取消注释引入字体组件,按实际路径进行调整
    // import fuiIcon from "@/components/firstui/fui-icon/fui-icon.vue"
    export default {
        name: "fui-rotate-verify",
        mixins: [mpjs, weex],
        emits: ['verify'],
        // components:{
        //     fuiIcon
        // },
        props: {
            //验证弹层外层盒子宽度 rpx
            width: {
                type: [Number, String],
                default: 600
            },
            background: {
                type: String,
                default: '#FFFFFF'
            },
            title: {
                type: String,
                default: '安全验证'
            },
            color: {
                type: String,
                default: '#B2B2B2'
            },
            size: {
                type: [Number, String],
                default: 28
            },
            descrColor: {
                type: String,
                default: '#333333'
            },
            descrSize: {
                type: [Number, String],
                default: 32
            },
            //图片地址(旋转了初始角度后的图片),必传
            //旋转角度建议区间为 -330deg<angle <-30deg 或 30deg<angle<330deg
            src: {
                type: String,
                default: ''
            },
            //图片宽度,单位rpx。默认为正方形图片
            imgWidth: {
                type: [Number, String],
                default: 240
            },
            //滑动条和滑块边框颜色
            borderColor: {
                type: String,
                default: '#EEEEEE'
            },
            sliderBgColor: {
                type: String,
                default: '#FFFFFF'
            },
            closeColor: {
                type: String,
                default: '#B2B2B2'
            },
            slideColor: {
                type: String,
                default: '#333333'
            },
            passColor: {
                type: String,
                default: ''
            },
            failColor: {
                type: String,
                default: ''
            },
            zIndex: {
                type: [Number, String],
                default: 996
            },
            maskBgColor: {
                type: String,
                default: 'rgba(0,0,0,.6)'
            },
            //点击遮罩 是否可关闭
            maskClosable: {
                type: Boolean,
                default: false
            }
        },
        watch: {
            imgWidth(val) {
                this.imgW = this.getPx(val)
            },
            width(val) {
                this.sliderWidth = this.getPx((Number(val) - 64))
            }
        },
        computed: {
            getColor() {
                const app = uni && uni.$fui && uni.$fui.color;
                let passColor = this.passColor || (app && app.success) || '#09BE4F'
                let failColor = this.failColor || (app && app.danger) || '#FF2B2B'
                return this.isPass ? passColor : failColor
            }
        },
        data() {
            let isNvue = false
            let isApp = 0
            // #ifdef APP-NVUE
            isNvue = true
            // #endif
 
            // #ifdef APP
            isApp = 1;
            // #endif
            return {
                isApp,
                isNvue,
                isShow: false,
                isPass: false,
                disabled: false,
                showRes: false,
                sliderHeight: 0,
                imgW: 0,
                sliderWidth: 0,
                resetNum: 0
            };
        },
        created() {
            this.sliderWidth = this.getPx((Number(this.width) - 64))
            this.sliderHeight = this.getPx(92)
            this.imgW = this.getPx(this.imgWidth)
        },
        methods: {
            getPx(value) {
                let val = parseInt(uni.upx2px(Number(value)))
                return val % 2 === 0 ? val : val + 1
            },
            success() {
                this.isPass = true;
            },
            fail() {
                this.showRes = true;
                this.isPass = false;
                setTimeout(() => {
                    this.reset()
                }, 300)
            },
            verify(e) {
                //Math.abs(angle + initAngle - 360) <= range || Math.abs(angle + initAngle) <= range
                //验证中禁止操作
                this.disabled = true
                this.$emit('verify', e)
            },
            /*
             验证结果,前端验证时使用
            @param {Number} angle 旋转角度
            @param {Number} initAngle 初始化时旋转角度
            @param {Number} range 可误差角度范围
            @param {function} callback 回调函数 返回参数=>是否通过验证(bool)
            */
            verifyRes(angle, initAngle, range, callback) {
                let res = false
                if (Math.abs(angle + initAngle - 360) <= range || Math.abs(angle + initAngle) <= range) {
                    res = true
                }
                callback && callback(res)
            },
            maskClose() {
                if (!this.maskClosable) return;
                this.closeVerify()
            },
            closeVerify() {
                this.reset();
                // #ifndef APP-NVUE
                this.isShow = false;
                // #endif
 
                // #ifdef APP-NVUE
                this.closeAni()
                // #endif
            },
            show() {
                // #ifndef APP-NVUE
                this.isShow = true;
                // #endif
 
                // #ifdef APP-NVUE
                this.openAni()
                // #endif
            },
            reset() {
                this.resetNum += 1
                this.isPass = false;
                this.disabled = false;
                this.showRes = false
            },
            stop() {}
        }
    }
</script>
 
<style scoped>
    .fui-rotate__verify-wrap {
        position: fixed;
        top: 0;
        right: 0;
        left: 0;
        bottom: 0;
        /* #ifndef APP-NVUE */
        transition-property: all;
        transition-timing-function: ease-in;
        transition-duration: 0.2s;
        display: flex;
        transform: scale3d(1, 1, 0);
        visibility: hidden;
        /* #endif */
        align-items: center;
        justify-content: center;
        opacity: 0;
    }
 
    /* #ifndef APP-NVUE */
    .fui-rv__wrap-show {
        opacity: 1;
        transform: scale3d(1, 1, 1);
        visibility: visible;
    }
 
    /* #endif */
 
    .fui-rotate__verify {
        padding: 60rpx 32rpx;
        text-align: center;
        border-radius: 24rpx;
        overflow: hidden;
        position: relative;
        /* #ifndef APP-NVUE */
        display: flex;
        box-sizing: border-box;
        /* #endif */
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }
 
    .fui-rv__close {
        position: absolute;
        padding: 16rpx 16rpx 0 0;
        right: 12rpx;
        top: 12rpx;
        /* #ifdef H5 */
        cursor: pointer;
        /* #endif */
    }
 
    .fui-rv__title {
        text-align: center;
        padding-top: 30rpx;
        font-weight: normal;
    }
 
    .fui-rv__descr {
        text-align: center;
        padding-top: 20rpx;
        font-weight: normal;
    }
 
    .fui-rv__image-box {
        position: relative;
        margin-top: 48rpx;
        margin-bottom: 64rpx;
        background: #F1F4FA;
    }
 
    /* #ifndef APP-NVUE */
    .fui-rv__image {
        border-radius: 50%;
        display: block;
        /* #ifndef APP-PLUS || MP-WEIXIN || H5 */
        position: absolute;
        left: 0;
        top: 0;
        /* #endif */
    }
 
    /* #endif */
 
    /* #ifndef APP-NVUE */
    .fui-rv__rest-ani {
        transition: transform 0.2s;
    }
 
    /* #endif */
 
    /* fix:vue3下动画问题,app端直接移除class效果未消失,导致卡顿 */
 
    /* #ifdef VUE3 */
    .fui-rv__un-ani {
        transition: transform 0s;
    }
 
    /* #endif */
 
    .fui-rv__result {
        position: absolute;
        z-index: 2;
        left: 0;
        top: 0;
        /* #ifndef APP-NVUE */
        display: flex;
        /* #endif */
        align-items: center;
        justify-content: center;
        background: rgba(0, 0, 0, 0.6);
    }
 
    .fui-rv__slidebar {
        /* #ifndef APP-NVUE */
        box-sizing: border-box;
        /* #endif */
        position: relative;
        border-width: 1px;
        border-style: solid;
    }
 
    .fui-rv__slider {
        /* #ifndef APP-NVUE */
        display: flex;
        box-sizing: border-box;
        /* #endif */
        align-items: center;
        justify-content: center;
        position: absolute;
        left: 0;
        top: 0;
        border-width: 1px;
        border-style: solid;
        /* #ifdef H5 */
        cursor: pointer;
        /* #endif */
    }
</style>