login.vue 16.8 KB
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 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
<route lang="yaml">
  meta:
    title: 登录
    constant: true
    layout: false
  </route>
<script lang="ts" setup name="login">
import type { FormInstance, FormRules } from 'element-plus'
import { ElMessage } from 'element-plus'
import useUserStore from '@/store/modules/user'
import { autoSalt } from '@/utils/common'
const route = useRoute()
const router = useRouter()
const userStore = useUserStore()
const logo = new URL('../assets/images/login-logo.png', import.meta.url).href
const banner = new URL('../assets/images/login-left.png', import.meta.url).href
// 表单类型,login 登录,reset 重置密码
const formType = ref('login')
const loading = ref(false)
const redirectPath = route.query.redirect?.toString() ?? '/'
const redirect = ref(redirectPath.indexOf('edit/password') > -1 ? '/' : redirectPath)
// 登录
const loginFormRef = ref<FormInstance>()
const loginForm: any = ref({
  logonUser: localStorage.login_account || '',
  pwd: '',
  userType: 2,
  platformGuid: '6646dcad76c411eea911fa163e419da9'
  // remember: !!localStorage.login_account,
})
const loginRules = ref<FormRules>({
  logonUser: [
    { required: true, trigger: 'blur', message: '请输入账号' },
  ],
  pwd: [
    { required: true, trigger: 'blur', message: '请输入密码' },
    // { min: 6, max: 18, trigger: 'blur', message: '密码长度为6到18位' },
  ],
  userType: [
    { required: true, trigger: 'change', message: '请选择用户类型' },
  ]
})
function handleLogin() {
  loginFormRef.value && loginFormRef.value.validate((valid) => {
    if (valid) {
      loading.value = true
      let params = { ...loginForm.value }
      params.pwd = autoSalt(params.pwd)
      userStore.login(params).then(() => {
        loading.value = false
        if (loginForm.value.remember) {
          localStorage.setItem('login_account', loginForm.value.logonUser)
        }
        else {
          localStorage.removeItem('login_account')
        }
        // 有菜单才跳转,没有菜单不跳转登录页面。
        if (userStore.userInfoData?.length > 0) {
          router.push('/data-asset/register-guide')
        }
        // router.push(redirect.value)
      }).catch(() => {
        loading.value = false
      })
    }
  })
}
// 注册
const registerFormRef = ref<FormInstance>()
const registerForm = ref({
  logonUser: '',
  captcha: '',
  pwd: '',
  userType: 2,
  checkPassword: '',
})
const registerRules = ref<FormRules>({
  logonUser: [
    { required: true, trigger: 'blur', message: '请输入账号' },
  ],
  captcha: [
    { required: true, trigger: 'blur', message: '请输入验证码' },
  ],
  pwd: [
    { required: true, trigger: 'blur', message: '请输入密码' },
    { min: 6, max: 18, trigger: 'blur', message: '密码长度为6到18位' },
  ],
  checkPassword: [
    { required: true, trigger: 'blur', message: '请再次输入密码' },
    {
      validator: (rule, value, callback) => {
        if (value !== registerForm.value.pwd) {
          callback(new Error('两次输入的密码不一致'))
        }
        else {
          callback()
        }
      },
    },
  ],
})
function handleRegister() {
  ElMessage({
    message: '注册模块仅提供界面演示,无实际功能,需开发者自行扩展',
    type: 'warning',
  })
  registerFormRef.value && registerFormRef.value.validate((valid) => {
    if (valid) {
      // 这里编写业务代码
    }
  })
}
// 重置密码
const resetFormRef = ref<FormInstance>()
const resetForm = ref({
  logonUser: localStorage.login_account || '',
  captcha: '',
  newPassword: '',
})
const resetRules = ref<FormRules>({
  logonUser: [
    { required: true, trigger: 'blur', message: '请输入用户名' },
  ],
  captcha: [
    { required: true, trigger: 'blur', message: '请输入验证码' },
  ],
  newPassword: [
    { required: true, trigger: 'blur', message: '请输入新密码' },
    { min: 6, max: 18, trigger: 'blur', message: '密码长度为6到18位' },
  ],
})
function handleReset() {
  ElMessage({
    message: '重置密码模块仅提供界面演示,无实际功能,需开发者自行扩展',
    type: 'warning',
  })
  resetFormRef.value && resetFormRef.value.validate((valid) => {
    if (valid) {
      // 这里编写业务代码
    }
  })
}
function testAccount(logonUser: string) {
  loginForm.value.logonUser = logonUser
  loginForm.value.pwd = '123456'
  handleLogin()
}
</script>
<template>
  <div>
    <div class="bg-banner" />
    <div id="login-box">
      <div class="login-banner">
        <div>
          <img :src="banner" class="banner">
          <div class="banner_desc">
            <h4>数据资产管理系统</h4>
            <span>激活数据流通体系,释放数据要素新质生产力</span>
          </div>
        </div>
      </div>
      <div class="login_form_panel">
        <div class="login_form">
          <el-form v-show="formType === 'login'" ref="loginFormRef" :model="loginForm" :rules="loginRules"
            class="login-form" autocomplete="on">
            <div class="title-container">
              <img :src="logo" class="title_img">
            </div>
            <div class="form-content">
              <el-form-item prop="logonUser">
                <el-input v-model.trim="loginForm.logonUser" placeholder="输入账号" text tabindex="1" autocomplete="on">
                  <!-- <template #prefix>
                      <el-icon>
                        <svg-icon name="ep:user" />
                      </el-icon>
                    </template> -->
                </el-input>
              </el-form-item>
              <el-form-item prop="pwd">
                <el-input v-model.trim="loginForm.pwd" type="password" placeholder="输入密码" tabindex="2" autocomplete="on"
                  show-password @keyup.enter="handleLogin">
                  <!-- <template #prefix>
                      <el-icon>
                        <svg-icon name="ep:lock" />
                      </el-icon>
                    </template> -->
                </el-input>
              </el-form-item>
              <!-- <el-form-item prop="userType" label="用户类型">
              <el-select v-model="loginForm.userType" class="m-2" placeholder="请选择">
                <el-option label="用户" :value="2" />
                <el-option label="管理员" :value="1" />
              </el-select>
            </el-form-item> -->
            </div>
            <!-- <div class="flex-bar">
            <el-checkbox v-model="loginForm.remember">
              记住我
            </el-checkbox>
            <el-link type="primary" :underline="false" @click="formType = 'reset'">
              忘记密码了?
            </el-link>
          </div> -->
            <el-button class="login-btn" :loading="loading" type="primary" size="large" @click.prevent="handleLogin">
              登录
            </el-button>
            <!-- <div class="sub-link">
            <span class="text">还没有帐号?</span>
            <el-link type="primary" :underline="false" @click="formType = 'register'">
              创建新帐号
            </el-link>
          </div>
          <div style="margin-top: 20px; margin-bottom: -20px; text-align: center;">
            <el-divider>演示账号一键登录</el-divider>
            <el-button type="primary" size="small" plain @click="testAccount('admin')">
              admin
            </el-button>
            <el-button size="small" plain @click="testAccount('test')">
              test
            </el-button>
          </div> -->
          </el-form>
          <el-form v-show="formType === 'register'" ref="registerFormRef" :model="registerForm" :rules="registerRules"
            class="login-form" auto-complete="on">
            <div class="title-container">
              <h3 class="title">
                探索从这里开始! 🚀
              </h3>
            </div>
            <div>
              <el-form-item prop="logonUser">
                <el-input v-model.trim="registerForm.logonUser" placeholder="账号" tabindex="1" autocomplete="on">
                  <template #prefix>
                    <el-icon>
                      <svg-icon name="ep:user" />
                    </el-icon>
                  </template>
                </el-input>
              </el-form-item>
              <el-form-item prop="captcha">
                <el-input v-model.trim="registerForm.captcha" placeholder="验证码" tabindex="2" autocomplete="on">
                  <template #prefix>
                    <el-icon>
                      <svg-icon name="ep:key" />
                    </el-icon>
                  </template>
                  <template #append>
                    <el-button>发送验证码</el-button>
                  </template>
                </el-input>
              </el-form-item>
              <el-form-item prop="pwd">
                <el-input v-model.trim="registerForm.pwd" type="password" placeholder="密码" tabindex="3" autocomplete="on"
                  show-password>
                  <template #prefix>
                    <el-icon>
                      <svg-icon name="ep:lock" />
                    </el-icon>
                  </template>
                </el-input>
              </el-form-item>
              <el-form-item prop="checkPassword">
                <el-input v-model.trim="registerForm.checkPassword" type="password" placeholder="确认密码" tabindex="4"
                  autocomplete="on" show-password>
                  <template #prefix>
                    <el-icon>
                      <svg-icon name="ep:lock" />
                    </el-icon>
                  </template>
                </el-input>
              </el-form-item>
            </div>
            <el-button :loading="loading" type="primary" size="large" style="width: 100%; margin-top: 20px;"
              @click.prevent="handleRegister">
              注册
            </el-button>
            <div class="sub-link">
              <span class="text">已经有帐号?</span>
              <el-link type="primary" :underline="false" @click="formType = 'login'">
                去登录
              </el-link>
            </div>
          </el-form>
          <el-form v-show="formType === 'reset'" ref="resetFormRef" :model="resetForm" :rules="resetRules"
            class="login-form" auto-complete="on">
            <div class="title-container">
              <h3 class="title">
                忘记密码了? 🔒
              </h3>
            </div>
            <div>
              <el-form-item prop="logonUser">
                <el-input v-model.trim="resetForm.logonUser" placeholder="账号" tabindex="1" autocomplete="on">
                  <template #prefix>
                    <el-icon>
                      <svg-icon name="ep:user" />
                    </el-icon>
                  </template>
                </el-input>
              </el-form-item>
              <el-form-item prop="captcha">
                <el-input v-model.trim="resetForm.captcha" placeholder="验证码" tabindex="2" autocomplete="on">
                  <template #prefix>
                    <el-icon>
                      <svg-icon name="ep:key" />
                    </el-icon>
                  </template>
                  <template #append>
                    <el-button>发送验证码</el-button>
                  </template>
                </el-input>
              </el-form-item>
              <el-form-item prop="newPassword">
                <el-input v-model.trim="resetForm.newPassword" type="password" placeholder="新密码" tabindex="3" autocomplete="on"
                  show-password>
                  <template #prefix>
                    <el-icon>
                      <svg-icon name="ep:lock" />
                    </el-icon>
                  </template>
                </el-input>
              </el-form-item>
            </div>
            <el-button :loading="loading" type="primary" size="large" style="width: 100%; margin-top: 20px;"
              @click.prevent="handleReset">
              确认
            </el-button>
            <div class="sub-link">
              <el-link type="primary" :underline="false" @click="formType = 'login'">
                返回登录
              </el-link>
            </div>
          </el-form>
        </div>
      </div>
    </div>
    <div class="footer">
      北京传世博润科技有限公司 Copyright @ 2023-2024 <a href="https://beian.miit.gov.cn" target="_blank">京ICP备2024044205号</a>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.footer {
  position: absolute;
    bottom: 20px;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 12px;
color: #606060;
font-weight: 200;
}
[data-mode="mobile"] {
  #login-box {
    position: relative;
    width: 100%;
    height: 100%;
    top: inherit;
    left: inherit;
    transform: translateX(0) translateY(0);
    flex-direction: column;
    justify-content: start;
    border-radius: 0;
    box-shadow: none;
    .login-banner {
      width: 100%;
      padding: 20px 0;
      .banner {
        position: relative;
        right: inherit;
        width: 100%;
        max-width: 375px;
        margin: 0 auto;
        display: inherit;
        top: inherit;
        transform: translateY(0);
      }
    }
    .login-form {
      width: 100%;
      min-height: auto;
      padding: 30px;
    }
  }
  .copyright {
    position: relative;
    bottom: 0;
    padding-bottom: 10px;
  }
}
:deep(input[type="password"]::-ms-reveal) {
  display: none;
}
:deep(.el-form) {
  .el-form-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    .el-form-item__content {
      width: 100%;
    }
    .el-select {
      width: 100%;
    }
  }
}
.bg-banner {
  position: fixed;
  z-index: 0;
  width: 100%;
  height: 100%;
  background: url('@/assets/images/login-bg.png') center/100% 100% no-repeat;
}
#login-box {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: space-around;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
  overflow: hidden;
  max-width: 1280px;
  min-width: 900px;
  padding-bottom: 20px;
  .login-banner {
    height: 100%;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    >div {
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    .banner {
      width: 495px;
    }
    .banner_desc {
      width: 496px;
      text-align: justify;
      font-size: 24px;
      color: #414141;
      font-weight: 200;
      margin-top: -32px;
      h4 {
        text-align: center;
        margin: 0 0 8px;
        font-size: 28px;
        color: #414141;
        font-weight: 600;
      }
    }
  }
  .login_form_panel {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    .login_form {
      width: 500px;
      height: 450px;
      margin-top: 45px;
      background: #FFFFFF;
      box-shadow: 0px 4px 10px 0px rgba(0,0,0,0.2);
      .title_img {
        margin-top: 54px;
        margin-bottom: 47px;
      }
      .form-content {
        margin: 0px 30px;
      }
    }
    .title-container {
      text-align: center;
      >img {
        width: 263px;
      }
      .form_title {
        height: 42px;
        font-size: 28px;
        color: #8D8D8E;
        letter-spacing: 0;
        text-align: center;
        line-height: 42px;
        font-weight: 400;
        margin: 32px 0;
      }
    }
  }
  .login-form {
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
    .title-container {
      position: relative;
      .title {
        font-size: 1.3em;
        color: var(--el-text-color-primary);
        margin: 0 auto 30px;
        font-weight: bold;
      }
    }
  }
  .el-form-item {
    margin-bottom: 24px;
    :deep(.el-input) {
      height: 44px;
      line-height: inherit;
      width: 100%;
      input {
        height: 44px;
        font-size: 14px;
        &:-webkit-autofill::first-line {
          font-size: 14px;
        }
      }
      .el-input__icon {
        width: 20px;
        height: 15px;
        svg {
          width: 100%;
          height: 100%;
        }
      }
      .el-input__prefix,
      .el-input__suffix {
        display: flex;
        align-items: center;
      }
      .el-input__prefix {
        left: 10px;
      }
      .el-input__suffix {
        right: 10px;
      }
      .el-input__wrapper {
        // border-radius: 0;
        // box-shadow: none;
        // border-bottom: 1px solid #e5e5e5;
        &:hover {
          // box-shadow: none;
        }
      }
    }
  }
  .flex-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
  }
  .sub-link {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--el-text-color-secondary);
    .text {
      margin-right: 10px;
    }
  }
}
.login-btn {
  margin: 24px 30px 0 30px;
  height: 44px;
  width: auto;
  font-size: 20px;
}
</style>