modal.vue 3.8 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2
<template>
  <transition name="uni-fade">
3 4
    <uni-modal
      v-show="visible"
fxy060608's avatar
fxy060608 已提交
5
      @touchmove.prevent>
fxy060608's avatar
fxy060608 已提交
6
      <div class="uni-mask"/>
fxy060608's avatar
fxy060608 已提交
7
      <div class="uni-modal">
8 9
        <div
          v-if="title"
fxy060608's avatar
fxy060608 已提交
10 11 12
          class="uni-modal__hd">
          <strong class="uni-modal__title">{{ title }}</strong>
        </div>
13 14
        <div
          class="uni-modal__bd"
15
          @touchmove.stop>{{ content }}</div>
fxy060608's avatar
fxy060608 已提交
16
        <div class="uni-modal__ft">
17 18 19 20
          <div
            v-if="showCancel"
            :style="{color:cancelColor}"
            class="uni-modal__btn uni-modal__btn_default"
fxy060608's avatar
fxy060608 已提交
21
            @click="_close('cancel')">{{ cancelText }}</div>
22 23 24
          <div
            :style="{color:confirmColor}"
            class="uni-modal__btn uni-modal__btn_primary"
fxy060608's avatar
fxy060608 已提交
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
            @click="_close('confirm')">{{ confirmText }}</div>
        </div>
      </div>
    </uni-modal>
  </transition>
</template>
<script>
import transition from './mixins/transition'
export default {
  name: 'Modal',
  mixins: [transition],
  props: {
    title: {
      type: String,
      default: ''
    },
    content: {
      type: String,
      default: ''
    },
    showCancel: {
      type: Boolean,
      default: true
    },
    cancelText: {
      type: String,
      default: '取消'
    },
    cancelColor: {
      type: String,
      default: '#000000'
    },
    confirmText: {
      type: String,
      default: '确定'
    },
    confirmColor: {
      type: String,
      default: '#007aff'
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    _close (type) {
      this.$emit('close', type)
    }
  }
}
</script>
<style>
	uni-modal {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		z-index: 999;
		display: block;
		box-sizing: border-box;
	}

	uni-modal .uni-modal {
		position: fixed;
		z-index: 999;
		width: 80%;
		max-width: 300px;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		background-color: #ffffff;
		text-align: center;
		border-radius: 3px;
		overflow: hidden;
	}

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

	uni-modal .uni-modal__hd {
108
		padding: 1em 1.6em 0.3em;
fxy060608's avatar
fxy060608 已提交
109 110 111 112 113
	}

	uni-modal .uni-modal__title {
		font-weight: 400;
		font-size: 18px;
114 115
		word-wrap:break-word;
		word-break:break-all;
116
		white-space: pre-wrap;
117 118 119 120 121
		overflow : hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
fxy060608's avatar
fxy060608 已提交
122 123 124 125 126 127 128 129 130
	}

	uni-modal .uni-modal__bd {
		padding: 1.3em 1.6em 1.3em;
		min-height: 40px;
		font-size: 15px;
		line-height: 1.4;
		word-wrap: break-word;
		word-break: break-all;
131
		white-space: pre-wrap;
fxy060608's avatar
fxy060608 已提交
132
		color: #999999;
133 134
		max-height: 400px;
		overflow-y: auto;
fxy060608's avatar
fxy060608 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
	}

	uni-modal .uni-modal__ft {
		position: relative;
		line-height: 48px;
		font-size: 18px;
		display: flex;
	}

	uni-modal .uni-modal__ft:after {
		content: " ";
		position: absolute;
		left: 0;
		top: 0;
		right: 0;
		height: 1px;
		border-top: 1px solid #d5d5d6;
		color: #d5d5d6;
		transform-origin: 0 0;
		transform: scaleY(0.5);
	}

	uni-modal .uni-modal__btn {
		display: block;
		flex: 1;
		color: #3cc51f;
		text-decoration: none;
		-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
		position: relative;
	}

	uni-modal .uni-modal__btn:active {
		background-color: #eeeeee;
	}

	uni-modal .uni-modal__btn:after {
		content: " ";
		position: absolute;
		left: 0;
		top: 0;
		width: 1px;
		bottom: 0;
		border-left: 1px solid #d5d5d6;
		color: #d5d5d6;
		transform-origin: 0 0;
		transform: scaleX(0.5);
	}

	uni-modal .uni-modal__btn:first-child:after {
		display: none;
	}

	uni-modal .uni-modal__btn_default {
		color: #353535;
	}

	uni-modal .uni-modal__btn_primary {
		color: #007aff;
	}
194
</style>