|
| 1 | +<template> |
| 2 | + <span> |
| 3 | + <transition :name="messageBoxTransition" @after-enter="onShow()" @after-leave="onHide()"> |
| 4 | + <div class="wd-messagebox" ref="popup" v-if="open" :style="{'z-index': zIndex}"> |
| 5 | + <div class="wd-messagebox-content"> |
| 6 | + <header v-if="title">{{ title }}</header> |
| 7 | + <p class="wd-messagebox-content-text">{{ text }}</p> |
| 8 | + <input class="wd-messagebox-content-input" v-if="isShowInput" v-model="inputValue" ref="input"></input> |
| 9 | + </div> |
| 10 | + <footer :class="{'wd-messagebox-footer-row': !isColumnButton, 'wd-messagebox-footer-column': isColumnButton}"> |
| 11 | + <span @click="onCancel" v-if="isShowCancelButton">{{ cancelText }}</span> |
| 12 | + <span @click="confirmHandler" :class="{disabled: isConfirmDisabled}">{{ confirmText }}</span> |
| 13 | + </footer> |
| 14 | + </div> |
| 15 | + </transition> |
| 16 | + </span> |
| 17 | +</template> |
| 18 | + |
| 19 | +<script> |
| 20 | +
|
| 21 | +import Popup from '../../util/popup/index.js' |
| 22 | +
|
| 23 | +export default { |
| 24 | + name: 'MessageBox', |
| 25 | + mixins: [Popup], |
| 26 | + props: { |
| 27 | + transition: { |
| 28 | + type: String, |
| 29 | + default: 'fade' |
| 30 | + }, |
| 31 | + title: { |
| 32 | + type: [String, Number], |
| 33 | + default: '' |
| 34 | + }, |
| 35 | + text: { |
| 36 | + type: [String, Number], |
| 37 | + default: '' |
| 38 | + }, |
| 39 | + type: { |
| 40 | + type: [String], |
| 41 | + default: 'alert' |
| 42 | + }, |
| 43 | + isShowInput: { |
| 44 | + type: Boolean, |
| 45 | + default: false |
| 46 | + }, |
| 47 | + isShowCancelButton: { |
| 48 | + type: Boolean, |
| 49 | + default: false |
| 50 | + }, |
| 51 | + isColumnButton: { |
| 52 | + type: Boolean, |
| 53 | + default: false |
| 54 | + }, |
| 55 | + inputType: { |
| 56 | + type: [String], |
| 57 | + default: 'text' |
| 58 | + }, |
| 59 | + confirmText: { |
| 60 | + type: [String, Number], |
| 61 | + default: '确定' |
| 62 | + }, |
| 63 | + cancelText: { |
| 64 | + type: [String, Number], |
| 65 | + default: '取消' |
| 66 | + }, |
| 67 | + onShow: { |
| 68 | + type: Function, |
| 69 | + default: () => {} |
| 70 | + }, |
| 71 | + onHide: { |
| 72 | + type: Function, |
| 73 | + default: () => {} |
| 74 | + }, |
| 75 | + onConfirm: { |
| 76 | + type: Function, |
| 77 | + default: () => {} |
| 78 | + }, |
| 79 | + onCancel: { |
| 80 | + type: Function, |
| 81 | + default: () => {} |
| 82 | + }, |
| 83 | + onMaskClick: { |
| 84 | + type: Function, |
| 85 | + default: () => {} |
| 86 | + }, |
| 87 | + onClickOutSide: { |
| 88 | + type: Function, |
| 89 | + default: () => {} |
| 90 | + }, |
| 91 | + validate: { |
| 92 | + type: Function, |
| 93 | + default: () => {return false} |
| 94 | + } |
| 95 | + }, |
| 96 | + data() { |
| 97 | + return { |
| 98 | + inputValue: '' |
| 99 | + } |
| 100 | + }, |
| 101 | + computed: { |
| 102 | + messageBoxTransition() { |
| 103 | + if(this.transition) { |
| 104 | + return `messagebox-${this.transition}` |
| 105 | + }else { |
| 106 | + return '' |
| 107 | + } |
| 108 | + }, |
| 109 | + isConfirmDisabled() { |
| 110 | + if(this.type === 'prompt') { |
| 111 | + return !this.validate(this.inputValue) |
| 112 | + }else { |
| 113 | + return false |
| 114 | + } |
| 115 | + } |
| 116 | + }, |
| 117 | + created() { |
| 118 | + }, |
| 119 | + watch: { |
| 120 | + inputType(val) { |
| 121 | + this.handleInputType(val) |
| 122 | + } |
| 123 | + }, |
| 124 | + methods: { |
| 125 | + maskClick() { |
| 126 | + this.onMaskClick() |
| 127 | + }, |
| 128 | + clickOutSide() { |
| 129 | + this.onClickOutSide() |
| 130 | + }, |
| 131 | + handleInputType(val) { |
| 132 | + if (val === 'range' || !this.$refs.input) { |
| 133 | + return |
| 134 | + } |
| 135 | + this.$refs.input.type = val |
| 136 | + }, |
| 137 | + confirmHandler() { |
| 138 | + if(!this.isConfirmDisabled) { |
| 139 | + this.onConfirm() |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | +} |
| 144 | +
|
| 145 | +</script> |
| 146 | + |
| 147 | +<style lang="sass"> |
| 148 | +
|
| 149 | + $background-color: #FFFFFF; |
| 150 | + $title-color: #222222; |
| 151 | + $text-color: #737373; |
| 152 | + $border-color: #dddddd; |
| 153 | + $button-text-color: #4384d8; |
| 154 | + $button-disabled-text-color: #cacaca; |
| 155 | + $input-border-color: #9a9a9a; |
| 156 | + $title-font-size: 36px; |
| 157 | + $text-font-size: 28px; |
| 158 | + $button-font-size: 32px; |
| 159 | +
|
| 160 | + .wd-messagebox { |
| 161 | + width: 600px; |
| 162 | + position: fixed; |
| 163 | + background-color: $background-color; |
| 164 | + top: 50%; |
| 165 | + left: 50%; |
| 166 | + transform: translate3d(-50%, -50%, 0); |
| 167 | + backface-visibility: hidden; |
| 168 | + overflow: hidden; |
| 169 | + border-radius: 16px; |
| 170 | +
|
| 171 | + .wd-messagebox-content { |
| 172 | + display: flex; |
| 173 | + flex-direction: column; |
| 174 | + align-items: center; |
| 175 | + justify-content: center; |
| 176 | + padding: 56px; |
| 177 | + min-height: 200px; |
| 178 | + box-sizing: border-box; |
| 179 | +
|
| 180 | + header { |
| 181 | + margin-bottom: 16px; |
| 182 | + text-align: center; |
| 183 | + align-self: stretch; |
| 184 | + font-size: $title-font-size; /* px */ |
| 185 | + line-height: 50px; |
| 186 | + color: $title-color; |
| 187 | + font-weight: bold; |
| 188 | +
|
| 189 | + &+.wd-messagebox-content-text { |
| 190 | + font-size: 28px; /* px */ |
| 191 | + color: $text-color; |
| 192 | + line-height: 40px; |
| 193 | + } |
| 194 | + } |
| 195 | +
|
| 196 | + .wd-messagebox-content-text { |
| 197 | + text-align: center; |
| 198 | + line-height: 50px; |
| 199 | + font-size: $title-font-size; /* px */ |
| 200 | + } |
| 201 | +
|
| 202 | + input { |
| 203 | + margin-top: 40px; |
| 204 | + padding: 16px; |
| 205 | + width: 488px; |
| 206 | + height: 64px; |
| 207 | + font-size: 28px; |
| 208 | + line-height: 64px; |
| 209 | + border: 1px solid $input-border-color; /* no */ |
| 210 | + border-radius: 4px; /* no */ |
| 211 | + box-sizing: border-box; |
| 212 | + } |
| 213 | + } |
| 214 | +
|
| 215 | + footer { |
| 216 | + display: flex; |
| 217 | + border-top: 1px solid $border-color; /* no */ |
| 218 | +
|
| 219 | + span { |
| 220 | + display: flex; |
| 221 | + flex: 1; |
| 222 | + height: 88px; |
| 223 | + align-items: center; |
| 224 | + justify-content: center; |
| 225 | + font-size: $button-font-size; /* px */ |
| 226 | + color: $button-text-color; |
| 227 | +
|
| 228 | + &.disabled { |
| 229 | + color: $button-disabled-text-color; |
| 230 | + } |
| 231 | + } |
| 232 | +
|
| 233 | + &.wd-messagebox-footer-row { |
| 234 | + flex-direction: row; |
| 235 | +
|
| 236 | + span { |
| 237 | + &:first-child { |
| 238 | + border-right: 1px solid $border-color; /* no */ |
| 239 | + } |
| 240 | + } |
| 241 | + } |
| 242 | + &.wd-messagebox-footer-column { |
| 243 | + flex-direction: column; |
| 244 | +
|
| 245 | + span { |
| 246 | + &:first-child { |
| 247 | + border-bottom: 1px solid $border-color; /* no */ |
| 248 | + } |
| 249 | + } |
| 250 | + } |
| 251 | + } |
| 252 | + } |
| 253 | + .messagebox-fade-enter-active, |
| 254 | + .messagebox-fade-leave-active { |
| 255 | + transition: opacity .3s; |
| 256 | + } |
| 257 | + .messagebox-fade-enter, |
| 258 | + .messagebox-fade-leave-active { |
| 259 | + opacity: 0; |
| 260 | + } |
| 261 | +</style> |
0 commit comments