actionSheet.vue 2.8 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3
<template>
  <uni-actionsheet @touchmove.prevent>
    <transition name="uni-fade">
4 5 6
      <div
        v-show="visible"
        class="uni-mask"
fxy060608's avatar
fxy060608 已提交
7 8
        @click="_close(-1)"
      />
fxy060608's avatar
fxy060608 已提交
9
    </transition>
10 11
    <div
      :class="{'uni-actionsheet_toggle':visible}"
fxy060608's avatar
fxy060608 已提交
12 13
      class="uni-actionsheet"
    >
Q
qiang 已提交
14 15 16 17
      <div class="uni-actionsheet__menu">
        <div
          v-if="title"
          class="uni-actionsheet__title"
fxy060608's avatar
fxy060608 已提交
18 19 20
        >
          {{ title }}
        </div>
21
        <div
fxy060608's avatar
fxy060608 已提交
22
          v-for="(itemTitle,index) in itemList"
23 24 25
          :key="index"
          :style="{color:itemColor}"
          class="uni-actionsheet__cell"
fxy060608's avatar
fxy060608 已提交
26 27 28 29
          @click="_close(index)"
        >
          {{ itemTitle }}
        </div>
fxy060608's avatar
fxy060608 已提交
30 31
      </div>
      <div class="uni-actionsheet__action">
32 33 34
        <div
          :style="{color:itemColor}"
          class="uni-actionsheet__cell"
fxy060608's avatar
fxy060608 已提交
35 36 37 38
          @click="_close(-1)"
        >
          取消
        </div>
fxy060608's avatar
fxy060608 已提交
39 40 41 42 43 44 45
      </div>
    </div>
  </uni-actionsheet>
</template>
<script>
export default {
  name: 'ActionSheet',
Q
qiang 已提交
46 47 48 49
  props: {
    title: {
      type: String,
      default: ''
50
    },
fxy060608's avatar
fxy060608 已提交
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
    itemList: {
      type: Array,
      default () {
        return []
      }
    },
    itemColor: {
      type: String,
      default: '#000000'
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    _close (tapIndex) {
      this.$emit('close', tapIndex)
    }
  }
}
</script>
<style>
	uni-actionsheet {
		display: block;
		box-sizing: border-box;
	}

	uni-actionsheet .uni-actionsheet {
		position: fixed;
		left: 0;
		bottom: 0;
		transform: translate(0, 100%);
		backface-visibility: hidden;
		z-index: 999;
		width: 100%;
		background-color: #efeff4;
88
    visibility: hidden;
Q
qiang 已提交
89
		transition: transform 0.3s, visibility 0.3s;
fxy060608's avatar
fxy060608 已提交
90 91 92
	}

	uni-actionsheet .uni-actionsheet.uni-actionsheet_toggle {
93
    visibility: visible;
fxy060608's avatar
fxy060608 已提交
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
		transform: translate(0, 0);
	}

	uni-actionsheet .uni-actionsheet * {
		box-sizing: border-box;
	}

	uni-actionsheet .uni-actionsheet__menu {
		background-color: #fcfcfd;
	}

	uni-actionsheet .uni-actionsheet__action {
		margin-top: 6px;
		background-color: #fcfcfd;
	}

Q
qiang 已提交
110
	uni-actionsheet .uni-actionsheet__cell ,
111
	uni-actionsheet .uni-actionsheet__title {
fxy060608's avatar
fxy060608 已提交
112 113 114 115
		position: relative;
		padding: 10px 0;
		text-align: center;
		font-size: 18px;
Q
qiang 已提交
116
	}
fxy060608's avatar
fxy060608 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
	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);
	}

	uni-actionsheet .uni-actionsheet__cell:active {
		background-color: #ececec;
	}

	uni-actionsheet .uni-actionsheet__cell:first-child:before {
		display: none;
	}
137
</style>