Commit 2ea31414 authored by 罗超's avatar 罗超

2

parent 1e6ff93a
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
.Order_Number { .Order_Number {
color: #0000ff; color: #0000ff;
font-size: 28rpx; font-size: 24rpx;
} }
.courseName { .courseName {
......
<template> <template>
<view class="indexassembly"> <view class="indexassembly" :style="{width:width,height:height}">
<view> <view>
<slot> <slot>
登录 登录
</slot> </slot>
<button class="hotsopt" style="" open-type="getUserInfo" @tap="getUserProfile()" @click="getCode"></button> <button class="hotsopt" :style="{width:width,height:height}" open-type="getUserInfo" @tap="getUserProfile()"
@click="getCode"></button>
</view> </view>
<van-popup :show="showPhone"> <van-popup :show="showPhone">
<view <view
style="width: 70vw;background: #FFF;display: flex;flex-direction: column;align-items: center;padding-bottom: 20px;border-radius: 8px;"> style="width: 70vw;background: #FFF;display: flex;flex-direction: column;align-items: center;padding-bottom: 20px;border-radius: 8px;">
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<text style="margin-top: 15px;font-size: 18px;font-weight: bold;color: #111111;">{{obj.Name}}</text> <text style="margin-top: 15px;font-size: 18px;font-weight: bold;color: #111111;">{{obj.Name}}</text>
<text style="margin-top: 5px;font-size: 13px;color: #111111;">申请获取您微信绑定的手机号码</text> <text style="margin-top: 5px;font-size: 13px;color: #111111;">申请获取您微信绑定的手机号码</text>
<view class="btn">获取手机号 <view class="btn">获取手机号
<button type="default" open-type="getPhoneNumber" v-if="showLogin == true" <button type="default" open-type="getPhoneNumber" v-if="showLogin == true"
style="position: absolute;left: 0;top: 0;width: 100%;height: 100%;opacity: 0;" style="position: absolute;left: 0;top: 0;width: 100%;height: 100%;opacity: 0;"
@getphonenumber=" decryptPhoneNumber"></button> @getphonenumber=" decryptPhoneNumber"></button>
</view> </view>
...@@ -33,34 +33,46 @@ ...@@ -33,34 +33,46 @@
reactive, reactive,
toRefs, toRefs,
onMounted, onMounted,
getCurrentInstance, getCurrentInstance,
inject inject
} from "vue"; } from "vue";
import { import {
login, login,
phoneLogin, phoneLogin,
parsePhone parsePhone
} from "../../../api/index"; } from "../../../api/index";
export default { export default {
name: "", name: "",
props: { props: {
state: String, state: String,
width: {
type: String,
default: '100rpx'
},
height: {
type: String,
default: '100rpx'
},
}, },
components: {}, components: {},
setup(props,{attrs,slots,emit}) { setup(props, {
attrs,
slots,
emit
}) {
const pages = getCurrentPages() // 获取栈实例 const pages = getCurrentPages() // 获取栈实例
const currentRoute = pages[pages.length-1].route; // 获取当前页面路由 const currentRoute = pages[pages.length - 1].route; // 获取当前页面路由
let Toast = inject("$toast"); let Toast = inject("$toast");
let data = reactive({ let data = reactive({
obj: { obj: {
Name: '', Name: '',
Photo: '', Photo: '',
}, },
showPhone: false, showPhone: false,
showLogin:true,//多次点击 showLogin: true, //多次点击
}); });
let methods = { let methods = {
getUserProfile() { getUserProfile() {
...@@ -72,9 +84,9 @@ ...@@ -72,9 +84,9 @@
data.obj.Name = info.userInfo.nickName; data.obj.Name = info.userInfo.nickName;
data.obj.Photo = info.userInfo.avatarUrl; data.obj.Photo = info.userInfo.avatarUrl;
data.showPhone = true; //显示获取手机号码弹窗 data.showPhone = true; //显示获取手机号码弹窗
if(currentRoute=="pages/index/index"){ if (currentRoute == "pages/index/index") {
uni.hideTabBar()//手机授权弹窗出现 隐藏tabbar uni.hideTabBar() //手机授权弹窗出现 隐藏tabbar
} }
}, },
fail: () => { fail: () => {
uni.showToast({ uni.showToast({
...@@ -95,7 +107,7 @@ ...@@ -95,7 +107,7 @@
data.obj.iv = e.detail.iv data.obj.iv = e.detail.iv
data.obj.encryptedData = e.detail.encryptedData data.obj.encryptedData = e.detail.encryptedData
// that.getCode() // that.getCode()
that.parsePhoneNum(data.obj.encryptedData, data.obj.iv,data.obj.code) that.parsePhoneNum(data.obj.encryptedData, data.obj.iv, data.obj.code)
} }
}, },
getCode() { //获取code getCode() { //获取code
...@@ -108,7 +120,7 @@ ...@@ -108,7 +120,7 @@
success: (res) => { success: (res) => {
//获取code //获取code
data.obj.code = res.code data.obj.code = res.code
}, },
fail: () => { fail: () => {
uni.showToast({ uni.showToast({
...@@ -127,10 +139,10 @@ ...@@ -127,10 +139,10 @@
}); });
}, },
//解密手机号 //解密手机号
async parsePhoneNum(encryptedData, iv, code) { async parsePhoneNum(encryptedData, iv, code) {
uni.showLoading({ uni.showLoading({
title: "登录中", title: "登录中",
}); });
data.showLogin = false; //防止多次点击登录 data.showLogin = false; //防止多次点击登录
let res = await parsePhone({ let res = await parsePhone({
encryptedData, encryptedData,
...@@ -138,27 +150,27 @@ ...@@ -138,27 +150,27 @@
code code
}) })
if (res && res.Data.phoneNumber) { if (res && res.Data.phoneNumber) {
data.obj.phoneNum = res.Data.phoneNumber data.obj.phoneNum = res.Data.phoneNumber
// data.obj.phoneNum = '18328620563' // data.obj.phoneNum = '18328620563'
data.obj.openid = res.Data.openid data.obj.openid = res.Data.openid
data.obj.unionid = res.Data.unionid data.obj.unionid = res.Data.unionid
that.phoneNumLogin() that.phoneNumLogin()
let obj = { let obj = {
Account :data.obj.phoneNum, Account: data.obj.phoneNum,
WeChatName :data.obj.Name, WeChatName: data.obj.Name,
WeChatPhoto :data.obj.Photo, WeChatPhoto: data.obj.Photo,
OpenId: data.obj.openid, OpenId: data.obj.openid,
unionid: data.obj.unionid, unionid: data.obj.unionid,
} }
try { try {
uni.setStorageSync("temporarydh", obj); uni.setStorageSync("temporarydh", obj);
} catch (e) { } catch (e) {
console.log(e,'eeeeeee') console.log(e, 'eeeeeee')
} }
} else { } else {
Toast.fail("授权失败,请重新授权") Toast.fail("授权失败,请重新授权")
data.showLogin = true; //防止多次点击登录 data.showLogin = true; //防止多次点击登录
uni.hideLoading(); uni.hideLoading();
} }
}, },
...@@ -169,32 +181,32 @@ ...@@ -169,32 +181,32 @@
OpenId: data.obj.openid, OpenId: data.obj.openid,
unionid: data.obj.unionid, unionid: data.obj.unionid,
}) })
if (res.Code==1) { if (res.Code == 1) {
uni.hideLoading(); uni.hideLoading();
data.showLogin = true; //防止多次点击登录 data.showLogin = true; //防止多次点击登录
res.Data.Account = data.obj.phoneNum; res.Data.Account = data.obj.phoneNum;
uni.setStorageSync("userInfo", res.Data); uni.setStorageSync("userInfo", res.Data);
Toast.success("登录成功"); Toast.success("登录成功");
emit('success') emit('success')
data.showPhone = false data.showPhone = false
uni.showTabBar() uni.showTabBar()
}else{ } else {
data.showLogin = true; //防止多次点击登录 data.showLogin = true; //防止多次点击登录
data.showPhone = false data.showPhone = false
if(currentRoute=="pages/index/index"){ if (currentRoute == "pages/index/index") {
uni.showTabBar()//手机授权弹窗出现 隐藏tabbar uni.showTabBar() //手机授权弹窗出现 隐藏tabbar
} }
uni.hideLoading(); uni.hideLoading();
if(res.Data.Error==-1){//如果没找到电话号码 就跳入登录 if (res.Data.Error == -1) { //如果没找到电话号码 就跳入登录
// setTimeout(() => { // setTimeout(() => {
// uni.reLaunch({ // uni.reLaunch({
// url: '/pages/login/login' // url: '/pages/login/login'
// }); // });
// }, 1000); // }, 1000);
} }
} }
} }
}; };
...@@ -212,8 +224,6 @@ ...@@ -212,8 +224,6 @@
</script> </script>
<style scoped> <style scoped>
.indexassembly { .indexassembly {
width: 110rpx;
height: 90rpx;
line-height: 90rpx; line-height: 90rpx;
position: relative; position: relative;
} }
...@@ -226,9 +236,6 @@ ...@@ -226,9 +236,6 @@
opacity: 0; opacity: 0;
left: 0; left: 0;
top: 0; top: 0;
width: 280rpx;
height: 90rpx;
} }
.btn { .btn {
......
...@@ -18,21 +18,22 @@ ...@@ -18,21 +18,22 @@
</van-field> </van-field>
</van-cell-group> </van-cell-group>
</view> </view>
<view class="flex flex_between_center btnBox"> <view class="btnBox" @click="login">
<view class="loginBtn flex flex_center_center" @click="login">账号登录</view> 账号登录
<view class="phoneBtn flex flex_center_center" @click="show=true">游客登录</view>
<!-- <button class="phoneBtn flex flex_center_center" open-type="getPhoneNumber" @getphonenumber="getphonenumber" @click="login2">手机号一键登录</button> -->
</view> </view>
<view class="btnBox" style="margin:20rpx auto 0;"> <view class="flex_center_center">
<indexassembly @success='againdata' > <indexassembly width="440rpx" height="90rpx" @success='againdata' >
<view class="loginBtn flex flex_center_center" style="background-color:#4C50E7;">授权登录</view> <view class="btnBox authBtn" >
授权登录
</view>
</indexassembly> </indexassembly>
</view> </view>
<view class="visitor" @click="show=true">
游客登录
</view>
<van-toast id="van-toast" /> <van-toast id="van-toast" />
<van-dialog :show='show' title="提示" message='游客登录,不能使用全部功能!' show-cancel-button @cancel='show = false' <van-dialog :show='show' title="提示" message='游客登录,不能使用全部功能!' show-cancel-button @cancel='show = false'
@confirm='login3'> @confirm='login3'>
</van-dialog> </van-dialog>
</view> </view>
</template> </template>
...@@ -304,14 +305,30 @@ ...@@ -304,14 +305,30 @@
} }
.btnBox { .btnBox {
width: 600rpx; width: 440rpx;
height: 90rpx; height: 90rpx;
border-radius: 12rpx; border-radius: 45rpx;
overflow: hidden; overflow: hidden;
margin: 0 auto; margin: 0 auto;
font-size: 32rpx; margin-bottom: 55rpx;
background-color: #4C50E8;
font-size: 30rpx;
font-family: PingFang SC; font-family: PingFang SC;
font-weight: 500; font-weight: 500;
color: #ffffff; color: #FFFFFF;
text-align: center;
line-height: 88rpx;
}
.authBtn{
background-color: #EDEDFD !important;
color: #4C50E8 !important;
}
.visitor{
text-align: center;
font-size: 28rpx;
font-family: PingFang SC;
font-weight: 500;
color: #BEBEBE;
margin-top: 55rpx;
} }
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment