index.vue 2.96 KB
Newer Older
xd's avatar
xd committed
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
<template>
  <div class="qr-code">
    <img id="image" src alt />
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "index",
  data() {
    return {
      accessToken: "",
      nowUrl: "",
      activeId: "",
      voucherId: "",
      unionId: ""
    };
  },
  mounted() {
    // alert('--->arCode: mounted: IN.')
    this.cleanUrl()
    // this.getAcessToken();
    this.createCode();
  },
  methods: {
    cleanUrl() {
      // alert('--->arCode: cleanUrl: IN.')
      this.nowUrl = this.$route.query.Url
      this.activeId = this.$route.query.activeId
      this.voucherId = this.$route.query.voucherId
      this.unionId = this.$route.query.unionId
    },
    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();
      });
    },
    // 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);
    //     }
    //   });
    // },
    createCode() {
      let _this = this;
      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}`;
      $.ajax({
        type: "POST",
        url: pageUrl,
        // data: JSON.stringify({ path: "pages/signIn/signIn" }),
        data: {},
        success: function(res) {
          console.log(res)
          $('#image').attr('src',res.data)
        },
        error: function(data) {
          alert('error' + JSON.stringify(data))
          console.log(data);
        }
      });
    }
  }
};
</script>

<style scoped lang="scss">
.qr-code {
  text-align: center;
  padding-top: 50px;
  #image {
    display: inline-block;
    width: 60%;
  }
}
</style>