Browse Source

fix:解决手机号登录、添加获取用户信息接口

master
xiaohei 1 year ago
parent
commit
bce7e75a4d
4 changed files with 322 additions and 263 deletions
  1. +12
    -3
      src/api/myApi.js
  2. +1
    -1
      src/config/env.js
  3. +12
    -16
      src/pages/my/my.vue
  4. +297
    -243
      src/pages/phone/index.vue

+ 12
- 3
src/api/myApi.js View File

@@ -30,6 +30,14 @@ const getUserInfoApi = function (data) {
});
};

const getProfileUserInfoApi = function (data) {
return request({
url: '/admin-api/system/user/profile/get',
method: 'get',
data: data
});
};

/**
* 获得用户积分规则分页
* @param {*} data
@@ -142,7 +150,7 @@ const replyGoodPageApi = function (data) {
const sendSmSCodeApi = function (data) {
return request({
url: '/admin-api/system/auth/send-sms-code',
method: 'get',
method: 'post',
data: data
});
};
@@ -150,7 +158,7 @@ const sendSmSCodeApi = function (data) {
const systemAuthSmsLogin = function (data) {
return request({
url: '/admin-api/system/auth/sms-login',
method: 'get',
method: 'post',
data: data
});
};
@@ -167,5 +175,6 @@ export {
replyCreatUpdateApi,
replyGoodPageApi,
sendSmSCodeApi,
systemAuthSmsLogin
systemAuthSmsLogin,
getProfileUserInfoApi
};

+ 1
- 1
src/config/env.js View File

@@ -2,7 +2,7 @@
* @name 小程序环境
* @description 多环境配置
*/
const envName = 'production';
const envName = 'development';
const envs = [{
envName: 'production',
appID: 'wx736395182f05a1b7',


+ 12
- 16
src/pages/my/my.vue View File

@@ -13,7 +13,7 @@
</image>
</view>
<view class="top-content flex1">
<view class="name" v-if="isLogin">{{ userInfo.nickName }}</view>
<view class="name" v-if="isLogin">{{ userInfo.nickname }}</view>
<view class="name" @tap="login" v-else>请登录</view>
<!-- <view class="role" wx:if="{{role}}">{{role}}</view> -->
</view>
@@ -135,22 +135,20 @@
};
},
async onLoad() {
// const { code } = await uni.pro.login();
// this.setData({
// code
// });
this.recursionApi();
},
onShow() {
// 设置判断,限制不同权限渲染不同数据
this.setMune();
this.getInitData();
// this.getUserInfoApi();
this.getUserInfoApi();
this.getUserInfo();
},
methods: {
async getUserInfoApi() {
const res = await myApi.getUserInfoApi();
if (res.data) {
this.myInfo = res.data
uni.setStorageSync('userInfoCount', res.data);
}
},
@@ -310,16 +308,14 @@
}
},

// // 获取我的信息
// async getUserInfo() {
// const res = await myApi.getUserInfoApi();
// if (res.data) {
// this.setData({
// myInfo: res.data,
// });
// wx.setStorageSync('userInfoCount', res.data);
// }
// },
// 获取我的信息
async getUserInfo() {
const res = await myApi.getProfileUserInfoApi();
if (res.data) {
this.userInfo = res.data
uni.setStorageSync("userInfoData", res.data);
}
},
async recursionApi() {
const {
data = []


+ 297
- 243
src/pages/phone/index.vue View File

@@ -1,35 +1,70 @@
<template>
<view style="height: 100%">
<view class="container"
style="background-image: url(https://jiexiu.xuqidata.com:8083/jiexiujumin/3ee992d1442bb8285c37f93a9ee1f93ed6e086131fc514d7b697b2cae00d753b.png)">
<view
class="container"
style="
background-image: url(https://jiexiu.xuqidata.com:8083/jiexiujumin/3ee992d1442bb8285c37f93a9ee1f93ed6e086131fc514d7b697b2cae00d753b.png);
"
>
<view class="title">介休网格通</view>
<view class="reg-bg">
<image
src="https://jiexiu.xuqidata.com:8083/jiexiujumin/5064115c2e62589da9486151d5bced709ccef7a11063c0f17eddc9654a816d80.png" />
src="https://jiexiu.xuqidata.com:8083/jiexiujumin/5064115c2e62589da9486151d5bced709ccef7a11063c0f17eddc9654a816d80.png"
/>
</view>

<view class="add-commutnity wx-authorize">
<van-form @submit="onSubmit">
<van-cell-group inset>
<van-field v-model="phone" name="手机号" label="手机号" placeholder="请填写手机号" />
<van-field
v-model="phone"
name="手机号"
label="手机号"
placeholder="请填写手机号"
/>
</van-cell-group>
<van-cell-group inset style="margin-top:20rpx">
<van-field v-model="sms" center clearable label="短信验证码" placeholder="请输入短信验证码">
<van-cell-group inset style="margin-top: 20rpx">
<van-field
v-model="sms"
center
clearable
label="短信验证码"
placeholder="请输入短信验证码"
>
<template #button>
<van-button size="small" type="primary" color="#f01b4e" @click="headerCode('codeTitle','timer')" v-if="codeTitle === '发送验证码' || codeTitle === '重新获取'">{{codeTitle}}</van-button>
<van-button size="small" type="primary" color="#f01b4e" v-else>{{codeTitle}}秒</van-button>
<van-button
size="small"
type="primary"
color="#f01b4e"
@click="headerCode('codeTitle', 'timer')"
v-if="codeTitle === '发送验证码' || codeTitle === '重新获取'"
>{{ codeTitle }}</van-button
>
<van-button size="small" type="primary" color="#f01b4e" v-else
>{{ codeTitle }}秒</van-button
>
</template>
</van-field>
</van-cell-group>
<div style="margin: 16px;">
<van-button round block type="primary" native-type="submit" color="#f01b4e">
<div style="margin: 16px">
<van-button
round
block
type="primary"
native-type="submit"
color="#f01b4e"
>
提交
</van-button>
</div>
</van-form>
</view>
<view class="user-agreement">
<checkbox color="#F01B4E" :checked="isAgreementBox" @tap="onAgreementSelect" />
<checkbox
color="#F01B4E"
:checked="isAgreementBox"
@tap="onAgreementSelect"
/>
<view class="checbox-text flex">
<text>已阅读并同意《</text>
<text @tap="onAgreement">用户服务协议</text>
@@ -41,271 +76,290 @@
</template>

<script>
//授权页
// const { loginApi } = app.api;
import * as myApi from '@/api/myApi'; // 我的
export default {
components: {},
data() {
return {
// env: app.globalData.env,
isAgreement: false,
isAgreementChecked: false,
//授权页
// const { loginApi } = app.api;
import * as myApi from "@/api/myApi"; // 我的
export default {
components: {},
data() {
return {
// env: app.globalData.env,
isAgreement: false,
isAgreementChecked: false,

//是否勾选的了用户协议
userInfo: null,
//是否勾选的了用户协议
userInfo: null,

code: '',
isAgreementBox: false,
codeTitle: '发送验证码',
phone: '',
sms: '',
timer: null,
};
},
onLoad() {
code: "",
isAgreementBox: false,
codeTitle: "发送验证码",
phone: "",
sms: "",
timer: null,
};
},
onLoad() {},
methods: {
headerCode(codeTitle, time) {
const vm = this;
let reg =
/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;

},
methods: {
headerCode(codeTitle, time) {
const vm = this;
let reg =
/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
if (vm.phone !== "") {
if (!reg.test(vm.phone)) {
uni.showToast({
title: "你输入的手机格式不正确",
icon: "none",
});
} else {
let TIME_COUNT = 60;
if (!this[time]) {
this[codeTitle] = TIME_COUNT;
this[time] = setInterval(async () => {
if (this[codeTitle] > 0 && this[codeTitle] <= TIME_COUNT) {
this[codeTitle]--;

if (vm.phone !== "") {
if (!reg.test(vm.phone)) {
uni.showToast({
title:"你输入的手机格式不正确",
icon:'none'
})
} else {
let TIME_COUNT = 60;
if (!this[time]) {
this[codeTitle] = TIME_COUNT;
this[time] = setInterval(async () => {
if (
this[codeTitle] > 0 &&
this[codeTitle] <= TIME_COUNT
) {
this[codeTitle]--;
if (this[codeTitle] == 59) {
const res = await myApi.sendSmSCodeApi({
mobile: vm.phone,
scene: 4,
});

if (this[codeTitle] == 59) {
const res = await myApi.sendSmSCodeApi({
mobile:vm.phone,
scene:4
})
console.log(res)
}
} else {
clearInterval(this[time]);
TIME_COUNT = 60
this[time] = null
this[codeTitle] = "重新获取";
console.log(res);
}
}, 1000);
} else {
uni.showToast({
title:"请勿重复点击",
icon:'none'
})
}
} else {
clearInterval(this[time]);
TIME_COUNT = 60;
this[time] = null;
this[codeTitle] = "重新获取";
}
}, 1000);
} else {
uni.showToast({
title: "请勿重复点击",
icon: "none",
});
}
} else {
uni.showToast({
title:"手机号不能为空",
icon:'none'
})
}
},
onAgreementSelect() {
this.isAgreementChecked = !this.isAgreementChecked
this.isAgreement = !this.isAgreement
},
} else {
uni.showToast({
title: "手机号不能为空",
icon: "none",
});
}
},
onAgreementSelect() {
this.isAgreementChecked = !this.isAgreementChecked;
this.isAgreement = !this.isAgreement;
},

onAgreement() {
uni.navigateTo({
url: '/pages/agreement/user-agreement'
onAgreement() {
uni.navigateTo({
url: "/pages/agreement/user-agreement",
});
},
async onSubmit() {
if (this.phone === "" || this.sms === "") {
uni.showToast({
title:
this.phone === ""
? "请输入手机号"
: this.sms === ""
? "请输入验证码"
: "",
icon: "none",
});
},
async onSubmit(){
if(this.phone === '' || this.sms){
uni.showToast({
title:this.phone === ''? '请输入手机号' : this.sms === '' ?'请输入验证码' : '',
icon:'none'
})
return false
}
const res = await myApi.systemAuthSmsLogin({
mobile:this.phone,
code:this.sms,
scene:4
})
console.log(res)
},
onAddCommunity() {
const {
isAgreement
} = this;
if (!isAgreement) {
uni.showToast({
title: '请勾选用户协议',
icon: 'error',
mask: true,
duration: 1000
});
}
},
return false;
}

async getPhoneNumber(e) {
const {
errMsg,
iv,
encryptedData
} = e.detail;
if (errMsg.indexOf('ok') === -1) {
return;
}
this.setData({
numberChecked: true
if (!this.isAgreement) {
uni.showToast({
title: "请勾选用户协议",
icon: "error",
mask: true,
duration: 1000,
});
const res = await app.globalData.register({
avatar: this.userInfo.avatarUrl,
nickName: this.userInfo.nickName,
iv,
encryptedData,
code: this.code
return false;
}
const res = await myApi.systemAuthSmsLogin({
mobile: this.phone,
code: this.sms,
scene: 4,
});

if (res.code === 0) {
uni.showToast({
title: '登录成功',
icon:'none'
})
uni.setStorageSync("userId", res.data.userId);
uni.setStorageSync("token", res.data.accessToken);
uni.switchTab({
url: "/pages/my/my",
});
}else{
uni.showToast({
title: res.data.msg,
icon:'none'
})
}
},
onAddCommunity() {
const { isAgreement } = this;
if (!isAgreement) {
uni.showToast({
title: "请勾选用户协议",
icon: "error",
mask: true,
duration: 1000,
});
// 判断注册成功后,返回到我的页面
if (res) {
uni.reLaunch({
url: '/pages/people/people'
});
}
}
}
};
},

async getPhoneNumber(e) {
const { errMsg, iv, encryptedData } = e.detail;
if (errMsg.indexOf("ok") === -1) {
return;
}
this.setData({
numberChecked: true,
});
const res = await app.globalData.register({
avatar: this.userInfo.avatarUrl,
nickName: this.userInfo.nickName,
iv,
encryptedData,
code: this.code,
});
// 判断注册成功后,返回到我的页面
if (res) {
uni.reLaunch({
url: "/pages/people/people",
});
}
},
},
};
</script>
<style lang="less">
/* pages/authorize/index.wxss */
.container {
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: center;
width: 100%;
height: 100vh;
}
/* pages/authorize/index.wxss */
.container {
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: center;
width: 100%;
height: 100vh;
}

.title {
font-size: 52rpx;
font-weight: 400;
color: #ffffff;
line-height: 60rpx;
letter-spacing: 1rpx;
margin-bottom: 20rpx;
}
.title {
font-size: 52rpx;
font-weight: 400;
color: #ffffff;
line-height: 60rpx;
letter-spacing: 1rpx;
margin-bottom: 20rpx;
}

.reg-bg {
width: 628rpx;
height: 816rpx;
}
.reg-bg {
width: 628rpx;
height: 816rpx;
}

.reg-bg image {
width: 100%;
height: 100%;
}
.reg-bg image {
width: 100%;
height: 100%;
}

.user-agreement {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 100rpx;
.user-agreement {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 100rpx;

.checbox-text {
font-size: 28rpx;
font-weight: 400;
color: #ffffff;
line-height: 28rpx;
}
}

.user-agreement checkbox {
transform: scale(0.6, 0.6);
}

.user-agreement view {
.checbox-text {
font-size: 28rpx;

font-weight: 400;
color: #ffffff;
line-height: 28rpx;
}
}

.wx-authorize {
width: 100%;
padding: 0 30rpx;
// margin-top: 40rpx;
margin-bottom: 38rpx;
}
.user-agreement checkbox {
transform: scale(0.6, 0.6);
}

.add-commutnity {
position: absolute;
top: 35%;
left: 0;
}
.user-agreement view {
font-size: 28rpx;

.add-commutnity-btn,
.wx-authorize-btn {
// width: 648rpx;
font-weight: 400;
color: #ffffff;
line-height: 28rpx;
}

padding: 33rpx 0;
background: linear-gradient(90deg, #fddf23 0%, #ffa2a2 100%);
border-radius: 42rpx;
color: #f01b4e;
line-height: 32rpx;
text-align: center;
font-size: 32rpx;
font-weight: 500;
}
.wx-authorize {
width: 100%;
padding: 0 30rpx;
// margin-top: 40rpx;
margin-bottom: 38rpx;
}

.wx-authorize-btn {
background: linear-gradient(180deg, #029b4d 0%, #108644 100%);
}
.add-commutnity {
position: absolute;
top: 35%;
left: 0;
}

.number-alert-container {
margin-top: 108rpx;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.add-commutnity-btn,
.wx-authorize-btn {
// width: 648rpx;

.number-alert-icon {
width: 144rpx;
height: 144rpx;
display: inline-block;
border: none;
border-radius: 50%;
}
padding: 33rpx 0;
background: linear-gradient(90deg, #fddf23 0%, #ffa2a2 100%);
border-radius: 42rpx;
color: #f01b4e;
line-height: 32rpx;
text-align: center;
font-size: 32rpx;
font-weight: 500;
}

.number-alert-title {
font-size: 32rpx;
font-weight: 500;
color: #293341;
line-height: 32rpx;
margin-top: 38rpx;
margin-bottom: 92rpx;
}
.wx-authorize-btn {
background: linear-gradient(180deg, #029b4d 0%, #108644 100%);
}

.number-alert-btn {
background: #19ba50;
border-radius: 42px;
color: #fff;
}
.number-alert-container {
margin-top: 108rpx;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

.phone-popup {
padding-bottom: 108rpx;
}
</style>
.number-alert-icon {
width: 144rpx;
height: 144rpx;
display: inline-block;
border: none;
border-radius: 50%;
}

.number-alert-title {
font-size: 32rpx;
font-weight: 500;
color: #293341;
line-height: 32rpx;
margin-top: 38rpx;
margin-bottom: 92rpx;
}

.number-alert-btn {
background: #19ba50;
border-radius: 42px;
color: #fff;
}

.phone-popup {
padding-bottom: 108rpx;
}
</style>

Loading…
Cancel
Save