Commit 5ed10c4b by 姜雷

添加请求模版

parent 8a6b4fdb
...@@ -107,92 +107,110 @@ Page({ ...@@ -107,92 +107,110 @@ Page({
if (this.validateLoginData()) { if (this.validateLoginData()) {
const { account, pwd } = this.data; const { account, pwd } = this.data;
console.log(account, pwd); console.log(account, pwd);
wx.requestSubscribeMessage({ systemFetch({
tmplIds: ['WU2yMHKM_yNPLGHRsstggnnGIgcRgDEIaJQiWWNJ9ss'], url: '/boss/login/init/data',
success(res) { method: 'GET',
console.log('in success', res); })
}, .then(res => {
fail(res) { console.log(res);
console.log('in fail', res); return res.templates;
}, })
complete(res) { .catch(err => {
console.log('in complete', res); return;
wx.login({ })
success: res => { .then(ids => {
if (res.code) { let tmplIds =
const code = res.code; ids && ids.length ? ids.map(item => item.templateId) : [];
wx.showLoading({ title: '' }); wx.requestSubscribeMessage({
systemFetch({ tmplIds: tmplIds,
url: '/login/verifyCode', success(res) {
}) console.log('in success', res);
.then((res: wx.RequestSuccessCallbackResult) => { },
console.log(res); fail(res) {
return { console.log('in fail', res);
verifyCode: res.data.verifyCode, },
cookie: res.header['Set-Cookie'], complete(res) {
}; console.log('in complete', res);
}) wx.login({
.then( success: res => {
({ if (res.code) {
verifyCode, const code = res.code;
cookie, wx.showLoading({ title: '' });
}: { systemFetch({
verifyCode: string; url: '/login/verifyCode',
cookie: string; })
}) => { .then((res: wx.RequestSuccessCallbackResult) => {
let mixpwd = md5(pwd); console.log(res);
return systemFetch({ return {
url: '/boss/login', verifyCode: res.data.verifyCode,
method: 'POST', cookie: res.header['Set-Cookie'],
header: { };
cookie: cookie, })
}, .then(
data: { ({
code, verifyCode,
account, cookie,
pwd: mixpwd, }: {
varifyCode: verifyCode, verifyCode: string;
cookie: string;
}) => {
let mixpwd = md5(pwd);
return systemFetch({
url: '/boss/login',
method: 'POST',
header: {
cookie: cookie,
},
data: {
code,
account,
pwd: mixpwd,
varifyCode: verifyCode,
},
});
}, },
)
.then(res => {
console.log(res);
const {
token,
data: { userInfo, userRoles },
} = res;
app.globalData.token = token;
app.globalData.userInfo = userInfo;
app.globalData.userRoles = userRoles.length
? userRoles[0].childs
: [];
try {
wx.setStorageSync('token', token);
} catch (error) {}
wx.hideLoading();
wx.redirectTo({
url: '/pages/homeAndReport/homeAndReport',
});
})
.catch(err => {
console.log(err);
wx.hideLoading();
wx.showToast({
title: err.errMsg,
icon: 'none',
});
}); });
}, } else {
)
.then(res => {
console.log(res);
const {
token,
data: { userInfo, userRoles },
} = res;
app.globalData.token = token;
app.globalData.userInfo = userInfo;
app.globalData.userRoles = userRoles.length
? userRoles[0].childs
: [];
try {
wx.setStorageSync('token', token);
} catch (error) {}
wx.hideLoading();
wx.redirectTo({
url: '/pages/homeAndReport/homeAndReport',
});
})
.catch(err => {
console.log(err);
wx.hideLoading();
wx.showToast({ wx.showToast({
title: err.errMsg, title: '登录获取code失败',
icon: 'none', icon: 'none',
}); });
}); }
} else { },
wx.showToast({ });
title: '登录获取code失败',
icon: 'none',
});
}
}, },
}); });
}, })
}); .catch(err => {
console.log(err);
});
} }
// fetch() // fetch()
// wx.redirectTo({ // wx.redirectTo({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment