吉安感知网项目-前端
罗广辉
3 hours ago 5f694550ed7bf0f6147c66feaa4406034ae62e54
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<template>
    <div class="login-right-new" :class="loginPageClass">
        <div class="user-login">用户登录</div>
        <el-form
            class="login-form"
            :rules="loginRules"
            ref="loginForm"
            :model="loginForm"
            label-width="0"
            label-position="top"
        >
            <div class="username">
                <div>
                    <el-form-item prop="username" label="用户名">
                        <el-input
                            class="username-input"
                            @keyup.enter="handleLogin"
                            v-model="loginForm.username"
                            :placeholder="$t('login.username')"
                        ></el-input>
                    </el-form-item>
                </div>
            </div>
            <div class="password">
                <el-form-item prop="password" label="密码">
                    <el-input
                        @keyup.enter="handleLogin"
                        :type="showPasswordModel ? 'text' : 'password'"
                        v-model="loginForm.password"
                        :placeholder="$t('login.password')"
                    ></el-input>
                    <img
                        v-if="showPasswordModel"
                        @click="showPasswordModel = !showPasswordModel"
                        src="../../assets/images/login/close-eye.png"
                        alt=""
                    />
                    <img v-else @click="showPasswordModel = !showPasswordModel" src="../../assets/images/login/see.png" alt="" />
                </el-form-item>
            </div>
            <!-- <div class="forgot-password">忘记密码</div> -->
            <div class="get-forget-password">
                <div></div>
                <div class="forget-password-text" @click.prevent="forgetPasswordClick">忘记密码</div>
            </div>
            <div class="login-submit">
                <el-form-item>
                    <el-button type="primary" @click.prevent="handleLogin">
                        {{ $t('login.submit') }}
                    </el-button>
                </el-form-item>
            </div>
        </el-form>
        <el-dialog
            v-model="tipDialogVisible"
            :width="400"
            :close-on-click-modal="false"
            :destroy-on-close="false"
            class="tip-dialogs"
        >
            <div class="dialog-close" @click="tipDialogVisible = false">
                <img src="../../assets/images/close.png" alt="" />
            </div>
            <div class="dialog-contents">
                <div class="tip-contents">{{ tipInfo }}</div>
                <div class="dialog-btns" v-if="tipInfo === '请联系系统管理员'" @click="tipDialogVisible = false">关闭</div>
                <el-upload
                    v-else
                    class="btn"
                    action="/upload"
                    accept=".lic"
                    :show-file-list="false"
                    :before-upload="handleUpload"
                >
                    <div class="dialog-btns">密钥上传</div>
                </el-upload>
            </div>
        </el-dialog>
    </div>
</template>
 
<script>
import { mapGetters } from 'vuex'
import { info } from '@/api/system/tenant'
import { getCaptcha } from '@/api/user'
import { getTopUrl } from '@/utils/util'
import { validatenull } from '@/utils/validate'
import { uploadLicense } from '@/api/system/dict'
import { ElMessage } from 'element-plus'
import getBaseConfig from '@/buildConfig/config'
 
const { userLoginTitle, userLoginPageClass } = getBaseConfig()
 
export default {
    name: 'userlogin',
    data() {
        const self = this
 
        return {
            tipDialogVisible: false, // 提示联系管理员
            tipInfo: '请联系系统管理员',
            tenantMode: this.website.tenantMode,
            // captchaMode: this.website.captchaMode,
            // registerMode: this.website.oauth2.registerMode,
            loginForm: {
                //租户ID
                tenantId: '000000',
                //部门ID
                deptId: '',
                //角色ID
                roleId: '',
                //用户名
                username: '',
                //密码
                password: '',
                //账号类型
                type: 'account',
                //验证码的值
                code: '',
                //验证码的索引
                key: '',
                //预加载白色背景
                image: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',
            },
            showPasswordModel: false,
            loginRules: {
                tenantId: [{ required: false, message: '请输入租户ID', trigger: 'blur' }],
                username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
                password: [
                    { required: true, message: '请输入密码', trigger: 'blur' },
                    { min: 1, message: '密码长度最少为6位', trigger: 'blur' },
                ],
            },
            passwordType: 'password',
            userBox: false,
            userForm: {
                deptId: '',
                roleId: '',
            },
            userOption: {
                labelWidth: 70,
                submitBtn: true,
                emptyBtn: false,
                submitText: '登 录',
                column: [
                    {
                        label: '角色',
                        prop: 'roleId',
                        type: 'select',
                        props: {
                            label: 'roleName',
                            value: 'id',
                        },
                        dicUrl: '/blade-system/role/select',
                        filterable: true,
                        span: 24,
                        display: false,
                        rules: [
                            {
                                required: true,
                                message: '请选择角色',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '部门',
                        prop: 'deptId',
                        type: 'select',
                        props: {
                            label: 'deptName',
                            value: 'id',
                        },
                        dicUrl: '/blade-system/dept/select',
                        filterable: true,
                        span: 24,
                        display: false,
                        rules: [
                            {
                                required: true,
                                message: '请选择部门',
                                trigger: 'blur',
                            },
                        ],
                    },
                ],
            },
 
            loginTitle: userLoginTitle(self.$route?.query?.xtn),
            loginPageClass: userLoginPageClass || '',
        }
    },
    created() {
        this.getTenant()
        this.refreshCode()
    },
    mounted() {
        this.$nextTick(() => {})
    },
    watch: {
        'loginForm.deptId'() {
            const column = this.findObject(this.userOption.column, 'deptId')
            if (this.loginForm.deptId.includes(',')) {
                column.dicUrl = `/blade-system/dept/select?deptId=${this.loginForm.deptId}`
                column.display = true
            } else {
                column.dicUrl = ''
            }
        },
        'loginForm.roleId'() {
            const column = this.findObject(this.userOption.column, 'roleId')
            if (this.loginForm.roleId.includes(',')) {
                column.dicUrl = `/blade-system/role/select?roleId=${this.loginForm.roleId}`
                column.display = true
            } else {
                column.dicUrl = ''
            }
        },
    },
    computed: {
        ...mapGetters(['tagWel', 'userInfo']),
    },
    props: [],
    methods: {
        refreshCode() {
            // if (this.website.captchaMode) {
            //   getCaptcha().then(res => {
            //     const data = res.data;
            //     this.loginForm.key = data.key;
            //     this.loginForm.image = data.image;
            //   });
            // }
        },
        showPassword() {
            this.passwordType === '' ? (this.passwordType = 'password') : (this.passwordType = '')
        },
        submitLogin(form, done) {
            // if (!validatenull(form.deptId)) {
            //   this.loginForm.deptId = form.deptId;
            // }
            // if (!validatenull(form.roleId)) {
            //   this.loginForm.roleId = form.roleId;
            // }
            this.handleLogin()
            done()
        },
        handleLogin() {
            this.$refs.loginForm.validate(valid => {
                if (valid) {
                    const loading = this.$loading({
                        lock: true,
                        text: '登录中,请稍后',
                        background: 'rgba(0, 0, 0, 0.7)',
                    })
                    this.$store
                        .dispatch('LoginByUsername', this.loginForm)
                        .then(() => {
                            window.isRefreshing = false
                            if (this.website.switchMode) {
                                const deptId = this.userInfo.deptId
                                const roleId = this.userInfo.roleId
                                if (deptId.includes(',') || roleId.includes(',')) {
                                    this.loginForm.deptId = deptId
                                    this.loginForm.roleId = roleId
                                    // this.userBox = true;
                                    this.$store.dispatch('LogOut').then(() => {
                                        loading.close()
                                    })
                                    return false
                                }
                            }
                            loading.close()
                            //加载工作流路由集
                            this.loadFlowRoutes()
                        })
                        .catch(err => {
                            console.log(err)
                            loading.close()
                            this.refreshCode()
                        })
                }
            })
        },
        // handleRegister() {
        //   // this.$parent.activeName = 'register';
        //   this.registerBox = true;
        // },
        loadFlowRoutes() {
            this.$store
                .dispatch('FlowRoutes')
                .then(res => {
                    // 如果密钥在有效期,可以直接跳转
                    this.$router.push(this.tagWel)
                })
                .catch(error => {
                    // 弹出错误信息
                    this.tipInfo = '密钥已过期请联系运维单位'
                    this.tipDialogVisible = true
                })
        },
        getTenant() {
            let domain = getTopUrl()
            // 临时指定域名,方便测试
            //domain = "https://bladex.cn";
            info(domain).then(res => {
                const data = res.data
                if (data.success && data.data.tenantId) {
                    this.tenantMode = false
                    this.loginForm.tenantId = data.data.tenantId
                    this.$parent.$refs.login.style.backgroundImage = `url(${data.data.backgroundUrl})`
                }
            })
        },
        // 上传
        handleUpload(file) {
            const formData = new FormData()
            formData.append('file', file)
            uploadLicense(formData)
                .then(res => {
                    if (res.data.code !== 200) return ElMessage.error('上传失败')
                    ElMessage.success('上传成功')
                    this.tipDialogVisible = false
                    this.$router.push(this.tagWel)
                })
                .catch(err => {
                    ElMessage.error('上传失败')
                })
        },
        forgetPasswordClick() {
            this.tipInfo = '请联系系统管理员'
            this.tipDialogVisible = true
        },
    },
}
</script>
<style scoped>
.login-right-new {
    padding: 16px;
}
 
.user-login {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
}
 
.login-form {
    width: 100%;
}
 
.username,
.password,
.get-forget-password,
.login-submit {
    margin-bottom: 12px;
}
 
.get-forget-password {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
 
.forget-password-text {
    font-size: 14px;
    color: #1677ff;
}
 
:deep(.el-button) {
    width: 100%;
}
 
.password img {
    width: 20px;
    height: 20px;
    margin-left: 8px;
    vertical-align: middle;
    cursor: pointer;
}
 
.dialog-close {
    text-align: right;
    cursor: pointer;
    margin-bottom: 8px;
}
 
.dialog-contents {
    text-align: center;
}
 
.dialog-btns {
    display: inline-block;
    padding: 6px 12px;
    border: 1px solid #dcdfe6;
    border-radius: 4px;
    cursor: pointer;
}
</style>