cyl/master-0804
commit
5db7686772
@ -1,236 +1,227 @@
|
|||||||
// let ajaxUrl = "http://192.168.3.83:8001";
|
// let ajaxUrl = "http://192.168.3.83:8001";
|
||||||
let ajaxUrl = "https://daotian.matripe.com.cn";
|
let ajaxUrl = "https://daotian.matripe.com.cn";
|
||||||
let requestTask;
|
|
||||||
let data = {
|
let data = {
|
||||||
ajaxUrl: ajaxUrl,
|
ajaxUrl: ajaxUrl,
|
||||||
startAbort($bool = 0) {
|
Get ($url = '', $parmas = {}, callback = () => { }, failback = () => { }) {
|
||||||
if ($bool == 1) {
|
let that = this,
|
||||||
requestTask.abort();
|
params = {};
|
||||||
}
|
let promise = new Promise((resolve, reject) => {
|
||||||
},
|
params = $parmas;
|
||||||
Get($url = '', $parmas = {}, callback = () => {}, failback = () => {}) {
|
resolve();
|
||||||
let that = this,
|
});
|
||||||
params = {};
|
promise.then(() => {
|
||||||
let promise = new Promise((resolve, reject) => {
|
that.postData($url, params, callback, failback, 'GET');
|
||||||
params = $parmas;
|
}).catch();
|
||||||
resolve();
|
},
|
||||||
});
|
Post ($url = '', $parmas = {}, callback = () => { }, failback = () => { }) {
|
||||||
promise.then(() => {
|
let that = this,
|
||||||
that.postData($url, params, callback, failback, 'GET');
|
params = {};
|
||||||
}).catch();
|
let promise = new Promise((resolve, reject) => {
|
||||||
},
|
params = $parmas;
|
||||||
Post($url = '', $parmas = {}, callback = () => {}, failback = () => {}) {
|
resolve();
|
||||||
let that = this,
|
});
|
||||||
params = {};
|
promise.then(() => {
|
||||||
let promise = new Promise((resolve, reject) => {
|
that.postData($url, params, callback, failback, 'POST');
|
||||||
params = $parmas;
|
}).catch();
|
||||||
resolve();
|
},
|
||||||
});
|
Put ($url = '', $parmas = {}, callback = () => { }, failback = () => { }) {
|
||||||
promise.then(() => {
|
let that = this,
|
||||||
that.postData($url, params, callback, failback, 'POST');
|
params = {};
|
||||||
}).catch();
|
let promise = new Promise((resolve, reject) => {
|
||||||
},
|
params = $parmas;
|
||||||
Put($url = '', $parmas = {}, callback = () => {}, failback = () => {}) {
|
resolve();
|
||||||
let that = this,
|
});
|
||||||
params = {};
|
promise.then(() => {
|
||||||
let promise = new Promise((resolve, reject) => {
|
that.postData($url, params, callback, failback, 'PUT');
|
||||||
params = $parmas;
|
}).catch();
|
||||||
resolve();
|
},
|
||||||
});
|
|
||||||
promise.then(() => {
|
|
||||||
that.postData($url, params, callback, failback, 'PUT');
|
|
||||||
}).catch();
|
|
||||||
},
|
|
||||||
|
|
||||||
setPublicParams() {
|
setPublicParams () {
|
||||||
let that = this,
|
let that = this,
|
||||||
params = {};
|
params = {};
|
||||||
let uuid_new = "";
|
let uuid_new = "";
|
||||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||||
if (uni.getSystemInfoSync().osName == "android") {
|
if (uni.getSystemInfoSync().osName == "android") {
|
||||||
uuid_new = "from_android_applyAssistantUniapp"
|
uuid_new = "from_android_applyAssistantUniapp"
|
||||||
} else {
|
} else {
|
||||||
uuid_new = "from_ios_applyAssistantUniapp"
|
uuid_new = "from_ios_applyAssistantUniapp"
|
||||||
}
|
}
|
||||||
// #endif
|
// #endif
|
||||||
params = {
|
params = {
|
||||||
'requestComeFrom': 'assistant_miniapp',
|
'requestComeFrom': 'assistant_miniapp',
|
||||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||||
'g-open-env': 'APP-PLUS',
|
'g-open-env': 'APP-PLUS',
|
||||||
appId: uuid_new,
|
appId: uuid_new,
|
||||||
// 请求来源标识 1.小程序 2.app 3.网页
|
// 请求来源标识 1.小程序 2.app 3.网页
|
||||||
appClassify: 2,
|
appClassify: 2,
|
||||||
appName: encodeURIComponent('报名助手')
|
appName: encodeURIComponent('报名助手')
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
'g-open-env': 'H5',
|
'g-open-env': 'H5',
|
||||||
appId: '',
|
appId: '',
|
||||||
appClassify: 3,
|
appClassify: 3,
|
||||||
appName: encodeURIComponent('报名助手')
|
appName: encodeURIComponent('报名助手')
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
'g-open-env': 'MP-MINI',
|
'g-open-env': 'MP-MINI',
|
||||||
appId: uni.getAccountInfoSync().miniProgram.appId,
|
appId: uni.getAccountInfoSync().miniProgram.appId,
|
||||||
appClassify: 1,
|
appClassify: 1,
|
||||||
appName: encodeURIComponent('报名助手')
|
appName: encodeURIComponent('报名助手')
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef MP-TOUTIAO
|
// #ifdef MP-TOUTIAO
|
||||||
'g-open-env': 'MP-TOUTIAO',
|
'g-open-env': 'MP-TOUTIAO',
|
||||||
appId: tt.getEnvInfoSync().microapp.appId,
|
appId: tt.getEnvInfoSync().microapp.appId,
|
||||||
subAppId: uni.getStorageSync('subAppId'),
|
subAppId: uni.getStorageSync('subAppId'),
|
||||||
appClassify: 1,
|
appClassify: 1,
|
||||||
appName: encodeURIComponent('报名助手')
|
appName: encodeURIComponent('报名助手')
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef MP-KUAISHOU
|
// #ifdef MP-KUAISHOU
|
||||||
'g-open-env': 'MP-KUAISHOU',
|
'g-open-env': 'MP-KUAISHOU',
|
||||||
appId: "",
|
appId: "",
|
||||||
appClassify: 1,
|
appClassify: 1,
|
||||||
appName: encodeURIComponent('报名助手')
|
appName: encodeURIComponent('报名助手')
|
||||||
// #endif
|
// #endif
|
||||||
}
|
}
|
||||||
return params
|
return params
|
||||||
},
|
},
|
||||||
// 发送请求
|
// 发送请求
|
||||||
postData($url = '', $parmas = {}, callback = () => {}, failback = () => {}, $method) {
|
postData ($url = '', $parmas = {}, callback = () => { }, failback = () => { }, $method) {
|
||||||
let that = this,
|
let that = this,
|
||||||
$header = {};
|
$header = {};
|
||||||
if (uni.getStorageSync("apply-token")) {
|
if (uni.getStorageSync("apply-token")) {
|
||||||
$header.Authorization = 'Bearer ' + uni.getStorageSync("apply-token");
|
$header.Authorization = 'Bearer ' + uni.getStorageSync("apply-token");
|
||||||
}
|
}
|
||||||
if (uni.getStorageSync("apply-agencyId")) {
|
if (uni.getStorageSync("apply-agencyId")) {
|
||||||
// console.log('uni.getStorageSync("apply-agencyId")', uni.getStorageSync("apply-agencyId"));
|
// console.log('uni.getStorageSync("apply-agencyId")', uni.getStorageSync("apply-agencyId"));
|
||||||
$header.Agencyid = uni.getStorageSync("apply-agencyId");
|
$header.Agencyid = uni.getStorageSync("apply-agencyId");
|
||||||
}
|
}
|
||||||
if ($parmas == '') {
|
if ($parmas == '') {
|
||||||
$parmas = {};
|
$parmas = {};
|
||||||
}
|
}
|
||||||
if ($parmas.formdata || $method == "POST" || $method == "PUT") {
|
if ($parmas.formdata || $method == "POST" || $method == "PUT") {
|
||||||
$header['content-type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
|
$header['content-type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
|
||||||
}
|
}
|
||||||
for (const k in $parmas) {
|
for (const k in $parmas) {
|
||||||
if ($parmas[k] == undefined || $parmas[k] == 'undefined') {
|
if ($parmas[k] == undefined || $parmas[k] == 'undefined') {
|
||||||
$parmas[k] = ''
|
$parmas[k] = ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("公共参数,+++++", Object.assign($parmas, that.setPublicParams()));
|
console.log("公共参数,+++++", Object.assign($parmas, that.setPublicParams()));
|
||||||
uni.getNetworkType({
|
uni.request({
|
||||||
success: function(res) {
|
url: ajaxUrl + $url,
|
||||||
// console.log(res);
|
data: Object.assign($parmas, that.setPublicParams()),
|
||||||
if (res.networkType != 'none') {
|
header: Object.assign($header, that.setPublicParams()),
|
||||||
requestTask = uni.request({
|
method: $method,
|
||||||
url: ajaxUrl + $url,
|
success: (res) => {
|
||||||
data: Object.assign($parmas, that.setPublicParams()),
|
// console.log('测试报错123123123123123123',res);
|
||||||
header: Object.assign($header, that.setPublicParams()),
|
// console.log('测试报错123123123123123123$url',$url);
|
||||||
method: $method,
|
let resData = res.data;
|
||||||
success: (res) => {
|
|
||||||
// console.log('测试报错123123123123123123',res);
|
|
||||||
// console.log('测试报错123123123123123123$url',$url);
|
|
||||||
let resData = res.data;
|
|
||||||
|
|
||||||
if (resData.status == 200) { // 正常
|
if (resData.status == 200) {// 正常
|
||||||
callback(resData.data, resData.msg);
|
callback(resData.data, resData.msg);
|
||||||
} else if (resData.status == 9999) { // 登录过期或者身份变动等需要登录的场景
|
} else if (resData.status == 9999) {// 登录过期或者身份变动等需要登录的场景
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: resData.msg,
|
title: resData.msg,
|
||||||
icon: "none"
|
icon: "none"
|
||||||
});
|
});
|
||||||
failback(resData);
|
failback(resData);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
uni.reLaunch({
|
uni.reLaunch({
|
||||||
url: '/root/person/loginIndex?path=/' + that.getPathCopy().path + '&level=' +
|
url: '/root/person/loginIndex?path=/' + that.getPathCopy().path + '&level=' + that.getPathCopy().level
|
||||||
that.getPathCopy().level
|
});
|
||||||
});
|
}, 1500);
|
||||||
}, 1500);
|
} else if (resData.status == 500 || resData.status == 502) {// 某种原因导致接口提示该状态码
|
||||||
} else if (resData.status == 500 || resData.status == 502) { // 某种原因导致接口提示该状态码
|
// if (resData.msg == '系统异常,请稍后') {
|
||||||
// if (resData.msg == '系统异常,请稍后') {
|
// uni.reLaunch({
|
||||||
// uni.reLaunch({
|
// url: '/root/other/error'
|
||||||
// url: '/root/other/error'
|
// });
|
||||||
// });
|
// } else {
|
||||||
// } else {
|
uni.showToast({
|
||||||
uni.showToast({
|
title: resData.msg,
|
||||||
title: resData.msg,
|
// title:'系统异常,请稍后',
|
||||||
// title:'系统异常,请稍后',
|
icon: "none"
|
||||||
icon: "none"
|
});
|
||||||
});
|
failback(resData.msg);
|
||||||
failback(resData.msg);
|
// }
|
||||||
// }
|
} else if (resData.status == 2002) {
|
||||||
} else if (resData.status == 2002) {
|
uni.showToast({
|
||||||
uni.showToast({
|
title: '已切换团队,需要重新登录',
|
||||||
title: '已切换团队,需要重新登录',
|
icon: "none"
|
||||||
icon: "none"
|
});
|
||||||
});
|
setTimeout(() => {
|
||||||
setTimeout(() => {
|
uni.reLaunch({
|
||||||
uni.reLaunch({
|
url: '/root/person/loginIndex?path=/pages/home/index&level=' + that.getPathCopy().level
|
||||||
url: '/root/person/loginIndex?path=/pages/home/index&level=' + that
|
});
|
||||||
.getPathCopy().level
|
}, 1500);
|
||||||
});
|
} else {// 其他异常
|
||||||
}, 1500);
|
if ($url == '/yishoudan/user/apply/order/V2/details') {
|
||||||
} else { // 其他异常
|
|
||||||
if ($url == '/yishoudan/user/apply/order/V2/details') {
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: resData.msg,
|
title: resData.msg,
|
||||||
icon: "none"
|
icon: "none"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
failback(resData.msg);
|
failback(resData.msg);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail(error) {
|
fail (error) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
// title: error.errMsg,
|
// title: error.errMsg,
|
||||||
title: '系统异常,请稍后',
|
title: '系统异常,请稍后',
|
||||||
icon: "none"
|
icon: "none"
|
||||||
})
|
})
|
||||||
failback(error);
|
failback(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
},
|
||||||
uni.showToast({
|
|
||||||
title: '网络异常,请检查网络',
|
|
||||||
icon: "none"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
// 头像上传
|
// 头像上传
|
||||||
uploadFile($file, callback = () => {}) {
|
uploadFile ($file, callback = () => { }) {
|
||||||
let that = this;
|
let that = this;
|
||||||
uni.uploadFile({
|
uni.uploadFile({
|
||||||
url: ajaxUrl + '/user/changeUserImgsrc',
|
url: ajaxUrl + '/user/changeUserImgsrc',
|
||||||
filePath: $file,
|
filePath: $file,
|
||||||
name: 'uploadFile',
|
name: 'uploadFile',
|
||||||
header: Object.assign({
|
header: Object.assign({
|
||||||
Authorization: 'Bearer ' + uni.getStorageSync("apply-token")
|
Authorization: 'Bearer ' + uni.getStorageSync("apply-token")
|
||||||
}, that.setPublicParams()),
|
}, that.setPublicParams()),
|
||||||
formData: that.setPublicParams(),
|
formData: that.setPublicParams(),
|
||||||
success: (uploadFileRes) => {
|
success: (uploadFileRes) => {
|
||||||
callback(JSON.parse(uploadFileRes.data).data.url);
|
callback(JSON.parse(uploadFileRes.data).data.url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/* 获取当前path
|
/* 获取当前path
|
||||||
*/
|
*/
|
||||||
getPathCopy() {
|
getPathCopy () {
|
||||||
const pages = getCurrentPages();
|
const pages = getCurrentPages();
|
||||||
if (pages.length > 0) {
|
if (pages.length > 0) {
|
||||||
let _path = pages[pages.length - 1].route;
|
let _path = pages[pages.length - 1].route;
|
||||||
return {
|
return {
|
||||||
path: _path,
|
path: _path,
|
||||||
level: _path.slice(0, 4)
|
level: _path.slice(0, 4)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
path: '',
|
path: '',
|
||||||
level: ''
|
level: ''
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
//监听用户的页面点击
|
||||||
|
watchUserPage (path) {
|
||||||
|
let that = this;
|
||||||
|
try {
|
||||||
|
if (uni.getStorageSync("apply-userinfo")) {
|
||||||
|
that.Post("/common/user/browsing/history/addRecord", { browsingUrl: path }, (res) => { });
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log("error", error);
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default data;
|
export default data;
|
||||||
Loading…
Reference in New Issue