gx
queenwuli
2020-12-21 1f3406acbac28b5b98c8d9dde2557374b97c0ef9
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
<template>
    <!-- 登录 -->
    <view>
        <view class="login-box">
            <input v-model="username" placeholder="输入账号" class="login-input" maxlength="60"/>
            <input v-model="password" placeholder="输入密码" class="login-input mt-20" maxlength="60"/>
            <button :disabled="isDisabled" class="blue-btn mt-20" @click="login">登录</button>
        </view>
    </view>
</template>
 
<script>
    export default {
        data(){
            return {
                username: '',
                password: '',
                isDisabled: false
            }
        },
        methods:{
            valid(){
                if(!this.username.trim()){
                    this.$toast.info('请输入账号');
                    return false;
                }
                if(!this.password.trim()){
                    this.$toast.info('输入密码');
                    return false;
                }
            },
            login(){
                if(this.valid() === false){
                    return;
                }
                this.isDisabled = true;
                this.$httpUtils.request('/api/common/login', {
                    username: this.username.trim(),
                    password: this.password.trim()
                }, 'POST').then((res) => {
                    if(res.status == 200){
                        const {mapInfo} = res;
                        uni.setStorage({
                            key: 'userInfo',
                            data: JSON.stringify({
                                token: mapInfo.token,
                                roleInfo: mapInfo.user
                            }),
                            success: () => {
                                uni.switchTab({
                                    url: '../workbench/index'
                                })
                            }
                        });
                    }
                    this.$toast.info(res.info);
                    this.isDisabled = false;
                }).catch((err) => {
                    this.isDisabled = false;
                })
            }
        }
    }
</script>
 
<style>
    .login-box{
        padding: 30px;
        box-sizing: border-box;
        width: 100%;
        position: absolute;
        bottom: 40px;
    }
    .login-input{
        border: 1px solid #ABB1CC;
        border-radius: 20px;
        text-align: center;
        padding: 10px 0;
        font-size: 14px;
    }
    .blue-btn{
        background: #2483ff;
        border-radius: 20px;
        color: #FFFFFF;
        font-size: 16px;
    }
    uni-button[disabled]:not([type]), uni-button[disabled][type=default]{
        color: #FFFFFF;
        background-color: rgba(36, 131, 255, 0.6);
    }
</style>