|
|
@@ -126,8 +126,10 @@ class Utils {
|
|
|
wx.getNetworkType({
|
|
|
success: function(res) {
|
|
|
if (res.networkType === 'none') {
|
|
|
+ wx.$emit('offline', true)
|
|
|
reslove('offline')
|
|
|
} else {
|
|
|
+ wx.$emit('offline', false)
|
|
|
reslove(res.networkType)
|
|
|
}
|
|
|
},
|
|
|
@@ -144,6 +146,20 @@ class Utils {
|
|
|
@status 是否携带userID
|
|
|
*/
|
|
|
async request(options) {
|
|
|
+ /**
|
|
|
+ * 检测网络状况 并判断是否发起请求
|
|
|
+ * 当无网络时传入 offline 并提示无网络
|
|
|
+ */
|
|
|
+ const networkType = await this.getNetworkType();
|
|
|
+ if (networkType === 'offline') {
|
|
|
+ wx.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: '网络未连接',
|
|
|
+ })
|
|
|
+ options.success && options.success(networkType)
|
|
|
+ return this.getNetworkType()
|
|
|
+ }
|
|
|
+
|
|
|
/* 拼接接口地址 */
|
|
|
if (this.getDataType(options.url) !== 'String') {
|
|
|
throw new Error('接口路径格式错误')
|
|
|
@@ -186,36 +202,22 @@ class Utils {
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
- /**
|
|
|
- * 检测网络状况 并判断是否发起请求
|
|
|
- * 当无网络时传入 offline 并提示无网络
|
|
|
- */
|
|
|
- const networkType = await this.getNetworkType();
|
|
|
- if (networkType === 'offline') {
|
|
|
- wx.showToast({
|
|
|
- icon: 'none',
|
|
|
- title: '网络未连接',
|
|
|
- })
|
|
|
- wx.$emit('offline', true)
|
|
|
- options.success && options.success(networkType)
|
|
|
- return this.getNetworkType()
|
|
|
+ /**根据判断写入openid */
|
|
|
+ // if (!options.no_openid) {
|
|
|
+ // options.data.openid = await this.getOpenid();
|
|
|
+ // }
|
|
|
+
|
|
|
+ /* 根据dont_login判断是否需要登录 */
|
|
|
+ if (options.dont_login) {
|
|
|
+ return this._request(options);
|
|
|
} else {
|
|
|
- /**根据判断写入openid */
|
|
|
- // if (!options.no_openid) {
|
|
|
- // options.data.openid = await this.getOpenid();
|
|
|
- // }
|
|
|
- /* 根据dont_login判断是否需要登录 */
|
|
|
- if (options.dont_login) {
|
|
|
- return this._request(options);
|
|
|
+ /* 设置userID和usertoken */
|
|
|
+ let _options = await this.getUserId(options);
|
|
|
+ /** 当user_id与user_token不全时 提示登陆重新获取 */
|
|
|
+ if (_options.data.user_id && _options.data.user_token) {
|
|
|
+ return this._request(_options);
|
|
|
} else {
|
|
|
- /* 设置userID和usertoken */
|
|
|
- let _options = await this.getUserId(options);
|
|
|
- /** 当user_id与user_token不全时 提示登陆重新获取 */
|
|
|
- if (_options.data.user_id && _options.data.user_token) {
|
|
|
- return this._request(_options);
|
|
|
- } else {
|
|
|
- this._doLogin();
|
|
|
- }
|
|
|
+ this._doLogin();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -243,8 +245,6 @@ class Utils {
|
|
|
dataType: opt.dataType,
|
|
|
responseType: opt.responseType,
|
|
|
success: function(res) {
|
|
|
- // 设置网络状态
|
|
|
- wx.$emit('offline', false)
|
|
|
// 判断是否含有成功方法并执行
|
|
|
if (opt.success && typeof opt.success === 'function') {
|
|
|
if (res.statusCode === 200) {
|
|
|
@@ -353,7 +353,14 @@ class Utils {
|
|
|
user_id: wx.getStorageSync('userid'),
|
|
|
user_token: wx.getStorageSync('usertoken'),
|
|
|
...options.formData
|
|
|
- }
|
|
|
+ };
|
|
|
+ !this._loading && wx.showLoading({
|
|
|
+ mask: true,
|
|
|
+ title: '上传中...',
|
|
|
+ success: () => {
|
|
|
+ this._loading = true
|
|
|
+ }
|
|
|
+ })
|
|
|
return new Promise((reslove, reject) => {
|
|
|
if (_type === "Array") {
|
|
|
const _arr = [];
|
|
|
@@ -372,6 +379,11 @@ class Utils {
|
|
|
if (data.errcode === 0) {
|
|
|
_arr.push(data.data);
|
|
|
if (_len === key) {
|
|
|
+ wx.hideLoading({
|
|
|
+ success: () => {
|
|
|
+ this._loading = false;
|
|
|
+ }
|
|
|
+ })
|
|
|
reslove(_arr)
|
|
|
}
|
|
|
}
|
|
|
@@ -401,11 +413,14 @@ class Utils {
|
|
|
wx.kx_request({
|
|
|
url: wx.kx_api.hwUser.getHwUserInfo,
|
|
|
success: res => {
|
|
|
- //成功后存入缓存
|
|
|
- wx.setStorageSync('userinfo', res.data.hwUser);
|
|
|
- that.setData({
|
|
|
- userinfo: res.data.hwUser
|
|
|
- })
|
|
|
+ if (res.data) {
|
|
|
+ //成功后存入缓存
|
|
|
+ wx.setStorageSync('userinfo', res.data.hwUser);
|
|
|
+ // 判断是否提交页面数据
|
|
|
+ that && that.setData({
|
|
|
+ userinfo: res.data.hwUser
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
}
|