shortPlay-mini/pages/entry/entry.vue

142 lines
2.6 KiB
Vue
Raw Permalink Normal View History

2024-03-29 10:16:19 +08:00
<template>
<view>
<view class="img-a">
<image src="../../static/head.png" mode="aspectFill"></image>
<view class="t-b">
您好
<br />
欢迎使用 种草短剧
</view>
</view>
<view class="login-view" style="">
<view class="t-login">
<form class="cl">
<button @tap="login()">微信登录/注册</button>
<view class="reg" @tap="navigateTo('/pages/login/login')">账号密码登录</view>
</form>
</view>
</view>
</view>
</template>
<script>
import {
codeGetOpenID,
loginByOpenid
} from '@/api/index.js'
import { mapMutations } from 'vuex'
export default {
data() {
return {
};
},
onLoad() {},
methods: {
...mapMutations(['setToken', 'setUserInfo']),
//当前登录按钮操作
login() {
this.getOpenId()
},
async getOpenId() {
const code = await this.authLogin()
const res = await codeGetOpenID({code})
this.setToken(res.msg)
const res1 = await loginByOpenid({openid: res.msg})
this.setUserInfo(res1.data)
if(res1.data.phone && res1.data.password) {
uni.showToast({ title: '登录成功!', icon: 'success' });
uni.reLaunch({
url: '/pages/home/mini/mini'
})
} else {
uni.navigateTo({
url: '/pages/register/register'
})
}
},
authLogin() {
return new Promise((resolve, reject) => {
uni.login({
provider: 'weixin',
success: (res) => {
console.log('code', res.code);
if (res.errMsg == 'login:ok') {
resolve(res.code)
} else {
reject('登录失败')
}
}
})
})
}
}
};
</script>
<style lang="scss">
page{
background-color: #ffffff;
}
.txt {
font-size: 32rpx;
font-weight: bold;
color: #333333;
}
.img-a {
width: 100%;
height: 550rpx;
overflow: hidden;
position: relative;
}
.img-a image {
width: 100%;
height: 550rpx;
}
.reg {
font-size: 35rpx;
color: #fff;
height: 90rpx;
line-height: 90rpx;
border-radius: 50rpx;
background: #f5f6fa;
color: #000000;
text-align: center;
margin-top: 40rpx;
}
.login-view {
width: 100%;
position: relative;
margin-top: -120rpx;
background-color: #ffffff;
border-radius: 40rpx 40rpx 0 0;
}
.t-login {
width: 85vw;
margin: 0 auto;
font-size: 28rpx;
padding-top: 80rpx;
}
.t-login button {
font-size: 35rpx;
background: #2796f2;
color: #fff;
height: 90rpx;
line-height: 90rpx;
border-radius: 50rpx;
}
.t-b {
text-align: left;
font-size: 42rpx;
color: #ffffff;
padding: 130rpx 0 0 70rpx;
font-weight: bold;
line-height: 70rpx;
position: absolute;
top: 0;
left: 0;
}
</style>