uniapp微信小程序登录

<template>
    <view class="vue_page">
        <!-- html start -->
        <view class="navbar">
            <view class="title_main">
                <text>海川检测</text>
            </view>
            <image class="logobg" src="../../static/images/loginbg.jpg" mode=""></image>
            <image class="logo" src="../../static/images/logo.jpg" mode=""></image>
        </view>

        <view style="margin-top: 400rpx;" v-if="flag">
            <view style="color: #444;font-size: 32rpx;font-weight: bold;text-align: center;margin-bottom: 50rpx;">
                请完成微信授权以继续使用</view>
            <view class="vue_main">
                <button @click="getPhoneNumber">授权微信用户信息</button>
            </view>
        </view>
        <view style="margin-top: 250rpx;text-align: center;" v-else>
            <view class="vue_main">
                <button type="default" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber">获取手机号</button>
                <view style="margin-top: 30rpx;">登录即表示您同意《用户隐私协议》</view>
            </view>
        </view>
        <!-- html end -->
    </view>
</template>

<script>
    export default {
        data() {
            return {
                // data start
                imageUrlone: this.$globalPath.img,
                flag: true,
                // data end
            }
        },
        onLoad() {},
        methods: {
            // methods start
            getPhoneNumber(e) {
                uni.getUserProfile({
                    desc: '登录',
                    lang: 'zh_CN',
                    success: (el) => {
                        uni.login({
                            success: (e) => {
                                // 请求 start
                                let obj = {
                                    userInfo: el.userInfo,
                                    iv: el.iv,
                                    signature: el.signature,
                                    encryptedData: el.encryptedData,
                                    code: e.code
                                }
                                uni.setStorageSync('arg', JSON.stringify(obj))
                                this.flag = false
                            }
                        })
                    }
                })
            },
            onGetPhoneNumber(e) {
                let options = JSON.parse(uni.getStorageSync('arg'));
                uni.showLoading({
                    title: '登录中'
                })
                this.$u.api.http({
                    method: 'post',
                    url: this.$globalPath.login,
                    data: {
                        ...options,
                        phoneCode: e.detail.code
                    },
                }).then(res => {
                    uni.hideLoading()
                    if (res.code === 200) {
                        uni.setStorageSync('token', res.result.token);
                        uni.setStorageSync('userInfo', res.result.userInfo);
                        uni.setStorageSync('role', res.result.role);
                        uni.switchTab({
                            url: '../index/index'
                        });
                    } else {
                        uni.showToast({
                            icon: 'error',
                            title: res.message
                        });
                    }
                })
            },
            // methods end
        }
    }
</script>

<style scoped lang="scss">
    // 头部
    .navbar {
        width: 750rpx;
        position: relative;
        // background-image: url('~@/static/images/myachievement.png');
        // background-image: url('../../../static/images/myachievement.png');
    }

    .navbar>.logobg {
        width: 750rpx;
        position: fixed;
        width: 100%;
        height: 800rpx;
        top: 0;
        left: 0;
        z-index: -1;
    }

    .navbar>.logo {
        width: 220rpx;
        height: 220rpx;
        margin-top: 200rpx;
        margin-left: 200rpx;
    }

    .title_main {
        font-size: 36rpx;
        font-weight: bold;
        color: #fff;
        margin-top: 90rpx;
        z-index: 11111;
        width: 750rpx;
    }

    .navbar>view>text {
        padding-left: 180rpx;
    }


    .vue_page {
        padding-left: 52rpx;
        padding-right: 52rpx;
    }

    .vue_logo {
        padding-top: 20vh;
    }

    .logo {
        display: block;
        margin-left: auto;
        margin: auto;
        width: 200rpx;
        height: 200rpx;
    }

    .vue_main>button {
        background-image: linear-gradient(to bottom right, #1576ff, #1576ff);
        color: #fff;
        font-size: 40rpx;
        width: 500rpx;
    }

    .vue_footer {
        margin-top: 36rpx;
        color: #666;
        font-size: 28rpx;

        navigator {
            display: inline-block;
            color: $themeColor;
            padding: 0 12rpx;
        }
    }

    .btn_a {
        color: #ff0000 !important;
    }

    .vue_btn {
        height: 100rpx;
        line-height: 100rpx;
        border-radius: 50rpx;
        border: 1px solid $themeColor;
        box-sizing: border-box;
        margin-top: 30rpx;
        color: $themeColor;
        text-align: center;
        font-size: 30rpx;
    }
</style>
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值