wanshenmean
2025-04-08 ef0a08b828d021bdc7978406e72bbde000097f5e
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
<template>
    <view class="login">
        <view class="login-main">
            <text class="login-main-title">欢迎登录</text>
            <view class="login-main-subtitle">耀能新能源PDA程序</view>
            <view class="login-main-body">
                <!-- <login-input key="username" v-model="user" clearable placeholder="用户名"
                    :maxlength="20"></login-input> -->
                <uni-easyinput v-model="user" focus placeholder="请输入用户名"></uni-easyinput>
                <view class="login-password">
                    <!-- <login-input key="password" v-model="password" password clearable placeholder="密码"
                        :maxlength="20"></login-input> -->
                    <uni-easyinput type="password" v-model="pass" placeholder="请输入密码"></uni-easyinput>
                </view>
                <view class="verCode" v-if="SYS_DEFAULT_CAPTCHA_OPEN">
                    <uni-easyinput key="code" v-model="code" clearable placeholder="请输入右边验证码"
                        :maxlength="10"></uni-easyinput>
                    <view class="canvas-img-code" @click="refresh()">
                        <img :src="validCodeBase64" :style="{ width: width + 'px', height: height + 'px' }"
                            class="login-validCode-img"/>
                          <!-- <img v-show="validCodeBase64 != ''" :src="validCodeBase64" :style="{ width: width + 'px', height: height + 'px' }"/> -->
                    </view>
                </view>
        
                <u-button type="success" size="default" shape="circle" :ripple="true" ripple-bg-color="#909399"
                    @click="login">
                    登录
                </u-button>
                <!-- <hd-button size="large" type="primary" :disabled="disabled" @click="doLogin">登录</hd-button> -->
            </view>
        </view>
        <!-- <view class="login-footer">
            <text>fant-mini-plus</text>
        </view> -->
    </view>
</template>
 
<script>
    var app = getApp();
    import smCrypto from '@/common/smCrypto.js'
    export default {
        data() {
            return {
                width: 120,
                height: 45,
                pass: '123456',
                user: 'Admin',
                SYS_DEFAULT_CAPTCHA_OPEN: true,
                validCodeBase64: '',
                validCodeReqNo: '',
                code:'1234'
            }
        },
        onLoad(options) {
            this.configSysBaseList()
        },
        methods: {
            configSysBaseList() {
                // this.$u.get('/api/User/getVierificationCode', null).then(res => {
                //     if (res.code == 200) {
                //         res.data.forEach((item) => {
                //             if (item.configKey == "SYS_DEFAULT_CAPTCHA_OPEN") {
                //                 if (item.configValue === 'true') {
                //                     this.SYS_DEFAULT_CAPTCHA_OPEN = true;
                //                 } else {
                //                     this.SYS_DEFAULT_CAPTCHA_OPEN = false;
                //                 }
                //             }
                //         })
                        //如果验证码开关是开就加载验证码
                        if (this.SYS_DEFAULT_CAPTCHA_OPEN) {
                            this.loginCaptcha()
                        }
                    // }
                 // })
            },
            loginCaptcha() {
                this.$u.get('/api/User/getVierificationCode', null).then(res => {
                
                    this.validCodeBase64 =  "data:image/png;base64," + res.img;
                    this.validCodeReqNo = res.uuid
    
                })
            },
            refresh() {
 
                this.loginCaptcha();
            },
            login() {
                if (this.pass == '') {
                    this.$t.message.toast('请输入密码')
                    return;
                } else if (this.user == '') {
                    this.$t.message.toast('请输入用户名')
                    return;
                } else if (this.pass.length < 6) {
                    this.$t.message.toast('密码应大于6位')
                    return;
                } else {
                    this.$t.message.loading('正在登录')
                    // let userifno = {
                    //     UUID: this.SYS_DEFAULT_CAPTCHA_OPEN ? this.validCodeReqNo : null,
                    //     PassWord: smCrypto.doSm2Encrypt(this.pass),
                    //     UserName: this.user,
                    //     VerificationCode: this.SYS_DEFAULT_CAPTCHA_OPEN ? this.code : null
                    // }
                    this.$u.post('/api/User/login', 
                    {UUID: this.validCodeReqNo,
                    passWord: this.pass,
                    userName: this.user,
                    verificationCode: this.code}
                    ).then(res => {
                        console.log(res)
                        this.$t.message.toast("登录成功")
                        this.$t.message.closeLoading()
                        uni.setStorage({
                            key: 'jo_id_token',
                            data: res.data.token,
                        });
                        uni.setStorage({
                            key: 'jo_user',
                            data: res.data,
                        });
                        setTimeout(() => {
                            this.$u.route({
                                type: 'reLaunch',
                                url: 'pages/index/index'
                            })
                        }, 300)
                    });
 
                }
            },
        }
    }
</script>
 
<style lang="scss" scoped>
    .login {
        // font-family: PingFangSC-Regular, PingFang SC;
        // background-color: $color-white;
        height: calc(100vh - var(--window-top));
        width: 100vw;
        box-sizing: border-box;
 
        &-main {
            padding: 112rpx 75rpx 0 75rpx;
            position: relative;
 
            &-title {
                display: flex;
                justify-content: center;
                align-items: center;
                height: 64rpx;
                font-size: 48rpx;
                font-weight: 600;
                // color: $color-text-secondary;
                line-height: 64rpx;
                letter-spacing: 8rpx;
            }
 
            &-subtitle {
                font-size: 28rpx;
                // color: $color-text-thirdly;
                line-height: 40rpx;
                letter-spacing: 12rpx;
                text-align: center;
                margin: 8rpx 0 104rpx;
            }
 
            &-body {
                position: relative;
                box-sizing: border-box;
                width: 600rpx;
                height: 548rpx;
 
                .login-password {
                    position: relative;
                    padding: 40rpx 0 40rpx;
                }
 
                .verCode {
                    position: relative;
                    padding: 0rpx 0 140rpx;
                    display: flex;
                    flex-direction: row;
                    align-items: center;
                    justify-content: center;
                }
            }
        }
 
        &-footer {
            display: flex;
            flex-direction: column;
            width: 100%;
            height: 300rpx;
            text-align: center;
            line-height: 28rpx;
            font-size: 20rpx;
            font-weight: 500;
        }
    }
</style>