login.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div class="aui-wrapper aui-page__login">
  3. <div class="aui-content__wrapper">
  4. <el-row>
  5. <el-col class="aui-content" :span="24" :offset="5">
  6. <!--<div class="login-header">-->
  7. <!--<h2 class="login-brand">{{ $t('brand.lg') }}</h2>-->
  8. <!--</div>-->
  9. <div class="login-body">
  10. <!--<h3 class="login-title">{{ $t('login.title') }}</h3>-->
  11. <img src="~@/assets/img/logo.png" style="width:50%;margin-bottom: 40px;">
  12. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()" status-icon>
  13. <el-form-item prop="username">
  14. <el-input v-model="dataForm.username" :placeholder="$t('login.username')">
  15. <span slot="prefix" class="el-input__icon">
  16. <svg class="icon-svg" aria-hidden="true"><use xlink:href="#icon-user"></use></svg>
  17. </span>
  18. </el-input>
  19. </el-form-item>
  20. <el-form-item prop="password">
  21. <el-input v-model="dataForm.password" type="password" :placeholder="$t('login.password')">
  22. <span slot="prefix" class="el-input__icon">
  23. <svg class="icon-svg" aria-hidden="true"><use xlink:href="#icon-lock"></use></svg>
  24. </span>
  25. </el-input>
  26. </el-form-item>
  27. <el-form-item prop="validCode">
  28. <el-row :gutter="20">
  29. <el-col :span="14">
  30. <el-input v-model="dataForm.validCode" :placeholder="$t('login.captcha')">
  31. <span slot="prefix" class="el-input__icon">
  32. <svg class="icon-svg" aria-hidden="true"><use xlink:href="#icon-safetycertificate"></use></svg>
  33. </span>
  34. </el-input>
  35. </el-col>
  36. <el-col :span="10" class="login-captcha">
  37. <img :src="captchaPath" @click="getCaptcha()">
  38. </el-col>
  39. </el-row>
  40. </el-form-item>
  41. <el-form-item>
  42. <el-button type="primary" @click="dataFormSubmitHandle()" class="w-percent-100">{{ $t('login.title') }}</el-button>
  43. </el-form-item>
  44. </el-form>
  45. </div>
  46. </el-col>
  47. </el-row>
  48. </div>
  49. </div>
  50. </template>
  51. <script>
  52. import Cookies from 'js-cookie'
  53. import debounce from 'lodash/debounce'
  54. import { messages } from '@/i18n'
  55. import { getUUID } from '@/utils'
  56. export default {
  57. data () {
  58. return {
  59. i18nMessages: messages,
  60. captchaPath: '',
  61. dataForm: {
  62. username: '',
  63. password: '',
  64. deviceId: '',
  65. validCode: ''
  66. }
  67. }
  68. },
  69. computed: {
  70. dataRule () {
  71. return {
  72. username: [
  73. { required: true, message: this.$t('validate.required'), trigger: 'blur' }
  74. ],
  75. password: [
  76. { required: true, message: this.$t('validate.required'), trigger: 'blur' }
  77. ],
  78. validCode: [
  79. { required: true, message: this.$t('validate.required'), trigger: 'blur' }
  80. ]
  81. }
  82. }
  83. },
  84. created () {
  85. this.getCaptcha()
  86. },
  87. methods: {
  88. // 获取验证码
  89. getCaptcha () {
  90. this.dataForm.deviceId = getUUID()
  91. this.captchaPath = `${window.SITE_CONFIG['apiURL']}/validata/code/${this.dataForm.deviceId}`
  92. },
  93. // 表单提交
  94. dataFormSubmitHandle: debounce(function () {
  95. this.$refs['dataForm'].validate((valid) => {
  96. if (!valid) {
  97. return false
  98. }
  99. this.$http.post('/idaas/sso/login', this.dataForm).then(({ data: res }) => {
  100. if (res.code !== 0) {
  101. this.getCaptcha()
  102. return this.$message.error(res.msg)
  103. }
  104. Cookies.set('token', res.sessionToken)
  105. // 发送用户登录成功MQ消息
  106. this.$http.get('/mq/user/login').then(({ data: res }) => {
  107. if (res.code !== 0) {
  108. return this.$message.error(res.msg)
  109. }
  110. }).catch(() => {})
  111. this.$router.replace({ name: 'home' })
  112. }).catch(() => {})
  113. })
  114. }, 1000, { 'leading': true, 'trailing': false })
  115. }
  116. }
  117. </script>
  118. <style scoped>
  119. .aui-page__login .aui-content{
  120. padding: 0!important;
  121. }
  122. </style>