移动端基于Vux二次封装弹窗

移动端基于Vux二次封装弹窗

// confirm
export function confirm (params) {
  if (!params) return
  let p = new Promise((resolve) => {
    let title, content, buttonText, confirmText, cancelText, showInput, inputAttrs, placeholder, showFn, hideFn,
      cancelFn, confirmFn
    if (typeof params === 'string') {
      content = params
    } else if (params.constructor === Object) {
      ({
        title,
        content,
        buttonText,
        confirmText,
        cancelText,
        showInput,
        inputAttrs,
        placeholder,
        showFn,
        hideFn,
        cancelFn,
        confirmFn,
      } = params)
    }
    console.log('# params #', title, content, buttonText, confirmText, cancelText, showInput, inputAttrs, placeholder, showFn, hideFn, cancelFn, confirmFn)
    this.$vux.confirm.show({
      title: title || '提示',
      content: content || '',
      buttonText: buttonText || '确定',
      confirmText: confirmText || '确认',
      cancelText: cancelText || '取消',
      showInput: showInput || false,
      inputAttrs: inputAttrs || {},
      placeholder: placeholder || '请输入',
      hideOnBlur: true,
      onShow () {
        console.log('# onShow #')
        if (showFn && typeof showFn === 'function') {
          showFn.call(this)
        }
      },
      onHide () {
        console.log('# onHide #')
        if (hideFn && typeof hideFn === 'function') {
          hideFn.call(this)
        }
      },
      onCancel () {
        console.log('# onCancel #')
        if (cancelFn && typeof cancelFn === 'function') {
          cancelFn.call(this)
        }
      },
      onConfirm () {
        console.log('# onConfirm #')
        if (confirmFn && typeof confirmFn === 'function') {
          confirmFn.call(this)
        }
        resolve()
      },
    })
  })
  return p
}

// toast
export function toast (params, callback) {
  if (!params) return
  console.log('# toast #', params)
  let text, type, width, time, position
  if (typeof params === 'string') {
    text = params
  } else if (params.constructor === Object) {
    ({type, width, time, text, position} = params)
  }
  this.$vux.toast.show({
    type: type || 'text',
    width: width || 'auto',
    time: time || '2000',
    text: text || '',
    position: position || 'default',
    isShowMask: true,
  })
  callback && setTimeout(() => { callback() }, time)
}

// loading
export function loading (params, show) {
  console.log('# loading000 #', params, show)
  let text, position, isShow = show
  if (typeof params === 'undefined') {
    isShow = true
  } else if (typeof params === 'boolean') {
    isShow = params
  } else if (typeof params === 'string') {
    text = params
  } else if (params.constructor === Object) {
    ({text, position} = params)
  }
  console.log('# loading #', params, isShow)
  if (isShow === false) {
    console.log('# hide #')
    this.$vux.loading.hide()
  } else {
    this.$vux.loading.show({
      text: text || '加载中...',
      position: position || 'fixed',
    })
  }
}
发布了12 篇原创文章 · 获赞 0 · 访问量 1959

猜你喜欢

转载自blog.csdn.net/weixin_41579185/article/details/97657965
今日推荐