actionSheet.vue 3.9 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3
<template>
  <uni-actionsheet @touchmove.prevent>
    <transition name="uni-fade">
4 5
      <div
        v-show="visible"
6 7
        class="uni-mask uni-actionsheet__mask"
        @click="_close(-1)"
fxy060608's avatar
fxy060608 已提交
8
      />
fxy060608's avatar
fxy060608 已提交
9
    </transition>
10
    <div
11
      :class="{ 'uni-actionsheet_toggle': visible }"
12
      :style="popupStyle.content"
13 14
      class="uni-actionsheet"
    >
Q
qiang 已提交
15
      <div class="uni-actionsheet__menu">
16 17 18
        <div
          v-if="title"
          class="uni-actionsheet__title"
19 20
        >
          {{ title }}
fxy060608's avatar
fxy060608 已提交
21
        </div>
22
        <div
23
          v-for="(itemTitle, index) in itemList"
24
          :key="index"
25
          :style="{ color: itemColor }"
26
          class="uni-actionsheet__cell"
27 28 29
          @click="_close(index)"
        >
          {{ itemTitle }}
fxy060608's avatar
fxy060608 已提交
30
        </div>
fxy060608's avatar
fxy060608 已提交
31 32
      </div>
      <div class="uni-actionsheet__action">
33
        <div
34
          :style="{ color: itemColor }"
35
          class="uni-actionsheet__cell"
36 37 38
          @click="_close(-1)"
        >
          取消
fxy060608's avatar
fxy060608 已提交
39
        </div>
fxy060608's avatar
fxy060608 已提交
40
      </div>
41
      <div :style="popupStyle.triangle" />
fxy060608's avatar
fxy060608 已提交
42
    </div>
43 44 45
    <keypress
      :disable="!visible"
      @esc="_close(-1)"
46
    />
fxy060608's avatar
fxy060608 已提交
47 48 49
  </uni-actionsheet>
</template>
<script>
50
import popup from './mixins/popup'
51
import keypress from '../../../helpers/keypress'
52

fxy060608's avatar
fxy060608 已提交
53 54
export default {
  name: 'ActionSheet',
55
  components: { keypress },
56
  mixins: [popup],
Q
qiang 已提交
57 58 59 60
  props: {
    title: {
      type: String,
      default: ''
61
    },
fxy060608's avatar
fxy060608 已提交
62 63 64 65 66 67 68 69 70 71
    itemList: {
      type: Array,
      default () {
        return []
      }
    },
    itemColor: {
      type: String,
      default: '#000000'
    },
72 73 74 75
    popover: {
      type: Object,
      default: null
    },
fxy060608's avatar
fxy060608 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88
    visible: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    _close (tapIndex) {
      this.$emit('close', tapIndex)
    }
  }
}
</script>
<style>
89 90 91 92
uni-actionsheet {
  display: block;
  box-sizing: border-box;
}
fxy060608's avatar
fxy060608 已提交
93

94 95 96 97 98 99 100 101 102 103 104
uni-actionsheet .uni-actionsheet {
  position: fixed;
  left: 6px;
  right: 6px;
  bottom: 6px;
  transform: translate(0, 100%);
  backface-visibility: hidden;
  z-index: 999;
  visibility: hidden;
  transition: transform 0.3s, visibility 0.3s;
}
fxy060608's avatar
fxy060608 已提交
105

106 107 108 109
uni-actionsheet .uni-actionsheet.uni-actionsheet_toggle {
  visibility: visible;
  transform: translate(0, 0);
}
fxy060608's avatar
fxy060608 已提交
110

111 112 113
uni-actionsheet .uni-actionsheet * {
  box-sizing: border-box;
}
fxy060608's avatar
fxy060608 已提交
114

115 116 117 118 119
uni-actionsheet .uni-actionsheet__menu,
uni-actionsheet .uni-actionsheet__action {
  border-radius: 5px;
  background-color: #fcfcfd;
}
fxy060608's avatar
fxy060608 已提交
120

121 122 123 124 125 126 127 128 129 130 131 132
uni-actionsheet .uni-actionsheet__action {
  margin-top: 6px;
}

uni-actionsheet .uni-actionsheet__cell,
uni-actionsheet .uni-actionsheet__title {
  position: relative;
  padding: 10px 6px;
  text-align: center;
  font-size: 18px;
  text-overflow: ellipsis;
  overflow: hidden;
133
  cursor: pointer;
134
}
fxy060608's avatar
fxy060608 已提交
135

136 137 138 139 140 141 142 143 144 145 146 147
uni-actionsheet .uni-actionsheet__cell:before {
  content: " ";
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  height: 1px;
  border-top: 1px solid #e5e5e5;
  color: #e5e5e5;
  transform-origin: 0 0;
  transform: scaleY(0.5);
}
fxy060608's avatar
fxy060608 已提交
148

149 150 151 152 153 154 155
uni-actionsheet .uni-actionsheet__cell:active {
  background-color: #ececec;
}

uni-actionsheet .uni-actionsheet__cell:first-child:before {
  display: none;
}
fxy060608's avatar
fxy060608 已提交
156

157
@media screen and (min-width: 500px) and (min-height: 500px) {
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
  .uni-mask.uni-actionsheet__mask {
    background: none;
  }
  uni-actionsheet .uni-actionsheet {
    width: 300px;
    left: 50%;
    right: auto;
    top: 50%;
    bottom: auto;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.3s, visibility 0.3s;
  }
  uni-actionsheet .uni-actionsheet.uni-actionsheet_toggle {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
  uni-actionsheet .uni-actionsheet__menu {
    box-shadow: 0px 0 20px 5px rgba(0, 0, 0, 0.3);
  }
  uni-actionsheet .uni-actionsheet__action {
    display: none;
  }
}
182
</style>