登录对接
This commit is contained in:
@@ -27,14 +27,14 @@ export default {
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
},
|
||||
params: {
|
||||
currentPage: 1,
|
||||
pageNum: 1,
|
||||
pageSize: 20,
|
||||
},
|
||||
reload() {
|
||||
this.data = [];
|
||||
this.status = 'loading';
|
||||
this.empty = false;
|
||||
this.params.currentPage = 1;
|
||||
this.params.pageNum = 1;
|
||||
this.next();
|
||||
},
|
||||
callBack: null,
|
||||
@@ -50,7 +50,7 @@ export default {
|
||||
console.warn(res);
|
||||
let resultData =
|
||||
res.data?.list || res.data?.records || [];
|
||||
if (this.params.currentPage == 1) {
|
||||
if (this.params.pageNum == 1) {
|
||||
this.data = resultData;
|
||||
if (resultData.length == 0 || resultData == 0) {
|
||||
this.empty = true;
|
||||
@@ -68,11 +68,11 @@ export default {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.params.currentPage == 1) {
|
||||
if (this.params.pageNum == 1) {
|
||||
this.firstCallBack && this.firstCallBack();
|
||||
}
|
||||
this.loadedCallback && this.loadedCallback();
|
||||
this.params.currentPage++;
|
||||
this.params.pageNum++;
|
||||
this.total = res.total;
|
||||
this.loading = false;
|
||||
});
|
||||
|
||||
@@ -1,68 +1,62 @@
|
||||
import config from './config';
|
||||
let arr = [];
|
||||
import config from './config'
|
||||
|
||||
let arr = []
|
||||
export default (options = {}) => {
|
||||
if (options.data == undefined) {
|
||||
options.data = {};
|
||||
options.data = {}
|
||||
}
|
||||
// 防止接口重复点击
|
||||
if (arr.indexOf(options.url) === -1) {
|
||||
arr.push(options.url);
|
||||
arr.push(options.url)
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
reject({
|
||||
code: -1,
|
||||
msg: '请勿重复提交',
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
}
|
||||
return new Promise((reslove, reject) => {
|
||||
uni.request({
|
||||
url:
|
||||
options.url.indexOf('http') === -1
|
||||
? config.domain + options.url
|
||||
: options.url,
|
||||
url: options.url.indexOf('http') === -1 ? config.domain + options.url : options.url,
|
||||
data: {
|
||||
...options.data,
|
||||
userId: uni.getStorageSync('userInfo').id,
|
||||
},
|
||||
header: {
|
||||
// 'Content-Type': 'application/json;charset=UTF-8',
|
||||
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
Authorization: '12',
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
Authorization: uni.getStorageSync('token'),
|
||||
...options.header,
|
||||
},
|
||||
method: options.method || 'GET',
|
||||
success: async (res) => {
|
||||
console.log(res);
|
||||
console.log(res)
|
||||
if (arr.indexOf(options.url) > -1) {
|
||||
arr.splice(arr.indexOf(options.url), 1);
|
||||
arr.splice(arr.indexOf(options.url), 1)
|
||||
}
|
||||
if (
|
||||
res.data.resultCode !== 10000 &&
|
||||
res.data.code !== 'A0000'
|
||||
) {
|
||||
errHandler(res.data);
|
||||
reject(res.data);
|
||||
if (res.data.resultCode !== 10000 && res.data.code !== 'A0000') {
|
||||
errHandler(res.data)
|
||||
reject(res.data)
|
||||
} else {
|
||||
reslove(res.data);
|
||||
reslove(res.data)
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
if (arr.indexOf(options.url) > -1) {
|
||||
arr.splice(arr.indexOf(options.url), 1);
|
||||
arr.splice(arr.indexOf(options.url), 1)
|
||||
}
|
||||
reject(err);
|
||||
reject(err)
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: '网络异常,请稍后再试',
|
||||
});
|
||||
})
|
||||
uni.reLaunch({
|
||||
url: '/pages/user/login',
|
||||
});
|
||||
})
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误处理
|
||||
@@ -72,17 +66,17 @@ function errHandler(res) {
|
||||
switch (res.resultCode) {
|
||||
case '401':
|
||||
// #ifdef MP
|
||||
uni.removeStorageSync('Cookie');
|
||||
uni.clearStorageSync();
|
||||
uni.removeStorageSync('Cookie')
|
||||
uni.clearStorageSync()
|
||||
// #endif
|
||||
uni.reLaunch({ url: '/pages/user/login' });
|
||||
break;
|
||||
uni.reLaunch({ url: '/pages/user/login' })
|
||||
break
|
||||
default:
|
||||
uni.showToast({
|
||||
title: res.msg || '服务端未知错误',
|
||||
title: res.message || res.msg || '服务端未知错误',
|
||||
duration: 2000,
|
||||
icon: 'none',
|
||||
});
|
||||
break;
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,6 +197,14 @@ const prePage = () => {
|
||||
return prePage
|
||||
}
|
||||
|
||||
const loginSuccess = (data) => {
|
||||
uni.setStorageSync('userInfo', data)
|
||||
uni.setStorageSync('token', data.token_type + ' ' + data.access_token)
|
||||
uni.reLaunch({
|
||||
url: '/pages/user/login',
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
validatePhoneNumber,
|
||||
toast,
|
||||
@@ -206,4 +214,5 @@ export default {
|
||||
getUserLocation,
|
||||
loadConfig,
|
||||
prePage,
|
||||
loginSuccess,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user