first commit
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
const RunFunction = ({func, code, data, msg}) => {
|
||||
if (func) {
|
||||
func({code, data, msg})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 请求完成后调用(带消息的)
|
||||
* @param app vue实例
|
||||
* @param response 请求返回值
|
||||
* @param success 成功的方法
|
||||
* @param fail 失败的方法
|
||||
* @param final 始终都要调用的方法
|
||||
*/
|
||||
const AssertResponseMessage = ({app, response, success, fail, final}) => {
|
||||
const {code, data, msg} = response
|
||||
|
||||
app = app ? app : (vue ? vue : app)
|
||||
|
||||
if (code === 0) {
|
||||
if (app) app.$notify({
|
||||
title: '成功',
|
||||
message: msg,
|
||||
type: 'success'
|
||||
});
|
||||
|
||||
RunFunction({func: success, code, data, msg})
|
||||
} else {
|
||||
if (app) app.$notify.error({
|
||||
title: '错误',
|
||||
message: msg
|
||||
});
|
||||
RunFunction({func: fail, code, data, msg})
|
||||
}
|
||||
|
||||
RunFunction({func: final, code, data, msg})
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求完成后调用(带消息的 成功不提示,失败提示)
|
||||
* @param app vue实例
|
||||
* @param response 请求返回值
|
||||
* @param success 成功的方法
|
||||
* @param fail 失败的方法
|
||||
* @param final 始终都要调用的方法
|
||||
*/
|
||||
const AssertResponseMessage2 = ({app, response, success, fail, final}) => {
|
||||
const {code, data, msg} = response
|
||||
|
||||
app = app ? app : (vue ? vue : app)
|
||||
|
||||
if (code === 0) {
|
||||
RunFunction({func: success, code, data, msg})
|
||||
} else {
|
||||
if (app) app.$notify.error({
|
||||
title: '错误',
|
||||
message: msg
|
||||
});
|
||||
RunFunction({func: fail, code, data, msg})
|
||||
}
|
||||
|
||||
RunFunction({func: final, code, data, msg})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 请求完成后调用
|
||||
* @param response 请求返回值
|
||||
* @param success 成功的方法
|
||||
* @param fail 失败的方法
|
||||
* @param final 始终都要调用的方法
|
||||
*/
|
||||
const AssertResponse = ({response, success, fail, final}) => {
|
||||
const {code, data, msg} = response
|
||||
if (code === 0) {
|
||||
RunFunction({func: success, code, data, msg})
|
||||
} else {
|
||||
RunFunction({func: fail, code, data, msg})
|
||||
}
|
||||
RunFunction({func: final, code, data, msg})
|
||||
}
|
||||
Reference in New Issue
Block a user