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 * @param {*} data
@@ -142,7 +150,7 @@ const replyGoodPageApi = function (data) {
const sendSmSCodeApi = function (data) { const sendSmSCodeApi = function (data) {
return request({ return request({
url: '/admin-api/system/auth/send-sms-code', url: '/admin-api/system/auth/send-sms-code',
method: 'get', method: 'post',
data: data data: data
}); });
}; };
@@ -150,7 +158,7 @@ const sendSmSCodeApi = function (data) {
const systemAuthSmsLogin = function (data) { const systemAuthSmsLogin = function (data) {
return request({ return request({
url: '/admin-api/system/auth/sms-login', url: '/admin-api/system/auth/sms-login',
method: 'get', method: 'post',
data: data data: data
}); });
}; };
@@ -167,5 +175,6 @@ export {
replyCreatUpdateApi, replyCreatUpdateApi,
replyGoodPageApi, replyGoodPageApi,
sendSmSCodeApi, sendSmSCodeApi,
systemAuthSmsLogin systemAuthSmsLogin,
getProfileUserInfoApi
}; };

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

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


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

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


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


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

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


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


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


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


code: '', code: "",
isAgreementBox: false, isAgreementBox: false,
codeTitle: '发送验证码', codeTitle: "发送验证码",
phone: '', phone: "",
sms: '', sms: "",
timer: null, timer: null,
}; };
}, },
onLoad() { 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}$/;


}, if (vm.phone !== "") {
methods: { if (!reg.test(vm.phone)) {
headerCode(codeTitle, time) { uni.showToast({
const vm = this; title: "你输入的手机格式不正确",
let reg = icon: "none",
/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/; });
} 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 (this[codeTitle] == 59) {
if (!reg.test(vm.phone)) { const res = await myApi.sendSmSCodeApi({
uni.showToast({ mobile: vm.phone,
title:"你输入的手机格式不正确", scene: 4,
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) { console.log(res);
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] = "重新获取";
} }
}, 1000); } else {
} else { clearInterval(this[time]);
uni.showToast({ TIME_COUNT = 60;
title:"请勿重复点击", this[time] = null;
icon:'none' this[codeTitle] = "重新获取";
}) }
} }, 1000);
} else {
uni.showToast({
title: "请勿重复点击",
icon: "none",
});
} }
} else {
uni.showToast({
title:"手机号不能为空",
icon:'none'
})
} }
}, } else {
onAgreementSelect() { uni.showToast({
this.isAgreementChecked = !this.isAgreementChecked title: "手机号不能为空",
this.isAgreement = !this.isAgreement icon: "none",
}, });
}
},
onAgreementSelect() {
this.isAgreementChecked = !this.isAgreementChecked;
this.isAgreement = !this.isAgreement;
},


onAgreement() { onAgreement() {
uni.navigateTo({ uni.navigateTo({
url: '/pages/agreement/user-agreement' url: "/pages/agreement/user-agreement",
});
},
async onSubmit() {
if (this.phone === "" || this.sms === "") {
uni.showToast({
title:
this.phone === ""
? "请输入手机号"
: this.sms === ""
? "请输入验证码"
: "",
icon: "none",
}); });
}, return false;
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
});
}
},


async getPhoneNumber(e) { if (!this.isAgreement) {
const { uni.showToast({
errMsg, title: "请勾选用户协议",
iv, icon: "error",
encryptedData mask: true,
} = e.detail; duration: 1000,
if (errMsg.indexOf('ok') === -1) {
return;
}
this.setData({
numberChecked: true
}); });
const res = await app.globalData.register({ return false;
avatar: this.userInfo.avatarUrl, }
nickName: this.userInfo.nickName, const res = await myApi.systemAuthSmsLogin({
iv, mobile: this.phone,
encryptedData, code: this.sms,
code: this.code 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> </script>
<style lang="less"> <style lang="less">
/* pages/authorize/index.wxss */ /* pages/authorize/index.wxss */
.container { .container {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: flex-end; justify-content: flex-end;
align-items: center; align-items: center;
width: 100%; width: 100%;
height: 100vh; height: 100vh;
} }


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


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


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


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


.checbox-text { .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 {
font-size: 28rpx; font-size: 28rpx;

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


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


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


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


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


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


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


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


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


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


.phone-popup { .number-alert-icon {
padding-bottom: 108rpx; width: 144rpx;
} height: 144rpx;
</style> 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>

||||||
x
 
000:0
Loading…
Cancel
Save