123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- <template>
- <view class="app-login-page">
- <view class="app-login">
- <view class="app-icon u-m-b-30 ">
- <image src="https://sylwt.top/api/visitor/resources/image?name=/ydl/menber-center/login-icon.png"
- mode="aspectFit" style="height: 40px;"></image>
- </view>
- <view class="app-title u-m-b-60">
- 欢迎使用会员中心系统小程序
- </view>
- <view style="height: 25vh;">
- <u-button v-if="userBook" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber" class="custom-button" style="width: 40px;" plain :hair-line="false">
- <view class="login-button">
- 本机号码一键登录
- </view>
- </u-button>
- <u-button v-else class="custom-button" style="width: 40px;" plain :hair-line="false" @click="check">
- <view class="login-button">
- 本机号码一键登录
- </view>
- </u-button>
- <view class="login-button other-button u-m-b-50 u-m-t-50" @click="toLogin">
- 其他手机号/账号登录
- </view>
- </view>
- <view class="app-user-book mb-30">
- <u-checkbox-group style="display: flex;justify-content: center;">
- <u-checkbox v-model="userBook" name="yes" shape="circle">我已阅读《运营商一键登录服务协议》</u-checkbox>
- </u-checkbox-group>
- </view>
- </view>
- <u-modal v-model="userBookModal" mask-close-able class="modal" show-cancel-button
- :title-style="{fontWeight: 'bold'}" @confirm="confirmModal">
- <view class="modal-content">
- 为了更好地保障你的合法权益,进行下一步前,请阅读并同意
- <text class="content-a">《运营商一键登录服务协议》</text>
- </view>
- </u-modal>
- </view>
- </template>
- <script setup>
- import { wxLoginOpenid, wxloginPhone } from '@/api/login.js'
- import {
- msg,
- msgSuccess
- } from "@/utils/common.js"
- import { ref } from 'vue'
- import {
- useAuthStore
- } from '@/store/authStore'
- const authStore = useAuthStore()
- const userBook = ref(false)
- const userBookModal = ref(false)
- function toLogin() {
- uni.navigateTo({
- url: "/pages/login/login"
- })
- }
- async function wxlogin(){
-
-
- const loginRes = await wx.login();
- const code = loginRes.code;
- wxLoginOpenid({code}).then(res=>{
- if(res?.data){
- const { openid, sessionKey } = res.data
-
- }
- })
- }
-
- function confirmModal() {
- userBook.value = true
- // this.wxlogin()
- }
-
- function checkUserBook() {
- if (!userBook.value) {
- userBookModal.value = true
- return false;
- }
- return true
- }
-
- function check(){
- if (!checkUserBook()) return;
- }
-
- async function decryptPhoneNumber(e){
- if (e.detail.encryptedData) {
- const {
- encryptedData,
- iv,
- code
- } = e.detail;
- const loginRes = await wx.login();
- const wxcode = loginRes.code;
- try{
- const openidRes = await wxLoginOpenid({code : wxcode})
- if(openidRes?.data){
- const { openid, sessionKey } = openidRes.data
- const phoneRes = await wxloginPhone({ openid, phoneCode: code})
- const { phone, token, isNewUser } = phoneRes.data;
- authStore.setPhone(phone);
- authStore.setAuthToken(token);
- uni.reLaunch({
- url: "/pages/register/register?mode=refine"
- })
- // if(isNewUser){
- // //新用户,跳转:完善用户信息
- // // console.log("完善用户信息")
- // uni.reLaunch({
- // url: "/pages/register/register?mode=refine"
- // })
- // }else{
- // // 老用户,跳转至:首页
- // msgSuccess("授权成功!")
- // setTimeout(()=>{
- // uni.switchTab({
- // url: "/pages/index/index"
- // })
- // }, 1000)
- // }
- }
- }catch(err){
- console.log("ee", err)
- }
-
- // 将 encryptedData 和 iv 发送到后端进行解密
- } else {
- msg('取消授权手机号');
- }
- }
- </script>
- <style lang="scss">
- .form-item .u-input--border {
- border-radius: 16rpx !important;
- }
- .custom-button {
- .u-btn {
- display: block !important;
- width: fit-content;
- padding: 0 !important;
- border-radius: 50rpx;
- }
- .u-btn--default {
- border: none !important;
- background-color: transparent !important;
- }
- }
- </style>
- <style lang="scss" scoped>
- .app-login-page {
- background-color: #ffffff;
- width: 100vw;
- height: 100vh;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .app-login {
- width: 90%;
- }
- .app-icon {
- text-align: center;
- }
- .app-title {
- text-align: center;
- font-size: 44rpx;
- letter-spacing: 2px;
- font-weight: 700;
- }
- .mb-30 {
- margin-bottom: 30rpx;
- }
-
- .login-button {
- background: linear-gradient(90deg, #006af5, #21b0fc);
- border-radius: 20rpx;
- line-height: 80rpx;
- text-align: center;
- color: #fff;
- margin-bottom: 50rpx;
- width: 550rpx;
- margin: 0 auto;
- font-size: 32rpx;
- letter-spacing: 4rpx;
- }
- .other-button{
- color: #006af5;
- background: #e5e5e5;
- }
-
- // 用户手册模拟态
- .modal {
- .modal-content {
- padding: 50rpx;
-
- .content-a {
- color: #2979ff;
- }
- }
- }
- </style>
|