Blame view

app/components/image-check/image-check.js 1.47 KB
htoooth authored
1 2 3 4
import udid from '../../common/udid';
import config from '../../common/config';

Component({
邱骏 authored
5
  /**
htoooth authored
6 7
     * 组件的初始数据
     */
邱骏 authored
8 9 10 11 12 13 14 15 16 17 18 19 20
  data: {
    imageSrc: '',
    degrees: [0, 0, 0, 0],
    imageClass: [0, 0, 0, 0]
  },

  attached: function() {
    this.setData({
      imageSrc: this.getVerifyImage()
    });
  },

  /**
htoooth authored
21 22
     * 组件的方法列表
     */
邱骏 authored
23 24
  methods: {
    /**
htoooth authored
25 26
         * 获取图片
         */
邱骏 authored
27 28
    getVerifyImage: function() {
      let timestamp = Date.parse(new Date());
htoooth authored
29 30
            let url = `${config.domains.api}/passport/img-check?business_line=${config.apiParams.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
邱骏 authored
31 32
      return url;
    },
htoooth authored
33
邱骏 authored
34
    /**
htoooth authored
35 36
         * 更新图片
         */
邱骏 authored
37 38 39 40 41
    refreshImage: function() {
      this.setData({
        imageSrc: this.getVerifyImage()
      });
    },
htoooth authored
42
邱骏 authored
43
    /**
htoooth authored
44 45
         * 改变图片的方向
         */
邱骏 authored
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    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
      });
htoooth authored
61
    }
邱骏 authored
62
  }
htoooth authored
63
});