invite.vue 2 KB
Newer Older
1 2
<template>
  <div class="invite-code">
全球's avatar
全球 committed
3 4
    <div class="nav">
      <van-icon
leiqingsong's avatar
leiqingsong committed
5 6 7 8
        name="arrow-left"
        size="20"
        class="nav-left"
        color="#ffffff"
leiqingsong's avatar
leiqingsong committed
9
        @click="handlerBack"
全球's avatar
全球 committed
10 11 12
      />
      <img :src="imgSrc" alt="" class="imgCode" />
    </div>
13 14 15 16 17
  </div>
</template>
<script>
import { inviteCode } from "@/api/invite";
export default {
leiqingsong's avatar
leiqingsong committed
18
  name: "Invite",
19 20 21 22 23 24 25 26 27
  data() {
    return {
      imgSrc: ""
    };
  },
  mounted() {
    this.inviteCode();
  },
  methods: {
leiqingsong's avatar
leiqingsong committed
28 29 30 31 32 33 34 35
    handlerBack() {
      try {
        this.$bridgeToAppFun.navigateBack();
      } catch {
        console.log("不能和App交互");
        this.$router.go(-1);
      }
    },
36 37 38 39 40 41
    inviteCode() {
      const _this = this;
      let loading = _this.$toast.loading({
        forbidClick: true,
        message: "加载中..."
      });
leiqingsong's avatar
leiqingsong committed
42 43
      const userId = JSON.parse(localStorage.getItem("user")).userId;
      inviteCode(userId).then(res => {
44
        if (loading) _this.$toast.clear();
xulili's avatar
xulili committed
45
        _this.imgSrc = _this.getUserPhoto(res);
46 47
      });
    },
xulili's avatar
xulili committed
48 49 50 51 52 53 54 55
    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(""));
56
      let imageType = "image/png";
xulili's avatar
xulili committed
57 58 59
      let imageUrl = "data:" + imageType + ";base64," + data;
      return imageUrl;
    }
60 61 62 63 64
  }
};
</script>
<style scoped lang="scss">
.invite-code {
xulili's avatar
xulili committed
65 66
  width: 100%;
  height: 100vh;
leiqingsong's avatar
leiqingsong committed
67
  background: url("../assets/images/invite_1.png");
xulili's avatar
xulili committed
68 69 70 71 72 73 74 75 76 77 78
  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 {
79 80
      width: 60px;
      height: 60px;
xulili's avatar
xulili committed
81
      bottom: 20px;
82 83
    }
  }
leiqingsong's avatar
leiqingsong committed
84 85 86 87 88
  @media screen and (min-device-width: 768px) {
    .imgCode {
      bottom: 1%;
    }
  }
89 90
}
</style>