index.vue 2.64 KB
Newer Older
Nature's avatar
Nature committed
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
<template>
  <transition :name="transition">
    <div v-show="show && !!content" :class="[c(),cusClass]">
      <div :class="c('wrap')">
        <div :class="c('img')">
          <img src="./warning@2x.png" style="width: 18px">
        </div>
        <div :class="c('content')">{{ content }}</div>
        <div :class="c('cross-area')" @click="close">
          <a :class="c('cross')" href="javascript:void(0)"/>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
import {base, prefix} from '../../common/mixins'

const directions = ['up', 'left', 'right', 'down']

export default {
  name: 'TopTip',
  mixins: [base, prefix],
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    content: {
      type: String,
      default: '',
    },
    entryDirection: {
      type: String,
      default: 'left',
    },
    cusClass: {
      type: String,
      default: '',
    },
  },
  data () {
    return {
      show: false,
    }
  },
  computed: {
    transition () {
      return directions.includes(this.entryDirection)
        ? this.b(`slide-in-${this.entryDirection}`)
        : this.b('slide-in-left')
    },
  },
  watch: {
    value (val) {
      this.show = val
    },
  },
  created () {
    if (this.value) {
      this.show = this.value
    }
  },
  methods: {
    close () {
      this.$emit('input', false)
    },
  },
}
</script>

<style lang="less">

  @topTipFontColor: #999;
  @topTipBackgroundColor: #fff8dc;
  @topTipCrossColor: #6d7a80;

  .crossLineRotate(@d) {
    width: 2px;
    height: 14px;
    display: block;
    transform: rotateZ(@d);
    background-color: @topTipCrossColor;
  }

  .hls-top-tip {
    text-align: center;

    &-wrap {
      position: relative;
      padding: 8px 32px 8px 15px;
      font-size: 14px;
      color: @topTipFontColor;
      background-color: @topTipBackgroundColor;
    }

    &-img{
      width: 13px;
      height: 100%;
      position: absolute;
      top: 0;
      display: -webkit-box;
      display: -webkit-flex;
      display: flex;
      -webkit-box-pack: center;
      -webkit-justify-content: center;
      justify-content: center;
      -webkit-box-align: center;
      -webkit-align-items: center;
      align-items: center;
    }

    &-content {
      word-break: break-word;
      margin-left: 26px;
      text-align: left;
    }

    &-cross-area {
      width: 32px;
      height: 100%;
      position: absolute;
      top: 0;
      right: 0;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    &-cross {
      .crossLineRotate(45deg);

      &:before {
        content: '';
        .crossLineRotate(-90deg);
      }
    }
  }
</style>