{"size": 2030, "ext": "js", "max_stars_repo_path": "src/utils/http/repsonseSideEffect.js", "max_stars_repo_name": "yjfe/maji", "max_stars_repo_stars_event_min_datetime": "2020-12-14T09:10:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-21T06:16:24.000Z", "max_issues_repo_path": "src/utils/http/repsonseSideEffect.js", "max_issues_repo_name": "yaoyunchou/maji", "max_issues_repo_issues_event_min_datetime": "2020-12-31T09:25:56.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-31T10:34:53.000Z", "max_forks_repo_path": "src/utils/http/repsonseSideEffect.js", "max_forks_repo_name": "yaoyunchou/maji", "max_forks_repo_forks_event_min_datetime": "2020-12-14T10:12:42.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-09T13:46:18.000Z"}
{"max_stars_count": 72, "max_issues_count": 2, "max_forks_count": 16, "avg_line_length": 29.0, "max_line_length": 80, "alphanum_fraction": 0.6}
/*
 * @Description: 
 * @Author: yamanashi12
 * @Date: 2019-05-10 10:17:53
 * @LastEditTime: 2020-12-01 15:17:33
 * @LastEditors: Please set LastEditors
 */
import {
  Message
} from 'element-ui'
/**
 * response 过滤器
 *
 * @export
 * @param {*} res
 * @returns
 */
export default function sideEffectDefault(state, res) {
  const { options = {} } = res
  if (state === 'start') {
    if (options && options.context) {
      // eslint-disable-next-line no-underscore-dangle
      if (options.context._isVue) {
        options.context.loading = true
      } else if (options.context.nodeType === 1) { // options为dom对象则修改disabled状态
        if (options.context.parentNode.disabled !== undefined) {
          options.context = options.context.parentNode
        }
        options.context.disabled = true
      }
    }
  } else if (state === 'complete') {
    if (options && options.context) {
      // eslint-disable-next-line no-underscore-dangle
      if (options.context._isVue) {
        options.context.loading = false
        options.context = null
      } else if (options.context.nodeType === 1) { // options为dom对象则修改disabled状态
        options.context.disabled = false
      }
    }
    if (options && options.successMsg) {
      Message({
        message: options.successMsg,
        type: 'success',
        duration: 2 * 1000
      })
    }
  } else if (state === 'filterError' || state === 'ajaxError') {
    if (options.isErrorMessage) return
    options.isErrorMessage = true
    if (options && options.context) {
      // eslint-disable-next-line no-underscore-dangle
      if (options.context._isVue) {
        options.context.loading = false
        options.context = null
      } else if (options.context.nodeType === 1) { // options为dom对象则修改disabled状态
        options.context.disabled = false
      }
    }
    if (!(options && options.errorMsg === 'none')) {
      Message({
        message: options.errorMsg || res.error.responseText || '网络错误',
        type: 'error',
        duration: 2 * 1000
      })
    }
  }
}
