DialogBox.vue 4.21 KB
<template>
  <div class="mask" v-if="isShowDialog">
    <div class="dialog-wrap">
      <div class="close" @click="closeHandle">
        <img src="@/assets/images/icon-close.png" />
      </div>
      <div class="dialog">
        <div :class="['dialog-content', modeName]" :style="{ 'background-image': `url(${backgroundImageList[currentIndex]})` }">
          <div class="dialog-title">
            {{ titleList[currentIndex] }}
          </div>
        </div>
      </div>
      <div class="left_arrow">
        <div class="arrow_inner" @click="changeHandle(-1)">
          <img src="@/assets/images/arrow_left.png" class="img" />
          <img src="@/assets/images/arrow_circle.png" class="circle" />
        </div>
      </div>

      <div class="right_arrow">
        <div class="arrow_inner" @click="changeHandle(1)">
          <img src="@/assets/images/arrow_right.png" class="img" />
          <img src="@/assets/images/arrow_circle.png" class="circle" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'MyDialog',
  props: {
    isShowDialog: Boolean,
    titleList: {
      type: Array,
      default: () => []
    },
    currentIndex: {
      type: Number,
      default: 0
    },
    backgroundImageList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      modeName: ''
    }
  },
  methods: {
    closeHandle() {
      this.$emit('update:isShowDialog', false)
    },
    changeHandle(val) {
      let { currentIndex, backgroundImageList } = this
      if (currentIndex == 0 && val == -1) {
        currentIndex = 4
      }
      if (currentIndex == backgroundImageList.length - 1 && val == 1) {
        currentIndex = -1
      }
      this.modeName = val == -1 ? 'to-left' : 'to-right'
      this.$emit('update:currentIndex', currentIndex + val)
      setTimeout(() => {
        this.modeName = ''
      }, 300)
    }
  }
}
</script>

<style lang="scss" scoped>
.mask {
  position: fixed;
  z-index: 99;
  left: 50%;
  top: 50%;
  background: rgba(0, 0, 0, 0.8);
  animation: show-mask 0.2s forwards;
  transform: translate(-50%, -50%);
}
@keyframes show-mask {
  0% {
    width: 0;
    height: 0;
    opacity: 0;
  }
  100% {
    width: 100%;
    height: 100%;
    opacity: 1;
  }
}
.dialog-wrap {
  width: 67.31%;
  height: 90.38%;
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  .close {
    width: 60px;
    height: 60px;
    position: absolute;
    right: -103px;
    top: 0.96vh;
    cursor: pointer;
    z-index: 3;
  }
  .dialog {
    width: 100%;
    height: 100%;
    overflow: hidden;
    &-content {
      width: 100%;
      height: 100%;
      background-repeat: no-repeat;
      background-size: 100% 100%;
    }
    .dialog-title {
      width: 13.19vw;
      font-weight: 900;
      font-size: 30px;
      color: #19ecff;
      text-align: center;
      margin: 0 auto;
      position: relative;
      line-height: 8.39vh;
    }
  }
  .to-left {
    animation: to-left 0.25s forwards;
  }
  .to-right {
    animation: to-right 0.25s forwards;
  }
  @keyframes to-left {
    0% {
      transform: translateX(-100%);
    }
    100% {
      transform: translateX(0);
    }
  }
  @keyframes to-right {
    0% {
      transform: translateX(100%);
    }
    100% {
      transform: translateX(0);
    }
  }
}
.left_arrow,
.right_arrow {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 2;
  width: 100px;
  .arrow_inner {
    position: absolute;
    width: 100px;
    height: 50vh;
    top: 50%;
    transform: translateY(-50%);
    z-index: 99;
    cursor: pointer;
  }
  .img {
    width: 48px;
    height: 48px;
    cursor: pointer;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
  }
  .circle {
    width: 84px;
    height: 84px;
    position: absolute;
    top: 50%;
    // transform: translateY(-50%);
    margin-top: -42px;
    z-index: 98;
  }
}
.left_arrow {
  left: -162px;
  .img {
    left: 18px;
  }
  .circle {
    left: 0;
  }
}
.right_arrow {
  right: -162px;
  .img {
    right: 18px;
  }
  .circle {
    right: 0;
  }
}
.left_arrow:hover,
.right_arrow:hover {
  .circle {
    animation: rotate360 1.2s ease-out 0s;
  }
}

@keyframes rotate360 {
  100% {
    transform: rotate(360deg);
  }
}
</style>