Novecane
2025-02-17 ff934f8fc407d0aadefc3303994613d64178120e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<script setup>
    import {
        wxLoginApi
    } from '@/api/index.js'
    import {
        onMounted,
        ref
    } from 'vue'
    import {
        BASE_URL
    } from '@/config/config.js';
    const baseUrl = ref(BASE_URL)
 
 
    //用户点击微信登录默认授权
    function wxLogin() {
        if (!uni.getStorageSync('openId') || !uni.getStorageSync('token')) {
            wx.login({
                success: async (res1) => {
                    //存储微信登录的code,调用后端接口传递code参数,返回openid(也就是userId)存储到本地,通过判断本地是否存在openId,存在表示已登录
                    uni.setStorageSync('code', res1.code)
                    await wxLoginApi({
                        code: res1.code
                    }).then((res2) => {
                        if (res2.code == 200) {
                            uni.redirectTo({
                                url: '/pages/layout/index'
                            })
                            uni.setStorageSync('openId', res2.data.userId)
                            uni.setStorageSync('token', res2.data.token)
                        } else {
                            uni.showToast({
                                title: '登录失败',
                                icon: 'none',
                            })
                        }
                    })
                },
                fail: (e) => {
                    uni.showToast({
                        title: '微信登录失败,请退出重试!',
                        duration: 2000,
                        icon: 'fail'
                    });
                }
            })
        }else{
            uni.redirectTo({
                url: '/pages/layout/index'
            })
        }
    }
</script>
 
<template>
    <view class="container">
        <view class="content">
            <!-- 顶部品牌区 -->
            <view class="brand-section">
                <image class="logo" src="../../static/images/login/sxwllogo.png" mode="aspectFit"></image>
                <text class="brand-name">智能物联平台</text>
<!--                 <text class="brand-subtitle"></text> -->
            </view>
 
            <!-- 登录主体 -->
            <view class="auth-section">
                <view class="welcome-text">
                    <text class="welcome-ch">欢迎登录</text>
                    <text class="welcome-en">Welcome Back</text>
                </view>
                <!-- 微信登录按钮 -->
                <view class="wx-login-btn" @click="wxLogin">
                    <image class="wx-icon" src="../../static/images/login/wx.png"></image>
                    <text class="btn-text">微信一键登录</text>
                </view>
            </view>
        </view>
        <!-- 底部装饰 -->
        <view class="decor-circle circle-1"></view>
        <view class="decor-circle circle-2"></view>
    </view>
</template>
 
<style lang="scss" scoped>
    .container {
        height: 100vh;
        background: linear-gradient(135deg, #4a90e2 0%, #5bc0de 100%);
        position: relative;
        overflow: hidden;
 
        .content {
            padding: 0 40rpx;
            position: relative;
            z-index: 2;
        }
 
        /* 品牌标识 */
        .brand-section {
            padding-top: 120rpx;
            text-align: center;
 
            .logo {
                width: 160rpx;
                height: 160rpx;
                border-radius: 24rpx;
                box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.1);
            }
 
            .brand-name {
                display: block;
                font-size: 48rpx;
                color: #fff;
                margin: 40rpx 0 16rpx;
                letter-spacing: 2rpx;
                font-weight: 500;
            }
 
            .brand-subtitle {
                font-size: 28rpx;
                color: rgba(255, 255, 255, 0.9);
            }
        }
 
        /* 登录区域 */
        .auth-section {
            margin-top: 120rpx;
            background: rgba(255, 255, 255, 0.95);
            border-radius: 40rpx;
            padding: 60rpx 40rpx;
            box-shadow: 0 20rpx 60rpx rgba(0, 0, 0, 0.1);
 
            .welcome-text {
                text-align: center;
                margin-bottom: 80rpx;
 
                .welcome-ch {
                    display: block;
                    font-size: 44rpx;
                    color: #333;
                    font-weight: 500;
                    margin-bottom: 16rpx;
                }
 
                .welcome-en {
                    font-size: 28rpx;
                    color: #888;
                    letter-spacing: 2rpx;
                }
            }
 
            /* 微信登录按钮 */
            .wx-login-btn {
                background: #07c160;
                height: 96rpx;
                border-radius: 48rpx;
                display: flex;
                align-items: center;
                justify-content: center;
                transition: all 0.2s;
 
                &:active {
                    transform: scale(0.98);
                    opacity: 0.9;
                }
 
                .wx-icon {
                    width: 48rpx;
                    height: 48rpx;
                    margin-right: 20rpx;
                }
 
                .btn-text {
                    color: #fff;
                    font-size: 34rpx;
                    font-weight: 500;
                }
            }
 
            /* 分隔线 */
            .divider {
                margin: 60rpx 0;
                display: flex;
                align-items: center;
 
                .divider-line {
                    flex: 1;
                    height: 1px;
                    background: #eee;
                }
 
                .divider-text {
                    padding: 0 30rpx;
                    color: #999;
                    font-size: 26rpx;
                }
            }
        }
    }
</style>