提交
This commit is contained in:
44
甲情_甲意/miniprogram/pages/denglu/denglu.acss
Normal file
44
甲情_甲意/miniprogram/pages/denglu/denglu.acss
Normal file
@ -0,0 +1,44 @@
|
||||
page {
|
||||
background-color: white;
|
||||
}
|
||||
.tupian{
|
||||
width: 500rpx;
|
||||
height: 500rpx;
|
||||
border-radius: 250rpx;
|
||||
overflow: hidden;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
display: block;
|
||||
}
|
||||
.wenzi{
|
||||
font-size: 40rpx;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin-top: 30px;
|
||||
}
|
||||
.container{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
margin-top: 50px;
|
||||
}
|
||||
navigator {
|
||||
background-color: blue;
|
||||
color: #fff;
|
||||
margin-bottom: 10rpx;
|
||||
padding: 20rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.navigator-hover {
|
||||
background-color: lightskyblue;
|
||||
color: #fff;
|
||||
}
|
||||
.image{
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
position: relative;
|
||||
left: 330rpx;
|
||||
}
|
7
甲情_甲意/miniprogram/pages/denglu/denglu.axml
Normal file
7
甲情_甲意/miniprogram/pages/denglu/denglu.axml
Normal file
@ -0,0 +1,7 @@
|
||||
<view>
|
||||
<image class="tupian" mode="scaleToFill" src="../image/logo.png" />
|
||||
<image mode="scaleToFill" class="image" src="/pages/image/login.png" />
|
||||
<text class="wenzi">请完成授权以继续使用</text>
|
||||
</view>
|
||||
|
||||
<button type="primary" onTap="Login">支付宝一键登录</button>
|
106
甲情_甲意/miniprogram/pages/denglu/denglu.js
Normal file
106
甲情_甲意/miniprogram/pages/denglu/denglu.js
Normal file
@ -0,0 +1,106 @@
|
||||
import {url} from '../request'
|
||||
Page({
|
||||
data: {
|
||||
authCode: '',
|
||||
intervalId: null, // 定时器ID,用于后续清除
|
||||
sid:0
|
||||
},
|
||||
|
||||
Login() {
|
||||
my.getAuthCode({
|
||||
scopes: 'auth_user',
|
||||
success: res => {
|
||||
const authcode = res.authCode;
|
||||
console.log(typeof authcode);
|
||||
console.log(authcode);
|
||||
|
||||
// 请求后端接口进行用户登录
|
||||
my.request({
|
||||
url: url + '/api/Alipay/parseCode',
|
||||
data: {
|
||||
authcode,
|
||||
severId:this.data.sid
|
||||
},
|
||||
success: (res) => {
|
||||
if(res.data.code==0){
|
||||
const { username, avatarUrl, id } = res.data.data.userVO;
|
||||
const setCookie = res.header['set-cookie'] || res.header['Set-Cookie'];
|
||||
console.log('Set-Cookie:', setCookie + '这是这个码');
|
||||
|
||||
// 存储用户信息到本地存储
|
||||
my.setStorage({
|
||||
key: 'userInfo',
|
||||
data: {
|
||||
username: username,
|
||||
avatarUrl: avatarUrl,
|
||||
cookie: setCookie,
|
||||
id: id,
|
||||
timestamp: new Date().getTime(),
|
||||
},
|
||||
success: function () {
|
||||
console.log('用户信息已存储');
|
||||
},
|
||||
fail: function (err) {
|
||||
console.error('存储失败:', err);
|
||||
}
|
||||
});
|
||||
|
||||
// 启动定时器清除缓存
|
||||
this.startClearingStorage();
|
||||
|
||||
// 登录成功后的处理逻辑
|
||||
console.log(res);
|
||||
my.alert({
|
||||
title: '登录成功',
|
||||
});
|
||||
my.navigateBack();
|
||||
}else{
|
||||
this.setData({
|
||||
sid:1,
|
||||
})
|
||||
console.log(this.data.sid);
|
||||
}
|
||||
},
|
||||
fail: (res) => {
|
||||
this.setData({
|
||||
sid:1,
|
||||
})
|
||||
console.log("登录失败:", res);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 启动定时器清除缓存
|
||||
startClearingStorage() {
|
||||
// 清除缓存定时器,每小时检查一次
|
||||
const intervalId = setInterval(() => {
|
||||
my.getStorage({
|
||||
key: 'userInfo',
|
||||
success: (res) => {
|
||||
const userInfo = res.data;
|
||||
|
||||
if (userInfo) {
|
||||
my.removeStorage({
|
||||
key: 'userInfo',
|
||||
success: function () {
|
||||
console.log('用户信息已删除');
|
||||
},
|
||||
fail: function (err) {
|
||||
console.error('删除失败:', err);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log('缓存中没有用户信息,停止定时器');
|
||||
clearInterval(intervalId); // 清除定时器
|
||||
}
|
||||
},
|
||||
});
|
||||
}, 86400*1000); // 每小时检查一次,单位是毫秒(3600秒 = 1小时)
|
||||
// 保存定时器ID,便于后续清除定时器
|
||||
this.setData({
|
||||
intervalId: intervalId,
|
||||
});
|
||||
},
|
||||
});
|
4
甲情_甲意/miniprogram/pages/denglu/denglu.json
Normal file
4
甲情_甲意/miniprogram/pages/denglu/denglu.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"styleIsolation": "apply-shared"
|
||||
}
|
Reference in New Issue
Block a user