<template>
  <div class="intro brightness" v-clickoutside="handleoutside">
    <div v-if="!istips">
      <p>分享链接给好友</p>
      <div class="link" v-html="url"></div>
      <div class="btn">
        <span
          @click.stop="$emit('close')"
        >
          取消
        </span>
        <span ref="btn" class="submit" :data-clipboard-text="url">
          一键复制
        </span>
      </div>
      <img
        class="close"
        @click.stop="$emit('close')"
        :src="require('@/assets/images/close.png')"
      />
    </div>

    <transition name="fade">
      <div class="tips" v-if="istips">
        场景链接复制成功
      </div>
    </transition>
  </div>
</template>

<script>
export default {
  methods: {
    handleoutside() {
      this.$emit("close");
    },
  },
  mounted() {
    let copy = new window.ClipboardJS(this.$refs.btn);
    copy.on("success", (e) => {
      this.istips = true
      setTimeout(() => {
        this.istips = false
        this.$emit('close')
      }, 3000);
      e.clearSelection();
    });
    copy.on("error", (err) => console.log(err));
  },
  data() {
    return {
      url: window.location.href.replace('http://','https://'),
      istips:false
    };
  }
};
</script>

<style lang="less" scoped>
@bx: 0 3px 6px rgba(0, 0, 0, 1);
@bc: rgba(12, 91, 246, 0.8);
@animation: 0.3s ease all;
.intro {
  text-align: center;
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  > div {
    padding: 20px;
    width: 30%;
    transform: translate(-50%, -50%);
    top: 50%;
    left: 50%;
    position: fixed;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 10px;
    box-sizing: content-box;

    > p {
      text-align: left;
    }
    .link {
      color: #fff;
      text-align: center;
      padding: 30px 20px;
      word-wrap: break-word;
      width: 80%;
      margin: 20px auto;
      background-color: rgba(0, 0, 0, 0.35);
    }

    .btn{
      width: 100%;
      display: flex;
      justify-content: space-around;
      align-items: center;
      margin-bottom: 20px;
      >span{
        color: #fff;
        border: 1px solid #ccc;
        background-color: transparent;
        border-radius: 30px;
        width: 200px;
        height: 40px;
        line-height: 40px;
        cursor: pointer;
      }

      .submit{
        background-color: @color;
        border: 1px solid  @color;
      }

    }

    .close {
      position: absolute;
      bottom: -18px;
      width: 36px;
      padding: 8px;
      left: 50%;
      transform: translateX(-50%);
      border-radius: 30px;
      box-shadow: @bx;
      background-color: @bc;
    }
  }

  .tips{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    width: 20%;
    padding: 20px 10px;
    z-index: 99999;
  }
}
</style>
