1
wwl
2025-07-31 c3c6cf8cb3f73755ac9fad29f2b2c0cf64f27979
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<template>
    <view class="mainbox">
        <img src="/static/images/loginbg.png" class="bgbox">
        <div class="top">
            <img :src="logoSrc" mode="scaleToFill" alt="" class="logo" @error="handleImageError">
        </div>
        <input type="text" class="nickname" placeholder="手机号码" v-model="loginForm.username">
        <input type="text" class="nickname" placeholder="身份证号" v-model="loginForm.sfzh">
        <input type="password" class="nickname" placeholder="密码默认为身份证号后6位" v-model="loginForm.password">
        <div class="btn" @tap="login" :disabled="loading">
            <div class="txt">{{ loading ? '登录中...' : '登录' }}</div>
        </div>
        <div class="btn1" @tap="edit" :disabled="loading">
            <div class="txt">修改电话</div>
        </div>
    </view>
</template>
<script>
    import {
        login1
    } from '@/api/login'
    import {
        getToken,
        setToken,
        removeToken
    } from '@/utils/auth'
// import {
//     encrypt,decrypt
// } from '@/utils/crypto.js'
    export default {
        name: "Login",
        data() {
            return {
                code: '',
                userInfo: {},
                codeUrl: "",
                val: "",
                canIUseGetUserProfile: false,
                globalConfig: getApp().globalData.config,
                loginForm: {
                    username: "", // 手机号码
                    password: "", // 身份证号后6位
                    mobile: false,
                    sfzh: ""
                },
                loading: false,
                logoSrc: '/static/images/logo.png', // 默认 Logo
            }
        },
        onLoad(options) {
            // 获取传递的 code 参数并设置 logoSrc
 
            if (uni.getStorageSync('hospId')) {
                this.code = uni.getStorageSync('hospId')
                this.logoSrc = `http://47.109.86.30:5902/img/${this.code}-logo.png`;
            }
            uni.showToast({
                title: '加载中...',
                icon: 'loading',
                duration: 500
            });
            if (uni.getUserProfile) {
                this.canIUseGetUserProfile = true;
            }
        },
        onShow() {
            this.localtoken = uni.getStorageSync('localtoken');
            console.log('localtoken:', this.localtoken);
        },
        methods: {
            // 处理图片加载失败
            handleImageError() {
                this.logoSrc = '/static/images/logo.png'; // 加载失败时使用默认本地 Logo
            },
            edit() {
                uni.navigateTo({
                    url: `/pages/edit` // ?code=${this.code}传递 item.code
                });
            },
            // 登录方法
            // 登录页面 script
            login() {
                // 防止重复点击
                if (this.loading) return;
 
                // 校验输入
                const {
                    username,
                    sfzh,
                    password
                } = this.loginForm;
                if (!username || !sfzh || !password) {
                    uni.showToast({
                        title: '请输入完整的账号、身份证号和密码',
                        icon: 'none'
                    });
                    return;
                }
 
                this.loading = true;
                // console.log('loginForm:', this.loginForm);
                // 加密对象
                // let data = JSON.stringify(this.loginForm)
                // const encryptedUserData = encrypt(data);
                // console.log('加密后的数据:', encryptedUserData);
                
                // 解密数据
                // const decryptedUserData = decrypt(encryptedUserData);
                // console.log('解密后的对象:', decryptedUserData);
                // 调用登录 API
                login1(this.loginForm).then((res) => {
                    console.log(res);
                    if (res.code == 200) {
                        // 设置 token
                        setToken(res.token);
                        // 序列化 orderList(如果不存在,传空数组)
                        // const orderList = encodeURIComponent(JSON.stringify(res.orderList || []));
                        // 序列化 sfzh
                        // const sfzh = encodeURIComponent(JSON.stringify(this.loginForm.sfzh));
                        localStorage.setItem('orderList', JSON.stringify(res.orderList));
                        localStorage.setItem('sfzh', JSON.stringify(this.loginForm.sfzh));
                        // 跳转到 friendReport 页面,传递 orderList 和 sfzh
                        uni.reLaunch({
                            // ?orderList=${orderList}&sfzh=${sfzh}
                            url: `/pages/friendReport/friendReport`
                        });
                    } else {
                        uni.showToast({
                            title: '账号或密码错误',
                            icon: 'none'
                        });
                    }
                }).catch((err) => {
                    console.error('Login error:', err);
                    uni.showToast({
                        title: '登录失败,请稍后重试',
                        icon: 'none'
                    });
                }).finally(() => {
                    this.loading = false; // 重置 loading 状态
                });
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .mainbox {
        display: flex;
        height: 1624rpx;
        flex-direction: column;
 
        .bgbox {
            width: 750rpx;
            height: 1624rpx;
            position: absolute;
            z-index: -1;
        }
 
        .top {
            display: flex;
            flex-direction: column;
            align-items: center;
            width: 100%;
            margin-top: 200rpx;
 
            .logo {
                width: 124rpx;
                height: 140rpx;
                margin-bottom: 16rpx;
            }
 
            .logotxt {
                width: 165rpx;
                height: 62rpx;
                margin-bottom: 81rpx;
            }
        }
 
        .nickname {
            width: 540rpx;
            height: 96rpx;
            background: #F4F5F8;
            border-radius: 48rpx;
            margin: 0 auto 40rpx;
            padding-left: 50rpx;
            font-size: 32rpx;
            color: #9496A2;
        }
 
        .btn {
            width: 540rpx;
            height: 96rpx;
            background: #419FFD;
            border-radius: 48rpx;
            margin: 25rpx auto 25rpx;
            display: flex;
            justify-content: center;
            align-items: center;
            opacity: 1;
 
            &[disabled] {
                opacity: 0.6;
            }
        }
 
        .btn1 {
            width: 540rpx;
            height: 96rpx;
            background: #54adff;
            border-radius: 48rpx;
            margin: 25rpx auto 25rpx;
            display: flex;
            justify-content: center;
            align-items: center;
            opacity: 1;
 
            &[disabled] {
                opacity: 0.6;
            }
        }
 
        .txt {
            font-size: 32rpx;
            color: #FFFFFF;
        }
    }
</style>