jiaqingjiayi-xiaochengxu/甲情_甲意/miniprogram/pages/denglu/denglu.js

60 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-11-15 03:51:28 +00:00
import {url} from '../request'
2024-11-19 10:12:40 +00:00
2024-11-10 07:01:22 +00:00
Page({
2024-11-19 10:12:40 +00:00
data: {
authCode: '',
2024-11-10 07:01:22 +00:00
},
2024-11-19 10:12:40 +00:00
Login() {
2024-11-10 07:01:22 +00:00
my.getAuthCode({
2024-11-19 10:12:40 +00:00
2024-11-15 03:51:28 +00:00
scopes: 'auth_user',
success: res => {
const authCode = res.authCode;
2024-11-19 10:12:40 +00:00
2024-11-15 03:51:28 +00:00
console.log(typeof authCode);
2024-11-19 10:12:40 +00:00
console.log(authCode);
// 请求后端接口进行用户登录
2024-11-15 03:51:28 +00:00
my.request({
2024-11-19 10:12:40 +00:00
url: url + '/api/Alipay/parseCode',
data: {
2024-11-15 03:51:28 +00:00
authCode,
},
2024-11-19 10:12:40 +00:00
success: (res) => {
const { username, avatarUrl,} = res.data.data;
const setCookie = res.header['Set-Cookie'];
// 存储用户信息到本地存储
my.setStorage({
key: 'userInfo',
2024-11-15 03:51:28 +00:00
data: {
2024-11-19 10:12:40 +00:00
username: username,
avatarUrl: avatarUrl,
cookie:setCookie
2024-11-15 03:51:28 +00:00
},
2024-11-19 10:12:40 +00:00
success: function () {
console.log('用户信息已存储',cookie);
},
fail: function (err) {
console.error('存储失败:', err);
}
2024-11-15 03:51:28 +00:00
});
2024-11-19 10:12:40 +00:00
// 登录成功后的处理逻辑
console.log(res);
2024-11-15 03:51:28 +00:00
my.alert({
title: '登录成功',
});
2024-11-19 10:12:40 +00:00
my.navigateBack();
},
fail: (res) => {
console.log("登录失败:", res);
2024-11-15 03:51:28 +00:00
}
2024-11-19 10:12:40 +00:00
});
2024-11-10 07:01:22 +00:00
}
2024-11-19 10:12:40 +00:00
});
2024-11-15 03:51:28 +00:00
},
2024-11-19 10:12:40 +00:00
});