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

  .van-button {
    position: absolute;
    left: 50%;
    bottom: 100px;
    transform: translateX(-50%);
    width: 160px;
    height: 36px;
    font-size: 18px;
    color: #ffffff;
    background-color: #88c678;
    border: none;
    border-radius: 4px;
  }

xulili's avatar
xulili committed
95 96 97 98 99 100 101 102 103
  .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 {
104 105
      width: 60px;
      height: 60px;
xulili's avatar
xulili committed
106
      bottom: 20px;
107 108
    }
  }
leiqingsong's avatar
leiqingsong committed
109 110 111 112 113
  @media screen and (min-device-width: 768px) {
    .imgCode {
      bottom: 1%;
    }
  }
114 115
}
</style>