研发图纸文件管理系统-前端项目
he wei
2025-03-13 ec8d9f802eac6841165425b228ef56474636fa9a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import Alert from './Alert'
 
const AlertMixin = {
  install(Vue) {
    Vue.mixin({
      methods: {
        $alert(message, duration = 2000) {
          let Constructor= Vue.extend(Alert)
          let alert = new Constructor()
          alert.$slots.default = message
          alert.$props.alert = this.$page.alert
          alert.$mount()
          document.body.appendChild(alert.$el)
 
          const appendHeight = alert.$el.offsetHeight + 16
          this.$page.alert.top += appendHeight
 
          setTimeout(() => {
            this.$page.alert.top -= appendHeight
            this.triggerRemoveAlert(appendHeight)
            setTimeout(() => {
              alert.$destroy()
              alert.$el.remove()
            }, 100)
          }, duration)
        },
        triggerRemoveAlert(height) {
          const event = new CustomEvent('alert_remove', {
            detail: {height}
          })
          window.dispatchEvent(event)
        }
      }
    })
  }
}
 
export default AlertMixin