import store from '@/store'
import {
  Notification
} from 'element-ui'

export default {
  install(Vue, options) {
    // 定位到错误位置
    Vue.prototype.$scErr = function (val) {
      return new Promise(resolve => {
        const isError = document.getElementsByClassName('is-error');
        isError[0].scrollIntoView({
          // 滚动到指定节点
          // 值有start,center,end，nearest，当前显示在视图区域中间
          block: 'center',
          // 值有auto、instant,smooth，缓动动画（当前是慢速的）
          behavior: 'smooth'
        });
        resolve()
      })
    }


    // 成功轻提示
    Vue.prototype.$sm = function (val) {
      return new Promise(resolve => {
        Notification({
          title: '成功',
          message: val,
          duration: 2000,
          type: 'success'
        })
        resolve()
      })
    }
    // 失败轻提示
    Vue.prototype.$fm = function (val) {
      return new Promise(resolve => {
        Notification({
          title: '提示',
          message: val,
          duration: 2000,
          type: 'warning'
        })
        resolve()
      })
    }
    // 删除弹窗
    Vue.prototype.$delDialog = function (val = '此操作将永久删除该文件, 是否继续?', warnText = '删除提示', btnText) {
      return new Promise(resolve => {
        this.$confirm(val, warnText, {
          cancelButtonText: '取消',
          confirmButtonText: btnText || '确定',
          type: 'warning'
        }).then(() => {
          resolve()
        })
      })
    }
  }
}