gx
queenwuli
2021-01-28 b83ba3cc4687f21d744e9866e10e30e91229e8a4
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
<template>
    <!-- 登录 -->
    <view>
        <!-- #ifndef H5 -->
        <view class="status_bar"></view>
        <!-- #endif -->
        <view class="login-header">
            <!-- <view class="logo-wrap"> -->
                <image src="../../static/images/logo.png" mode="widthFix" class="logo"></image>
            <!-- </view> -->
            
            <text>讯聪美业</text>
        </view>
        <view class="login-box">
            <!-- <text class="title">登录</text> -->
            <view class="input-group-row">
                <input v-model="username" type="text" maxlength="60" :disabled="isDisabled"  placeholder="请输入账号" placeholder-class='placeholder'/>
            </view>
            <template v-if="isHidePwd">
                <view class="input-group-row mt-10">
                    <input v-model="password" type="password" :disabled="isDisabled" maxlength="60" placeholder="请输入密码" placeholder-class="placeholder" />
                    <text @click="isHidePwd=false" class="iconfont iconyanjing font-18 gray"></text>
                </view>
            </template>
            <template v-else>
                <view class="input-group-row mt-10">
                    <input v-model="password" type="text" :disabled="isDisabled" maxlength="60" placeholder="请输入密码" placeholder-class="placeholder" />
                    <text @click="isHidePwd=true" class="iconfont iconyanjing1 gray"></text>
                </view>
            </template>
            <navigator class="forget-pwd" url="./forgetPassword" hover-class="none">
                <text>忘记密码?</text>
            </navigator>
            <button :disabled="isDisabled" class="blue-btn" @click="login">登录</button>
        </view>
    </view>
</template>
 
<script>
    export default {
        data(){
            return {
                username: '',
                password: '',
                isDisabled: false,
                isHidePwd: true
            }
        },
        onLoad(options) {
            if(!options || options.isNotLogin != 1){
                this.isLogin();
            }
        },
        onBackPress(options){
            if (this.lastBackPressed && this.lastBackPressed + 2000 >= Date.now()) {
                plus.runtime.quit();
            }else{
                this.lastBackPressed = Date.now();
                this.Toast.info('再按一次退出应用');
                return true;
            }
        },
        methods:{
            isLogin(){
                let token = this.$httpUtils.getToken();
                if(token){
                    uni.switchTab({
                        url: '../workbench/index'
                    })
                }
            },
            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,
                                userFunction: mapInfo.userFunction
                            }),
                            success: () => {
                                uni.switchTab({
                                    url: '../workbench/index'
                                })
                            }
                        });
                    }
                    this.$toast.info(res.info);
                    this.isDisabled = false;
                }).catch((err) => {
                    this.isDisabled = false;
                })
            }
        }
    }
</script>
 
<style>
    .status_bar{
        background: #518EFF;
    }
    .login-header{
        background: #518EFF;
        padding: 60px 0 110px;
        border-radius: 0 0 20px 20px;
        text-align: center;
        font-size: 20px;
        color: #FFFFFF;
    }
    .logo-wrap{
        display: block;
        width: 72px;
        height: 72px;
        background: #FFFFFF;
        border-radius: 8px;
        margin: 0 auto 10px;
    }
    .logo{
        width: 92px;
        display: block;
        margin: 0 auto 10px;
        /* height: 72px; */
    }
    .login-box{
        margin: -50px 10px 0;
        padding: 30px 20px;
        background: #FFFFFF;
        border: 1px solid #EDEAF4;
        border-radius: 4px;
        box-shadow:0 6px 6px rgba(237,234,244,0.5);
    }
    .login-box .title{
        display: block;
        font-size: 20px;
        font-weight: bold;
        color: #518EFF;
        text-align: center;
    }
    .input-group-row input{
        text-align: left;
    }
    .forget-pwd{
        text-align: right;
        margin-top: 5px;
        font-size: 14px;
        color: #518EFF;
    }
    .blue-btn{
        margin-top: 30px;
    }
    uni-button[disabled]:not([type]), uni-button[disabled][type=default]{
        color: #FFFFFF;
        background-color: rgba(36, 131, 255, 0.6);
    }
</style>