login-form.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <div class="login-form-wrapper">
  3. <div class="item">
  4. <div class="login-form-title">FlexiStream</div>
  5. <div class="login-form-sub-title">Login to FlexiStream</div>
  6. <a-form ref="loginForm" :model="formData" class="login-form" @submit-success="handleSubmit">
  7. <a-form-item field="username" :rules="[{ required: true, message: '用户名不能为空' }]"
  8. :validate-trigger="['change', 'blur']" hide-label>
  9. <a-input v-model="formData.username" :placeholder="$t('login.userName')">
  10. <template #prefix>
  11. <icon-user />
  12. </template>
  13. </a-input>
  14. </a-form-item>
  15. <a-form-item field="password" :rules="[{ required: true, message: '密码不能为空' }]"
  16. :validate-trigger="['change', 'blur']" hide-label>
  17. <a-input-password v-model="formData.password" :placeholder="$t('login.password')" allow-clear>
  18. <template #prefix>
  19. <icon-lock />
  20. </template>
  21. </a-input-password>
  22. </a-form-item>
  23. <a-space :size="16" direction="vertical">
  24. <div class="login-form-password-actions">
  25. <a-checkbox v-model="rememberPassword">
  26. {{ $t('login.RememberAccountNumber') }}
  27. </a-checkbox>
  28. <!-- <a-link>忘记密码</a-link> -->
  29. </div>
  30. <a-button type="primary" html-type="submit" long :loading="formLoading">{{ $t('login.disembark') }}</a-button>
  31. </a-space>
  32. </a-form>
  33. </div>
  34. </div>
  35. </template>
  36. <script setup>
  37. import { ref, reactive, toRefs, onMounted } from 'vue'
  38. import { encryptByDES } from "@/utils"
  39. import { loginApi } from "@/api/path/login.api"
  40. import { useSystemStore } from "@/store/modules/systemStore"
  41. import { useRouter } from 'vue-router'
  42. import { updateRouteByMenu } from '@/router/router.update'
  43. import { FormLoginUser } from '@/store/modules/Login'
  44. import { useI18n } from 'vue-i18n'
  45. const { t } = useI18n();
  46. const router = useRouter()
  47. const systemStore = useSystemStore()
  48. const LoginSet = FormLoginUser()
  49. const state = ref({
  50. formData: {
  51. username: '',
  52. password: ''
  53. },
  54. formLoading: false,
  55. rememberPassword: false,
  56. })
  57. const { formData, formLoading, rememberPassword } = toRefs(state.value)
  58. const handleSubmit = async () => {
  59. const { data } = await loginApi({
  60. username: formData.value.username,
  61. password: encryptByDES(formData.value.password)
  62. })
  63. if (rememberPassword.value) {
  64. LoginSet.loginYester(formData.value)
  65. } else {
  66. const nste = localStorage.getItem("USER_KEY_ACCOUT") || false;
  67. if (nste) {
  68. localStorage.removeItem('USER_KEY_ACCOUT')
  69. }
  70. }
  71. systemStore.setStateValue({
  72. key: 'token',
  73. value: data.token,
  74. localStorage: true,
  75. })
  76. systemStore.setStateValue({
  77. key: 'user_login_information',
  78. value: JSON.stringify(data.userInfo ? data.userInfo : data),
  79. localStorage: true,
  80. })
  81. systemStore.setStateValue({
  82. key: 'role',
  83. value: data.userType,
  84. localStorage: true,
  85. })
  86. await updateRouteByMenu(router, systemStore)
  87. router.push({
  88. path: "/",
  89. })
  90. }
  91. onMounted(() => {
  92. if (LoginSet.loadCredentials()) {
  93. formData.value.username = LoginSet.loadCredentials()?.username
  94. formData.value.password = LoginSet.loadCredentials()?.password
  95. }
  96. })
  97. </script>
  98. <style lang="less" scoped>
  99. .login-form-wrapper {
  100. position: absolute;
  101. top: 50%;
  102. left: 80%;
  103. transform: translate(-50%, -50%);
  104. background-color: #fff;
  105. width: 550px;
  106. height: 500px;
  107. border-radius: 16px;
  108. }
  109. .item {
  110. width: 80%;
  111. }
  112. .login-form {
  113. margin-top: 32px;
  114. &-wrapper {
  115. display: flex;
  116. justify-content: center;
  117. align-items: center;
  118. }
  119. &-title {
  120. color: @text_color_1;
  121. font-weight: 500;
  122. font-size: 24px;
  123. line-height: 32px;
  124. }
  125. &-sub-title {
  126. color: @text_color_2;
  127. font-size: 16px;
  128. line-height: 24px;
  129. }
  130. &-password-actions {
  131. display: flex;
  132. justify-content: space-between;
  133. margin-bottom: 15px;
  134. }
  135. &-register-btn {
  136. color: @text_color_3 !important;
  137. }
  138. }
  139. </style>