Skip to content

Commit

Permalink
login page
Browse files Browse the repository at this point in the history
  • Loading branch information
kathywang944 authored Jul 9, 2024
1 parent 7f84c78 commit 81156ea
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
61 changes: 61 additions & 0 deletions login.js
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',
});
}
});
3 changes: 3 additions & 0 deletions login.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"navigationBarTitleText": "登录"
}
11 changes: 11 additions & 0 deletions login.wxml
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>
49 changes: 49 additions & 0 deletions login.wxss
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;
}

0 comments on commit 81156ea

Please sign in to comment.