invite.vue 1.5 KB
Newer Older
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
<template>
  <div class="invite-code">
    <img :src="imgSrc" alt="" class="imgCode" />
  </div>
</template>
<script>
import { inviteCode } from "@/api/invite";
var userId = "13933770749";
export default {
  data() {
    return {
      imgSrc: ""
    };
  },
  mounted() {
    this.inviteCode();
  },
  methods: {
    inviteCode() {
      const _this = this;
      let loading = _this.$toast.loading({
        forbidClick: true,
        message: "加载中..."
      });
      inviteCode(userId).then(res => {
        if (loading) _this.$toast.clear();
xulili's avatar
xulili committed
27
        _this.imgSrc = _this.getUserPhoto(res);
28 29
      });
    },
xulili's avatar
xulili committed
30 31 32 33 34 35 36 37 38 39 40 41
    getUserPhoto(res) {
      let uInt8Array = new Uint8Array(res);
      let len = uInt8Array.length;
      let binaryString = new Array(len);
      while (len--) {
        binaryString[len] = String.fromCharCode(uInt8Array[len]);
      }
      let data = window.btoa(binaryString.join(""));
      let imageType = "image/jpeg";
      let imageUrl = "data:" + imageType + ";base64," + data;
      return imageUrl;
    }
42 43 44 45 46
  }
};
</script>
<style scoped lang="scss">
.invite-code {
xulili's avatar
xulili committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60
  width: 100%;
  height: 100vh;
  background: url("../assets/images/invite.jpeg");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  .imgCode {
    position: absolute;
    width: 60px;
    height: 60px;
    right: 50px;
    bottom: 10px;
  }
  @media only screen and (device-width: 375px) and (-webkit-device-pixel-ratio: 3) {
    .imgCode {
61 62
      width: 60px;
      height: 60px;
xulili's avatar
xulili committed
63
      bottom: 20px;
64 65 66 67
    }
  }
}
</style>