zhouwx
2024-08-08 395043aae3a96a22c53b6b3e4af0812c8528d624
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
<template>
  <div class="login">
    <div class="title">
      <div class="logo">
        <img class="pics2" :src="logoPng">
        <span style="font-size: 40px;color: black">沙湾市安全培训</span>
        <div style="width: 2px;height: 40px;background-color: #1C68A7;margin-top: 5px;margin-left: 15px;margin-right: 15px"></div>
        <span style="font-size: 28px;color: white">危化品全生命周期管理系统</span>
      </div>
      <div class="content">
        <div class="imgBox">
          <div class="imG"></div>
        </div>
        <div class="formBox">
          <div class="loginTitle">账号登录</div>
          <div style="padding: 20px 0;">
            <el-form ref="loginRef" :model="loginForm" :rules="loginRules" class="login-form">
              <el-form-item>
                <div class="fromRow">
                  <el-input
                      v-model="loginForm.username"
                      type="text"
                      size="large"
                      auto-complete="off"
                      placeholder="请输入用户名"
                      style="height: 50px"
                  >
                    <template #prefix><svg-icon icon-class="user" class="el-input__icon input-icon" /></template>
                  </el-input>
                </div>
              </el-form-item>
              <el-form-item>
                <div class="fromRow">
                  <el-input
                      style="height: 50px"
                      v-model="loginForm.password"
                      type="password"
                      size="large"
                      auto-complete="off"
                      placeholder="请输入密码"
                      @keyup.enter="handleLogin"
                      show-password
                  >
                    <template #prefix><svg-icon icon-class="password" class="el-input__icon input-icon" /></template>
                  </el-input>
                </div>
              </el-form-item>
              <el-form-item>
                <div class="fromRow">
                  <el-input
                      v-model="loginForm.code"
                      size="large"
                      auto-complete="off"
                      placeholder="验证码"
                      style="height: 50px;width:63%"
                      @keyup.enter="handleLogin"
                  >
                    <template #prefix><svg-icon icon-class="validCode" class="el-input__icon input-icon" /></template>
                  </el-input>
                  <div class="login-code">
                    <img :src="codeUrl" @click="getCode" class="login-code-img"/>
                  </div>
                </div>
              </el-form-item>
              <el-form-item>
                <div class="fromRow">
                  <el-button
                      :loading="loading"
                      size="large"
                      type="primary"
                      style="width:100%;"
                      @click.prevent="handleLogin"
                  >
                    <span v-if="!loading">登 录</span>
                    <span v-else>登 录 中...</span>
                  </el-button>
                </div>
              </el-form-item>
            </el-form>
          </div>
        </div>
      </div>
 
    </div>
    <!--  底部  -->
    <div class="el-login-footer">
      <span>Copyright ©2024-{{nowYear}} All Rights Reserved.</span>
    </div>
<!--    <img class="pics1" :src="dataPng">-->
<!--    <img class="pics2" :src="searchPng">-->
 
 
<!--    <div class="login-panel">-->
<!--      <el-form ref="loginRef" :model="loginForm" :rules="loginRules" class="login-form">-->
<!--        <h3 class="title">安全在线教育平台</h3>-->
<!--        <el-form-item prop="username">-->
<!--          <el-input-->
<!--              v-model="loginForm.username"-->
<!--              type="text"-->
<!--              size="large"-->
<!--              auto-complete="off"-->
<!--              placeholder="账号"-->
<!--          >-->
<!--            <template #prefix><svg-icon icon-class="user" class="el-input__icon input-icon" /></template>-->
<!--          </el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item prop="password">-->
<!--          <el-input-->
<!--              v-model="loginForm.password"-->
<!--              type="password"-->
<!--              size="large"-->
<!--              auto-complete="off"-->
<!--              placeholder="密码"-->
<!--              @keyup.enter="handleLogin"-->
<!--              show-password-->
<!--          >-->
<!--            <template #prefix><svg-icon icon-class="password" class="el-input__icon input-icon" /></template>-->
<!--          </el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item prop="code" v-if="captchaEnabled">-->
<!--          <el-input-->
<!--              v-model="loginForm.code"-->
<!--              size="large"-->
<!--              auto-complete="off"-->
<!--              placeholder="验证码"-->
<!--              style="width: 63%"-->
<!--              @keyup.enter="handleLogin"-->
<!--          >-->
<!--            <template #prefix><svg-icon icon-class="validCode" class="el-input__icon input-icon" /></template>-->
<!--          </el-input>-->
<!--          <div class="login-code">-->
<!--            <img :src="codeUrl" @click="getCode" class="login-code-img"/>-->
<!--          </div>-->
<!--        </el-form-item>-->
<!--        <el-form-item style="width:100%;">-->
<!--          <el-button-->
<!--              :loading="loading"-->
<!--              size="large"-->
<!--              type="primary"-->
<!--              style="width:100%;"-->
<!--              @click.prevent="handleLogin"-->
<!--          >-->
<!--            <span v-if="!loading">登 录</span>-->
<!--            <span v-else>登 录 中...</span>-->
<!--          </el-button>-->
<!--        </el-form-item>-->
<!--      </el-form>-->
<!--    </div>-->
  </div>
</template>
 
<script setup>
import {onMounted, ref, watch, defineAsyncComponent, nextTick} from "vue"
import { getCodeImg } from "@/api/login";
import Cookies from "js-cookie";
import { encrypt, decrypt } from "@/utils/jsencrypt";
import useUserStore from '@/store/modules/user'
import { Base64 } from 'js-base64'
import menu from "@/layout/components/Sidebar/menu";
import dataPng from "@/assets/images/login-data.png"
import searchPng from "@/assets/images/login-search.png"
import logoPng from "@/assets/logo/logo3.png"
 
const userStore = useUserStore()
const route = useRoute();
const router = useRouter();
const { proxy } = getCurrentInstance();
const nowYear = ref();
// 时间格式化
const timeForm = {
  hour12: false,
  year: 'numeric',
  month: '2-digit',
  day: '2-digit',
  hour: '2-digit',
  minute: '2-digit',
  second: '2-digit'
}
 
const loginForm = ref({
  username: "",
  password: "",
  code: "",
  uuid: ""
});
 
const loginRules = {
  username: [{ required: true, trigger: "blur", message: "请输入您的账号" }],
  password: [{ required: true, trigger: "blur", message: "请输入您的密码" }],
  code: [{ required: true, trigger: "change", message: "请输入验证码" }]
};
 
const codeUrl = ref("");
const loading = ref(false);
const regRef = ref(null)
// 验证码开关
const captchaEnabled = ref(true);
// 注册开关
const isRegister = ref(false);
const redirect = ref(undefined);
 
onMounted(()=>{
  const curTime = new Date().toLocaleString('zh', timeForm).replace(/\//g, '-');
  nowYear.value = curTime.slice(0, 4);
})
 
const openRegist = ()=>{
  regRef.value.dialogVisible = true
}
 
watch(route, (newRoute) => {
  redirect.value = newRoute.query && newRoute.query.redirect;
}, { immediate: true });
 
const sidebarRouters = ref([])
function handleLogin() {
  proxy.$refs.loginRef.validate(valid => {
    if (valid) {
      loading.value = true;
      // 勾选了需要记住密码设置在 cookie 中设置记住用户名和密码
      // if (loginForm.value.rememberMe) {
      Cookies.set("username", loginForm.value.username, { expires: 30 });
      Cookies.set("password", encrypt(loginForm.value.password), { expires: 30 });
      //   Cookies.set("rememberMe", loginForm.value.rememberMe, { expires: 30 });
      // } else {
      // 否则移除
      //   Cookies.remove("username");
      //   Cookies.remove("password");
      //   Cookies.remove("rememberMe");
      // }
      // 调用action的登录方法
      // loginForm.value.password = Base64.encode(loginForm.value.password)
      const param = {
        username: loginForm.value.username,
        password: Base64.encode(loginForm.value.password),
        code: loginForm.value.code,
        uuid: loginForm.value.uuid,
        identity: loginForm.value.role
      }
      userStore.login(param).then(() => {
        // const query = route.query;
        // const otherQueryParams = Object.keys(query).reduce((acc, cur) => {
        //   if (cur !== "redirect") {
        //     acc[cur] = query[cur];
        //   }
        //   return acc;
        // }, {});
 
        //暂时不分角色
        // const userInfo = JSON.parse(Cookies.get('userInfo'))
        // if(userInfo.identity === 0 ) {
        //   //监管用户(管理员)
        //   sidebarRouters.value =  menu.adminMenu
        //   Cookies.set('routers',JSON.stringify(sidebarRouters.value))
        // }else if(userInfo.identity === 1) {
        //   sidebarRouters.value =  menu.agencyMenu
        //   Cookies.set('routers',JSON.stringify(sidebarRouters.value))
        // }
        const userInfo = JSON.parse(Cookies.get('userInfo'))
        if(userInfo.userType === 0) {
          sidebarRouters.value =  menu.adminMenu
          Cookies.set('routers',JSON.stringify(sidebarRouters.value))
        }else {
          sidebarRouters.value =  menu.companyMenu
          Cookies.set('routers',JSON.stringify(sidebarRouters.value))
        }
        let path = ""
        if(sidebarRouters.value[0].children && sidebarRouters.value[0].children.length > 0){
          path = sidebarRouters.value[0].path + '/'+ sidebarRouters.value[0].children[0].path
        }else {
          path = sidebarRouters.value[0].path
        }
 
        router.push({
          path: path
        })
        // router.push({ path: redirect.value || "/", query: otherQueryParams });
      }).catch(() => {
        loading.value = false;
        // 重新获取验证码
        if (captchaEnabled.value) {
          getCode();
        }
      });
    }
  });
}
 
function getCode() {
  getCodeImg().then(res => {
    captchaEnabled.value = res.data.captchaEnabled
    if (captchaEnabled.value) {
      codeUrl.value = "data:image/gif;base64," + res.data.image
      loginForm.value.uuid = res.data.uuid
    }
  });
}
 
 
getCode();
</script>
 
<style lang='scss' scoped>
.login {
  margin: 0;
  padding: 0;
  font-family: "microsoft yahei";
  font-size: 14px;
  //background: #04C1F8;
  background: #04C1F8 url(../assets/images/bgpag.png) no-repeat;
  //background-repeat: no-repeat;
  background-size: cover;
  height: 100%;
  :deep(.el-form-item__content .el-form-item) {
    display: block;
  }
  :deep(.el-form-item--default) {
    margin-bottom: -25px;
  }
}
.logo {
  display: flex;
  align-items: center;
  padding-top: 80px;
}
.pics1{
  position: absolute;
  width: 500px;
  bottom: 0;
  right: 0;
  opacity: 0.5;
}
.pics2{
  width:60px;
  margin-right: 10px;
  //top: 20px;
  //left: 20px;
 
}
.content{
  position: relative;
}
.imgBox {
  width: 560px;
  height: 560px;
  margin-top: 80px;
  float: left;
  position: relative;
}
.fromRow{
  width: 100%;
  margin: 25px 0;
}
.imG{
  width: 500px;
  height: 500px;
  background-image: url(../assets/images/ad.png) ;
  background-repeat: no-repeat;
  position: absolute;
  left: 30px;
  top: 30px;
}
.formBox{
  width: 370px;
  height: 400px;
  border-radius: 5px;
  background: rgba(25,25,25,0.6);
  margin-top: 130px;
  padding: 20px;
  float: right;
}
.loginTitle{
  width: 100%;
  text-align: center;
  font-size: 16px;
  color: #FFF;
  line-height: 50px;
  border-bottom: 1px solid #FFF;
}
.title {
  width: 90%;
  height: auto;
  max-width: 1200px;
  margin: 0 auto;
}
.login-panel{
  border-radius: 1.2rem;
  background: #ffffff;
  width: 550px;
  display: flex;
  justify-content: center;
  align-items: center;
  transform: translateY(-20%);
  box-shadow: 15px 15px 30px rgba(0,0,0,.1);
}
.login-img{
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  img{
    width: 80%;
  }
}
//.login-form {
//  flex: 1;
//  padding: 25px;
//  .el-input {
//    height: 44px;
//    input {
//      height: 44px;
//    }
//  }
//  .input-icon {
//    height: 39px;
//    width: 14px;
//    margin-left: 0px;
//  }
//}
.login-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}
.login-code {
  width: 33%;
  height: 40px;
  float: right;
  img {
    cursor: pointer;
    vertical-align: middle;
  }
}
 
.el-form-item--default{
  margin-bottom: 24px;
}
 
::v-deep(.el-form-item__content){
  display: flex;
  justify-content: space-between;
}
.el-login-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}
.login-code-img {
  margin-top: 5px;
  width: 90px;
  height: 40px;
  padding-left: 7px;
}
 
@media screen and (max-width: 1050px) {
  .imG {
    display: none;
  }
  .imgBox {
   width: 0;
  }
  .formBox{
    width: 100%;
  }
}
 
 
</style>