SearchForm默认折叠

el-message加入关闭进度条,鼠标移入移出时不再重新计时
master
toesbieya 6 years ago
parent 5408210238
commit a150bafc12
  1. 23
      vue/src/assets/styles/element-ui.scss
  2. 2
      vue/src/bizComponents/SearchForm/index.vue
  3. 2
      vue/src/components/Message/index.js
  4. 31
      vue/src/components/Message/main.vue
  5. 3
      vue/src/config/request.js

@ -84,6 +84,20 @@
line-height: 12px; line-height: 12px;
} }
&__progress {
z-index: -1;
position: absolute;
height: 3px;
bottom: 0;
left: 10px;
right: 10px;
animation: el-message-progress linear;
background: currentColor;
opacity: .3;
transform-origin: 0 50%;
transform: scaleX(0);
}
.el-message__icon, .el-message__content { .el-message__icon, .el-message__content {
color: #fff !important; color: #fff !important;
} }
@ -222,6 +236,15 @@
} }
} }
@keyframes el-message-progress {
0% {
transform: scaleX(1)
}
100% {
transform: scaleX(0)
}
}

@ -15,7 +15,7 @@
data() { data() {
return { return {
showCollapse: false, showCollapse: false,
collapse: false, collapse: true,
num: 0 num: 0
} }
}, },

@ -27,7 +27,7 @@ const Message = function (options) {
if (originalMessage) { if (originalMessage) {
//旧实例的badge+1,并重新计时(如果有的话) //旧实例的badge+1,并重新计时(如果有的话)
originalMessage.badge++ originalMessage.badge++
originalMessage.clearTimer() originalMessage.clearTimer(true)
originalMessage.startTimer() originalMessage.startTimer()
return originalMessage return originalMessage
} }

@ -7,7 +7,6 @@
@mouseenter="clearTimer" @mouseenter="clearTimer"
@mouseleave="startTimer" @mouseleave="startTimer"
> >
<div v-if="badge>1" :key="badge" class="el-message__badge">{{badge}}</div>
<i v-if="iconClass" :class="iconClass"/> <i v-if="iconClass" :class="iconClass"/>
<i v-else :class="typeClass"/> <i v-else :class="typeClass"/>
<slot> <slot>
@ -15,6 +14,8 @@
<p v-else v-html="message" class="el-message__content"/> <p v-else v-html="message" class="el-message__content"/>
</slot> </slot>
<i v-if="showClose" class="el-message__closeBtn el-icon-close" @click="close"/> <i v-if="showClose" class="el-message__closeBtn el-icon-close" @click="close"/>
<div v-if="badge>1" :key="'badge'+badge" class="el-message__badge">{{badge}}</div>
<div v-if="progress&&!closed" :key="'progress'+badge" class="el-message__progress" :style="progressStyle"/>
</div> </div>
</transition> </transition>
</template> </template>
@ -24,10 +25,14 @@
data() { data() {
return { return {
visible: false, visible: false,
badge: 1, badge: 1,//1
progress: true,//
pause: false,//
message: '', message: '',
duration: 3000, duration: 3000,
type: '', startAt: 0,//
remainTime: 0,//
type: '',//js
iconClass: '', iconClass: '',
customClass: '', customClass: '',
onClose: null, onClose: null,
@ -58,13 +63,16 @@
return { return {
'top': `${this.verticalOffset}px` 'top': `${this.verticalOffset}px`
} }
},
progressStyle() {
if (!this.progress || this.closed) return 'transform: scaleX(0)'
if (this.pause) return `transform: scaleX(${this.remainTime / this.duration});animation-play-state:paused`
return `animation-duration: ${this.duration}ms;animation-play-state:running`
} }
}, },
watch: { watch: {
closed(newVal) { closed(newVal) {
if (newVal) { if (newVal) this.visible = false
this.visible = false
}
} }
}, },
methods: { methods: {
@ -76,14 +84,19 @@
this.closed = true this.closed = true
typeof this.onClose === 'function' && this.onClose(this) typeof this.onClose === 'function' && this.onClose(this)
}, },
clearTimer() { clearTimer(reset) {
this.pause = true
this.remainTime = reset === true ? this.duration : this.remainTime - (Date.now() - this.startAt)
clearTimeout(this.timer) clearTimeout(this.timer)
}, },
startTimer() { startTimer() {
if (this.duration > 0) { if (this.duration > 0 && !this.closed) {
this.pause = false
this.startAt = Date.now()
if (this.remainTime === 0) this.remainTime = this.duration
this.timer = setTimeout(() => { this.timer = setTimeout(() => {
!this.closed && this.close() !this.closed && this.close()
}, this.duration) }, this.remainTime)
} }
} }
}, },

@ -1,6 +1,7 @@
import axios from 'axios' import axios from 'axios'
import {apiPrefix} from '@/config' import {apiPrefix} from '@/config'
import {Message, MessageBox, Notification} from 'element-ui' import {MessageBox, Notification} from 'element-ui'
import Message from '@/components/Message'
import store from '@/store' import store from '@/store'
const service = axios.create({ const service = axios.create({

Loading…
Cancel
Save