李旭东
2023-12-08 7efc6ed86025b610cab109a2e9f83362740d8ed4
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<template>
    <view class="login_index">
        <view class="login_header">
            <view class="login_header_title">
                <!-- 登录 -->
            </view>
            <view class="login_header_icon">
                <u-image src="@/static/login-icon.png" width="70px" height="70px"></u-image>
            </view>
        </view>
        <view class="login_content">
            <view class="login_content_title">
                管片数字工厂
            </view>
            <view class="login_content_form">
                <u-form
                    ref="form"
                    :model="formLogin"
                    :rules="rulesLogin">
                    <u-form-item prop="username" borderBottom>
                        <u-input 
                            v-model="formLogin.username" 
                            border="none" 
                            placeholder="请输入手机号码"
                            clearable>
                            <template slot="prefix">
                                <u-icon name="account" label="|" labelColor="#EDEDED" labelSize="12px"></u-icon>
                            </template>
                        </u-input>
                    </u-form-item>
                    <u-form-item prop="password" borderBottom>
                        <u-input 
                            v-model="formLogin.password" 
                            border="none"
                            clearable
                            placeholder="请输入密码"
                            type="password">
                            <template slot="prefix">
                                <u-icon name="lock" label="|" labelColor="#EDEDED" labelSize="12px"></u-icon>
                            </template>
                        </u-input>
                    </u-form-item>
                    <!-- <u-text type="primary" text="立即注册" @click="navGotoRegister()"></u-text> -->
                    <u-text type="primary" text="管理员电话:13800138008"></u-text>
                    <view class="login_content_button">
                        <u-button 
                            type="primary" 
                            :color="colorStyle"
                            @click="submitForm()">登录
                        </u-button>
                    </view>
                </u-form>
                <view class="login_content_info">
                    <!-- 登录代表你已同意<span>《用户协议》</span>和<span>《隐私政策》</span> -->
                </view>
            </view>
        </view>
    </view>
</template>
 
<script>
import { throttle } from '../../plugins/public';
    export default {
        data() {
            return {
                formLogin: {
                    // username: '18103009188',
                    username: '',
                    password: ''
                },
                rulesLogin: {
                    username: [{
                        required: true,
                        message: '请输入手机号码',
                        trigger: 'blur',
                    },
                    {
                        // 自定义验证函数,见上说明
                        validator: (rule, value, callback) => {
                            return uni.$u.test.mobile(value);
                        },
                        message: '请输入正确的手机号码',
                        trigger: 'blur',
                    }],
                    password: [{
                        required: true,
                        message: '请输入密码',
                        trigger: 'blur',
                    }]
                },
                colorStyle: 'linear-gradient(to right, rgb(79, 142, 244), rgb(85, 109, 254))'
            }
        },
        onShow() {
            const that = this;
            // uni.clearStorage();
            // uni.clearStorageSync();
            // wx.getSetting({
            //     complete: (info) => {
            //         if(!info.authSetting['scope.userInfo']) {
            //             uni.showModal({
            //                 title: '提示',
            //                 content: '是否授权获取您的信息,该信息仅用于确认身份信息',
            //                 success: function (res) {
            //                     if (res.confirm) {
            //                         wx.login({
            //                             success(res) {
            //                                 uni.$u.toast('授权成功!');
            //                                 that.$api.system.getUserInfo(res.code).then((res) => {
            //                                     if(res.success) {
            //                                         uni.setStorageSync('openId', res.data.openid);
            //                                         that.$api.system.changeWChartUser({
            //                                             openId: res.data.openid
            //                                         }).then((reslut) => {
            //                                             console.log(reslut);
            //                                             that.switchUserInfo(reslut.data.regstatus, reslut.data.reginfo);
            //                                         })
            //                                     } else {
            //                                         uni.$u.toast(res.statusMsg);
            //                                     }
            //                                 })
            //                             },
            //                             fail: (err) => {
            //                                 console.log(err,'---');
            //                             }
            //                         })
            //                     } else if (res.cancel) {
            //                         wx.exitMiniProgram({
            //                             success: (res) => {
            //                                 console.log(res,'--');
            //                             }
            //                         })
            //                     }
            //                 }
            //             });
            //         } else {
            //             wx.login({
            //                 success(res) {
            //                     that.$api.system.getUserInfo(res.code).then((res) => {
            //                         if(res.success) {
            //                             uni.setStorageSync('openId', res.data.openid);
            //                             that.$api.system.changeWChartUser({
            //                                 openId: res.data.openid
            //                             }).then((reslut) => {
            //                                 that.switchUserInfo(reslut.data.regstatus, reslut.data.reginfo);
            //                                 // uni.navigateTo({
            //                                 //     url: '../../robePages/safeManage/addHidden'
            //                                 // })
            //                             })
            //                         } else {
            //                             uni.$u.toast(res.statusMsg);
            //                         }
            //                     })
            //                 },
            //                 fail: (err) => {
            //                     console.log(err,'---');
            //                 }
            //             })
            //         }
            //     }
            // })
        },
        onReady() {
            this.$refs.form.setRules(this.rulesLogin);
        },
        methods: {
            // 立即注册
            navGotoRegister: throttle(function() {
                uni.navigateTo({
                    url: '../registerIndex/index'
                })
            }, 3000),
            // 检查用户信息
            switchUserInfo(status, data) {
                switch(status) {
                    // case 0:
                    //     uni.$u.toast('当前用户未注册');
                    // break;
                    // case 2:
                    //     uni.$u.toast('您的信息暂未审核,请联系您的管理人员');
                    // break;
                    case 3:
                        uni.$u.toast('您的审核未通过, 请检查注册信息后重新提交!');
                        setTimeout(() => {
                            uni.navigateTo({
                                url: '../registerIndex/index?data=' + JSON.stringify(data)
                            })
                        }, 2000)
                    break;
                }
            },
            // 提交登录信息
            submitForm: throttle(function() {
                this.$refs.form.validate().then((valid) => {
                    console.log(valid);
                    if(valid) {
                        const params = Object.assign({}, this.formLogin);
                        this.$api.system.userLogin(params).then((res) => {
                            console.log(res.data, '----');
                            if(res.success) {
                                uni.$u.toast('登录成功!');
                                uni.setStorageSync('realName', res.data.realName);
                                uni.setStorageSync('telphone', res.data.telphone);
                                uni.setStorageSync('userType', res.data.userType);
                                uni.setStorageSync('menus', res.data.menus);
                                uni.setStorageSync('userToken', res.data.token);
                                if(res.data.userType === 1){
                                    uni.navigateTo({
                                        url: '../robeHome/index',
                                        fail(err) {
                                            console.log(err,'???');
                                        }
                                    })
                                }else{
                                    uni.navigateTo({
                                        url: '../labourHome/index',
                                        fail(err) {
                                            console.log(err,'???');
                                        }
                                    })
                                }
                            } else {
                                uni.$u.toast(res.statusMsg);
                            }
                        }).catch((err) => {
                            uni.$u.toast('请检查网络服务!')
                        })
                    }
                })
            }, 3000),
        }
    }
</script>
 
<style scoped lang="scss">
.login_index {
    position: relative;
    width: 100vw;
    height: 100vh;
    background: #F6F6F6;
    
    .login_header {
        position: relative;
        width: 100%;
        height: 50%;
        // background: #556DFE;
        background: url('https://szpipe.thhy-tj.com/group1/M00/00/04/bx5d1GR1awaAOSrGAADytgHWrpk815.png') no-repeat;
        background-size: 100% 100%;
        border-radius: 0 0 20px 20px;
        
        .login_header_title {
            padding: 40px 0 0;
            color: #fff;
            font-size: 20px;
            text-align: center;
        }
        
        .login_header_icon {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translateX(-50%) translateY(-45%);
            padding: 15px;
            border-radius: 15px;
            background: #FFFFFF;
        }
    }
    
    .login_content {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translateX(-50%) translateY(-30%);
        padding: 20px;
        width: calc(90% - 40px);
        border-radius: 15px;
        box-shadow: 0 2px 12px 0 rgba(120, 83, 251, 0.3);
        background: #fff;
        
        .login_content_title {
            padding: 10px 0;
            font-size: 24px;
            text-align: center;
        }
        
        .login_content_form {
            padding: 20px 0 0;
        }
        .login_content_button {
            margin-top: 40px;
        }
        
        .login_content_info {
            padding: 20px 0 0;
            font-size: 12px;
            text-align: center;
            
            & span {
                color: #556DFE;
            }
        }
    }
}
 
::v-deep .u-form-item__body__right__message {
    margin-left: 0 !important;
}
::v-deep .u-form-item {
    margin-bottom: 10px;
}
::v-deep .u-text {
    justify-content: flex-end !important;
}
</style>