-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f84c78
commit 81156ea
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
Page({ | ||
data: { | ||
phoneNumber: '', | ||
password: '' | ||
}, | ||
|
||
onPhoneNumberInput: function (e) { | ||
this.setData({ | ||
phoneNumber: e.detail.value | ||
}); | ||
}, | ||
|
||
onPasswordInput: function (e) { | ||
this.setData({ | ||
password: e.detail.value | ||
}); | ||
}, | ||
|
||
login: function () { | ||
wx.cloud.callFunction({ | ||
name: 'loginUser', | ||
data: { | ||
phoneNumber: this.data.phoneNumber, | ||
password: this.data.password | ||
}, | ||
success: res => { | ||
if (res.result.success) { | ||
wx.showToast({ | ||
title: '登录成功', | ||
icon: 'success', | ||
duration: 2000 | ||
}); | ||
wx.setStorageSync('userId', res.result.user.userId); // 存储用户ID | ||
wx.redirectTo({ | ||
url: '/pages/profile/profile', | ||
}); | ||
} else { | ||
wx.showToast({ | ||
title: res.result.error, | ||
icon: 'none', | ||
duration: 2000 | ||
}); | ||
} | ||
}, | ||
fail: err => { | ||
wx.showToast({ | ||
title: '调用云函数失败', | ||
icon: 'none', | ||
duration: 2000 | ||
}); | ||
console.error('调用云函数失败:', err); | ||
} | ||
}); | ||
}, | ||
|
||
navigateToRegister: function () { | ||
wx.redirectTo({ | ||
url: '/pages/register/register', | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"navigationBarTitleText": "登录" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<view class="container"> | ||
<view class="header"> | ||
<text>登录</text> | ||
</view> | ||
<view class="form"> | ||
<input placeholder="手机号" bindinput="onPhoneNumberInput" /> | ||
<input placeholder="密码" password="true" bindinput="onPasswordInput" /> | ||
<button bindtap="login">登录</button> | ||
<view class="register-link" bindtap="navigateToRegister">没有账号?立即注册</view> | ||
</view> | ||
</view> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100vh; | ||
background-color: #f8f8f8; | ||
} | ||
|
||
.header { | ||
margin-bottom: 20px; | ||
} | ||
|
||
.form { | ||
width: 80%; | ||
} | ||
|
||
input { | ||
width: 100%; | ||
padding: 10px; | ||
margin: 10px 0; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
} | ||
|
||
button { | ||
width: 100%; | ||
padding: 10px; | ||
background-color: #4285f4; | ||
color: #fff; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover { | ||
background-color: #357ae8; | ||
} | ||
|
||
.register-link { | ||
margin-top: 20px; | ||
color: #4285f4; | ||
cursor: pointer; | ||
text-align: center; | ||
} | ||
|
||
.register-link:hover { | ||
color: #357ae8; | ||
} |