LoginFormDataCenter.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <div class="login-box">
  3. <Form class="p-4 enter-x" :model="formData" :rules="getFormRules" ref="formRef" v-show="getShow" @keypress.enter="handleLogin" autocomplete="off">
  4. <FormItem name="account" class="enter-x">
  5. <div class="input-box">
  6. <div class="img-user" />
  7. <Input size="large" v-model:value="formData.account" :placeholder="t('sys.login.userName')" class="fix-auto-fill" />
  8. </div>
  9. </FormItem>
  10. <FormItem name="password" class="enter-x">
  11. <div class="input-box">
  12. <div class="img-pass" />
  13. <InputPassword size="large" visibilityToggle v-model:value="formData.password" :placeholder="t('sys.login.password')" />
  14. </div>
  15. </FormItem>
  16. </Form>
  17. <div class="btn-box">
  18. <div class="btn" @click="handleLogin"> {{ t('sys.login.loginButton') }}</div>
  19. </div>
  20. </div>
  21. </template>
  22. <script lang="ts" setup>
  23. import { reactive, ref, toRaw, unref, computed, onMounted } from 'vue';
  24. import { Checkbox, Form, Input, Row, Col, Button } from 'ant-design-vue';
  25. import { createFromIconfontCN } from '@ant-design/icons-vue';
  26. import { useI18n } from '/@/hooks/web/useI18n';
  27. import { useMessage } from '/@/hooks/web/useMessage';
  28. import { useUserStore } from '/@/store/modules/user';
  29. import { LoginStateEnum, useLoginState, useFormRules, useFormValid } from './useLogin';
  30. import { useDesign } from '/@/hooks/web/useDesign';
  31. import { getCodeInfo } from '/@/api/sys/user';
  32. //import { onKeyStroke } from '@vueuse/core';
  33. const ACol = Col;
  34. const ARow = Row;
  35. const FormItem = Form.Item;
  36. const InputPassword = Input.Password;
  37. const IconFont = createFromIconfontCN({
  38. scriptUrl: '//at.alicdn.com/t/font_2316098_umqusozousr.js',
  39. });
  40. const { t } = useI18n();
  41. const { notification, createErrorModal } = useMessage();
  42. const { prefixCls } = useDesign('login');
  43. const userStore = useUserStore();
  44. const { setLoginState, getLoginState } = useLoginState();
  45. const { getFormRules } = useFormRules();
  46. const formRef = ref();
  47. const thirdModalRef = ref();
  48. const loading = ref(false);
  49. const rememberMe = ref(false);
  50. const formData = reactive({
  51. account: '',
  52. password: '',
  53. inputCode: '',
  54. });
  55. const randCodeData = reactive({
  56. randCodeImage: '',
  57. requestCodeSuccess: false,
  58. checkKey: null,
  59. });
  60. const { validForm } = useFormValid(formRef);
  61. //onKeyStroke('Enter', handleLogin);
  62. const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN);
  63. async function handleLogin() {
  64. const data = await validForm();
  65. if (!data) return;
  66. try {
  67. loading.value = true;
  68. const { userInfo } = await userStore.login(
  69. toRaw({
  70. password: data.password,
  71. username: data.account,
  72. captcha: data.inputCode,
  73. checkKey: randCodeData.checkKey,
  74. mode: 'none', //不要默认的错误提示
  75. })
  76. );
  77. if (userInfo) {
  78. notification.success({
  79. message: t('sys.login.loginSuccessTitle'),
  80. description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.realname}`,
  81. duration: 3,
  82. });
  83. }
  84. } catch (error) {
  85. // notification.error({
  86. // message: t('sys.api.errorTip'),
  87. // description: error.message || t('sys.api.networkExceptionMsg'),
  88. // duration: 3,
  89. // });
  90. loading.value = false;
  91. //update-begin-author:taoyan date:2022-5-3 for: issues/41 登录页面,当输入验证码错误时,验证码图片要刷新一下,而不是保持旧的验证码图片不变
  92. handleChangeCheckCode();
  93. //update-end-author:taoyan date:2022-5-3 for: issues/41 登录页面,当输入验证码错误时,验证码图片要刷新一下,而不是保持旧的验证码图片不变
  94. }
  95. }
  96. function handleChangeCheckCode() {
  97. formData.inputCode = '';
  98. //TODO 兼容mock和接口,暂时这样处理
  99. randCodeData.checkKey = 1629428467008; //new Date().getTime();
  100. getCodeInfo(randCodeData.checkKey).then((res) => {
  101. randCodeData.randCodeImage = res;
  102. randCodeData.requestCodeSuccess = true;
  103. });
  104. }
  105. /**
  106. * 第三方登录
  107. * @param type
  108. */
  109. function onThirdLogin(type) {
  110. thirdModalRef.value.onThirdLogin(type);
  111. }
  112. //初始化验证码
  113. onMounted(() => {
  114. handleChangeCheckCode();
  115. });
  116. </script>
  117. <style lang="less" scoped>
  118. @import '/@/design/theme.less';
  119. @ventSpace: zxm;
  120. .login-box {
  121. display: flex;
  122. flex-direction: column;
  123. justify-content: center;
  124. align-items: center;
  125. gap: 20px;
  126. padding: 20px;
  127. margin-top: 8%;
  128. margin-left: 28%;
  129. .input-box {
  130. display: flex;
  131. flex-direction: row;
  132. width: 100%;
  133. background: #165691;
  134. border: 1px solid #1d7fbd;
  135. border-radius: 4px;
  136. font-size: 0.9rem;
  137. transition: all 0.3s;
  138. input {
  139. background: #165691 !important;
  140. border: none;
  141. color: #fff;
  142. }
  143. .img-user {
  144. width: 24px;
  145. height: 24px;
  146. margin: 0 12px;
  147. background: url('@/assets/images/vent/loginDataCenter/user.svg') no-repeat center;
  148. background-size: contain;
  149. align-self: center;
  150. }
  151. .img-pass {
  152. width: 24px;
  153. height: 24px;
  154. margin: 0 12px;
  155. background: url('@/assets/images/vent/loginDataCenter/password.svg') no-repeat center;
  156. background-size: contain;
  157. align-self: center;
  158. }
  159. :deep(.zxm-input .zxm-input-lg) {
  160. background: #165691 !important;
  161. border: none;
  162. color: #fff;
  163. }
  164. :deep(.zxm-input-affix-wrapper > input.zxm-input) {
  165. background: #165691 !important;
  166. border: none;
  167. color: #fff;
  168. }
  169. :deep(.zxm-form-item-has-error :not(.zxm-input-disabled):not(.zxm-input-borderless).zxm-input) {
  170. background: #165691 !important;
  171. }
  172. :deep(.zxm-input-affix-wrapper) {
  173. background: #165691 !important;
  174. border: none;
  175. }
  176. }
  177. .btn-box {
  178. width: 276px;
  179. height: 40px;
  180. top: 40px;
  181. left: 30%;
  182. cursor: pointer;
  183. background: #2390fd;
  184. border-radius: 4px;
  185. .btn {
  186. color: #fff;
  187. display: flex;
  188. justify-content: center;
  189. align-items: center;
  190. font-size: 14px;
  191. height: 40px;
  192. }
  193. }
  194. }
  195. </style>