image-check.js
2.44 KB
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
import udid from '../../common/udid';
import config from '../../common/config';
import { isNeedImgCheck } from '../../common/login';
Component({
properties: {
refresh: {
type: Boolean,
observer: 'refresh'
}
},
/**
* 组件的初始数据
*/
data: {
imageSrc: '',
degrees: [0, 0, 0, 0],
imageClass: [0, 0, 0, 0],
isNeedImgCheck: false
},
attached: function() {
this.setData({
imageSrc: this.getVerifyImage()
});
this.refresh();
},
/**
* 组件的方法列表
*/
methods: {
/**
* 获取图片
*/
getVerifyImage: function() {
let timestamp = Date.parse(new Date());
let url = `${config.domains.api}/passport/img-check?business_line=${config.business_line}&app_version=0.0.1&udid=${udid.get()}&client_type=${config.apiParams.client_type}&fromPage=${config.apiParams.client_type}&t=${timestamp}`; // eslint-disable-line
return url;
},
/**
* 更新组件状态,是否需要图片验证码
*/
refresh: function() {
isNeedImgCheck().then(result => {
if (result.code === 200 && result.data) {
this.setData({
isNeedImgCheck: true
});
} else {
this.setData({
isNeedImgCheck: false
});
}
this.triggerEvent('isNeedImgCheck', {
isNeedImgCheck: this.data.isNeedImgCheck
});
});
},
/**
* 换一批
*/
refreshImage: function() {
this.setData({
imageSrc: this.getVerifyImage()
});
},
/**
* 改变图片的方向
*/
changeDirection: function(event) {
let indexNum = event.currentTarget.id.replace('image-', '');
let degrees = this.data.degrees;
let imageClass = this.data.imageClass;
degrees[indexNum] = (degrees[indexNum] + 1) % 4;
imageClass[indexNum] = (imageClass[indexNum] + 140) % 560;
this.setData({
degrees: degrees,
imageClass: imageClass
});
this.triggerEvent('refreshCode', {
degrees: this.data.degrees
});
}
}
});