修改二维码登录逻辑
This commit is contained in:
@@ -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 })
|
||||
|
Reference in New Issue
Block a user