index.vue 2.96 KB
Newer Older
xulili's avatar
xulili committed
1
<template>
2 3 4
  <div class="qr-code">
    <img id="image" src alt />
  </div>
xulili's avatar
xulili committed
5 6 7
</template>

<script>
8 9 10 11 12 13 14 15 16 17 18 19 20
import axios from "axios";
export default {
  name: "index",
  data() {
    return {
      accessToken: "",
      nowUrl: "",
      activeId: "",
      voucherId: "",
      unionId: ""
    };
  },
  mounted() {
21
    // alert('--->arCode: mounted: IN.')
22
    this.cleanUrl()
xulili's avatar
xulili committed
23
    // this.getAcessToken();
xd's avatar
xd committed
24
    this.createCode()
25 26 27
  },
  methods: {
    cleanUrl() {
28
      // alert('--->arCode: cleanUrl: IN.')
xulili's avatar
xulili committed
29 30 31 32
      this.nowUrl = this.$route.query.Url
      this.activeId = this.$route.query.activeId
      this.voucherId = this.$route.query.voucherId
      this.unionId = this.$route.query.unionId
xulili's avatar
xulili committed
33
    },
34 35 36 37 38 39 40 41 42
    getAcessToken() {
      let _this = this;
      axios({
        url: "http://139.155.48.151:8085/workWx/auth/oauth2/getAccessToken",
        method: "get"
      }).then(res => {
        _this.accessToken = res.data.data;
        _this.createCode();
      });
xulili's avatar
xulili committed
43
    },
xulili's avatar
xulili committed
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
    // createCode() {
    //   let _this = this;
    //   let pageUrl = `/wxx/cgi-bin/wxaapp/createwxaqrcode?access_token=${_this.accessToken}`;
    //   $.ajax({
    //     type: "POST",
    //     url: pageUrl,
    //     data: JSON.stringify({ path: "pages/signIn/signIn" }),
    //     // data: JSON.stringify({ path: `${_this.nowUrl}&detailid=${_this.voucherId}&actionid=${_this.activeId}&unionid=${_this.unionId}` }),
    //     xhrFields: { responseType: "arraybuffer" },
    //     success: function(res) {
    //       alert('success' + JSON.stringify(res))
    //       let imgUrl =
    //         "data:image/png;base64," +
    //         btoa(
    //           new Uint8Array(res).reduce(
    //             (data, byte) => data + String.fromCharCode(byte),
    //             ""
    //           )
    //         );
    //       $("#image").attr("src", imgUrl);
    //     },
    //     error: function(data) {
    //       alert('error' + JSON.stringify(data))
    //       console.log(data);
    //     }
    //   });
    // },
71
    createCode() {
72
      let _this = this;
xulili's avatar
xulili committed
73 74 75 76 77 78
      let nowUrl = _this.nowUrl? _this.nowUrl : ""
      let voucherId = _this.voucherId? _this.voucherId : ""
      let activeId = _this.activeId? _this.activeId : ""
      let unionId = _this.unionId? _this.unionId : ""
      let pageUri = `${nowUrl}&detailid=${voucherId}&actionid=${activeId}&unionid=${unionId}`;
      let pageUrl = `http://139.155.48.151:8085/workWx/auth/oauth2/wxMiniQrCode?pageUri=${pageUri}`;
79 80 81
      $.ajax({
        type: "POST",
        url: pageUrl,
82
        // data: JSON.stringify({ path: "pages/signIn/signIn" }),
xulili's avatar
xulili committed
83
        data: {},
84
        success: function(res) {
xulili's avatar
xulili committed
85 86
          console.log(res)
          $('#image').attr('src',res.data)
87 88
        },
        error: function(data) {
xulili's avatar
xulili committed
89
          alert('error' + JSON.stringify(data))
90 91 92
          console.log(data);
        }
      });
xulili's avatar
xulili committed
93 94
    }
  }
95
};
xulili's avatar
xulili committed
96 97 98
</script>

<style scoped lang="scss">
99 100 101 102 103 104 105 106
.qr-code {
  text-align: center;
  padding-top: 50px;
  #image {
    display: inline-block;
    width: 60%;
  }
}
xulili's avatar
xulili committed
107
</style>