修改二维码登录逻辑

This commit is contained in:
2024-03-27 14:44:59 +08:00
parent 3b5525a2a2
commit 61bcbf6f69
11 changed files with 173 additions and 25 deletions

View File

@@ -1,3 +1,4 @@
import { getTenementDetail } from "../../service/tenement";
import { userApply } from "../../service/user";
import { alertInfo, alertSuccess } from "../../utils/index";
import request from '../../utils/request'
@@ -10,7 +11,8 @@ Page({
*/
data: {
id: "",
name: "",
tenement: {},
nickName: ""
},
/**
@@ -18,12 +20,67 @@ Page({
*/
onLoad(options) {
const querys = decodeURIComponent(options.scene)
const { id, name } = querys;
this.setData({ id, name })
const { id } = querys;
// this.setData({ id, name })
this.getInfo(id);
},
async getInfo(id) {
const { code, message, data } = await getTenementDetail(id);
if (code !== OK) {
alertInfo(message)
return
}
this.setData({
tenement: data,
id
})
},
exit() {
wx.exitMiniProgram()
},
onChangeName(e) {
this.setData({
nickName: e.detail
})
},
async handleLogin(phoneCode) {
const { id, nickName } = this.data;
loadingFunc(async () => {
const wxLoginCode = await wxLogin()
const result = await userApply({ code: wxLoginCode, phoneCode, id, name: nickName })
const { code, message, data } = result;
if (code !== OK) {
alertError(message)
return
}
if (!data?.id) {
this.noPermission()
return;
}
alertSuccess("登录成功")
const { token, ...user } = data
wx.setStorageSync('user', user)
wx.setStorageSync('token', data?.token)
wx.switchTab({
url: '/pages/home/index',
})
})
},
getPhoneNumber(e) {
const { errno, code: phoneCode } = e.detail;
switch(errno) {
case 103:
alertInfo("已拒绝");
return;
case 1400001:
alertInfo("服务达到上限")
return;
default:
this.handleLogin(phoneCode)
return;
}
},
async join() {
const { id } = this.data;
const { code, message, data } = await userApply({ id })

View File

@@ -1,5 +1,6 @@
{
"usingComponents": {
"van-button": "@vant/weapp/button/index"
"van-button": "@vant/weapp/button/index",
"van-field": "@vant/weapp/field/index"
}
}

View File

@@ -1,11 +1,21 @@
<!--pages/apply/index.wxml-->
<view class="content">
<view class="text"> 即将加入{{tenement.name}} </view>
<view class="nickName">
<van-field
required
value="{{ name }}"
label="你的昵称"
placeholder="请输入你的昵称"
border="{{ false }}"
bind:change="onChangeName"
/>
</view>
<view class="contentWrapper">
<view class="text"> 确定要加入{{name}}吗? </view>
<view class="operate">
<van-button type="default" block style="flex: 1;" bind:click="exit">退出</van-button>
<van-button type="info" block style="flex:1;margin-left: 20rpx;">确认</van-button>
<van-button type="info" block style="flex:1;margin-left: 20rpx;" open-type="getPhoneNumber" bind:getphonenumber="getPhoneNumber">确认</van-button>
</view>
</view>
</view>

View File

@@ -6,6 +6,7 @@
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.text {
@@ -24,3 +25,10 @@
margin-right: 40rpx;
}
.nickName {
width: 95vw;
margin-bottom: 60rpx;
display: flex;
justify-content: center;
}