Comparing version 1.0.30 to 1.1.0
101
lib/index.js
@@ -17,2 +17,24 @@ 'use strict'; | ||
var _ = require('lodash'); | ||
var messageList = []; | ||
var pushMessage = function pushMessage() { | ||
messageList = messageList.filter(function (item, index) { | ||
return index === 0 || index !== 0 && JSON.stringify(item) !== JSON.stringify(messageList[0]); | ||
}); | ||
showMessage(); | ||
}; | ||
var showMessage = _.debounce(function () { | ||
if (messageList[0].type === 1) { | ||
v.$message.success(messageList[0].message); | ||
} else if (messageList[0].type === 2) { | ||
v.$notify.error({ | ||
title: '提示', | ||
message: messageList[0].message | ||
}); | ||
} else if (messageList[0].type === 3) { | ||
v.$message.error(messageList[0].message); | ||
} | ||
messageList.splice(0, 1); | ||
}, 300); | ||
exports['default'] = function (_ref) { | ||
@@ -23,2 +45,7 @@ var store = _ref.store; | ||
/** | ||
* 1: 成功, | ||
* 2,notify-error, | ||
* 3: 失败提醒 | ||
*/ | ||
/* eslint-disable */ | ||
@@ -28,6 +55,6 @@ // http请求设置 | ||
// 请求前配置 去首位空格 | ||
_axios2['default'].interceptors.response.eject(instanceResponse); | ||
if (isloaded) { | ||
return _axios2['default']; | ||
} | ||
_axios2['default'].interceptors.response.eject(instanceResponse); | ||
var instanceRequest = _axios2['default'].interceptors.request.use(function (config) { | ||
@@ -137,35 +164,51 @@ var requestData = ''; // 防串改 参数集合 | ||
var instanceResponse = _axios2['default'].interceptors.response.use(function (result) { | ||
// console.log(result) | ||
/* result 为服务器响应回来的数据 */ | ||
/* 方式一:直接返回处理后的 result */ | ||
if (result.data.code === 400) { | ||
(function () { | ||
/* 方式二:返回一个 Promise 对象 可以根据服务端返回的错误码进行判断 */ | ||
var time = 0; | ||
result.data.data.length > 0 && result.data.data.forEach(function (item) { | ||
setTimeout(function () { | ||
v.$notify.error({ | ||
title: '提示', | ||
message: item | ||
}); | ||
}, time); | ||
time = time + 500; | ||
/* 方式二:返回一个 Promise 对象 可以根据服务端返回的错误码进行判断 */ | ||
// let time = 0 | ||
result.data.data.length > 0 && result.data.data.forEach(function (item) { | ||
messageList.push({ | ||
type: 2, | ||
message: item | ||
}); | ||
})(); | ||
pushMessage(); | ||
/* setTimeout(() => { | ||
v.$notify.error({ | ||
title: '提示', | ||
message: item | ||
}) | ||
}, time) */ | ||
/* time = time + 500 */ | ||
}); | ||
} else if (result.data.code === 200 && result.data.msg.trim() !== '') { | ||
v.$message({ | ||
type: 'success', | ||
message: result.data.msg | ||
}); | ||
} else if (result.data.code === 302) { | ||
v.$message.error(result.data.msg); | ||
sessionStorage.clear(); | ||
store.commit('setName', ''); | ||
store.commit('setUserName', ''); | ||
store.commit('setUserId', ''); | ||
store.commit('setAuthority', []); | ||
v.$router.push('/'); | ||
} else if (result.data.msg && result.data.msg.trim() !== '') { | ||
v.$message.error(result.data.msg); | ||
} | ||
messageList.push({ | ||
type: 1, | ||
message: result.data.msg | ||
}); | ||
pushMessage(); | ||
// v.$message() | ||
} else if (result.data.code === 302) { | ||
messageList.push({ | ||
type: 3, | ||
message: result.data.msg | ||
}); | ||
pushMessage(); | ||
// v.$message.error(result.data.msg) | ||
sessionStorage.clear(); | ||
store.commit('setName', ''); | ||
store.commit('setUserName', ''); | ||
store.commit('setUserId', ''); | ||
store.commit('setAuthority', []); | ||
v.$router.push('/'); | ||
messageList = []; | ||
} else if (result.data.msg && result.data.msg.trim() !== '') { | ||
messageList.push({ | ||
type: 3, | ||
message: result.data.msg | ||
}); | ||
pushMessage(); | ||
// v.$message.error(result.data.msg) | ||
} | ||
return result; | ||
@@ -172,0 +215,0 @@ }, function (err) { |
{ | ||
"name": "one-sport", | ||
"version": "1.0.30", | ||
"version": "1.1.0", | ||
"description": "use for one-sport company", | ||
@@ -34,4 +34,5 @@ "main": "lib/index.js", | ||
"axios": "^0.19.0", | ||
"js-md5": "^0.7.3" | ||
"js-md5": "^0.7.3", | ||
"lodash": "^4.17.11" | ||
} | ||
} |
9750
231
3
+ Addedlodash@^4.17.11
+ Addedlodash@4.17.21(transitive)