index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div class="login-box">
  3. <div class="login-logo">
  4. <!-- <svg-icon name="logo" :size="45" />-->
  5. <img src="~@/assets/images/logo-login.png" width="75" />
  6. <h1 class="mb-0 ml-2 text-3xl font-bold" style="font-size: 2.675rem;">惠州市就业驿站管理系统</h1>
  7. </div>
  8. <a-form layout="horizontal" :model="state.formInline" @submit.prevent="handleSubmit" style="border: 1px solid #f0f0f0;width: 600px;height: 400px;padding: 100px;">
  9. <div style="width: 400px;height: 400px; border-radius: 10px;">
  10. <a-form-item>
  11. <a-input v-model:value="state.formInline.username" size="large" placeholder="请输入帐号">
  12. <template #prefix><user-outlined type="user" /></template>
  13. </a-input>
  14. </a-form-item>
  15. <a-form-item>
  16. <a-input
  17. v-model:value="state.formInline.password"
  18. size="large"
  19. type="password"
  20. placeholder="请输入密码"
  21. autocomplete="new-password"
  22. >
  23. <template #prefix><lock-outlined type="user" /></template>
  24. </a-input>
  25. </a-form-item>
  26. <!-- <a-form-item>
  27. <a-input
  28. v-model:value="state.formInline.verifyCode"
  29. placeholder="验证码"
  30. :maxlength="4"
  31. size="large"
  32. >
  33. <template #prefix><SafetyOutlined /></template>
  34. <template #suffix>
  35. <img
  36. :src="state.captcha"
  37. class="absolute right-0 h-full cursor-pointer"
  38. @click="setCaptcha"
  39. />
  40. </template>
  41. </a-input>
  42. </a-form-item>-->
  43. <a-form-item>
  44. <a-button style="border-radius: 8px;" type="primary" html-type="submit" size="large" :loading="state.loading" block>
  45. 登录
  46. </a-button>
  47. </a-form-item>
  48. </div>
  49. </a-form>
  50. </div>
  51. </template>
  52. <script setup lang="ts">
  53. import { reactive } from 'vue';
  54. import { UserOutlined, LockOutlined, SafetyOutlined } from '@ant-design/icons-vue';
  55. import { useRoute, useRouter } from 'vue-router';
  56. import { message, Modal } from 'ant-design-vue';
  57. import { useUserStore } from '@/store/modules/user';
  58. import { getImageCaptcha } from '@/api/login';
  59. import { to } from '@/utils/awaitTo';
  60. const state = reactive({
  61. loading: false,
  62. captcha: '',
  63. formInline: {
  64. username: '',
  65. password: '',
  66. verifyCode: '',
  67. captchaId: '',
  68. },
  69. });
  70. const route = useRoute();
  71. const router = useRouter();
  72. const userStore = useUserStore();
  73. const setCaptcha = async () => {
  74. /*const { id, img } = await getImageCaptcha({ width: 100, height: 50 });
  75. state.captcha = img;
  76. state.formInline.captchaId = id;*/
  77. };
  78. setCaptcha();
  79. const handleSubmit = async () => {
  80. const { username, password, verifyCode } = state.formInline;
  81. if (username.trim() == '' || password.trim() == '') {
  82. return message.warning('用户名或密码不能为空!');
  83. }
  84. /*if (!verifyCode) {
  85. return message.warning('请输入验证码!');
  86. }*/
  87. message.loading('登录中...', 0);
  88. state.loading = true;
  89. console.log(state.formInline);
  90. // params.password = md5(password)
  91. const [err] = await to(userStore.login(state.formInline));
  92. if (err) {
  93. Modal.error({
  94. title: () => '提示',
  95. content: () => err.message,
  96. });
  97. setCaptcha();
  98. } else {
  99. message.success('登录成功!');
  100. setTimeout(() => router.replace((route.query.redirect as string) ?? '/'));
  101. }
  102. state.loading = false;
  103. message.destroy();
  104. };
  105. </script>
  106. <style lang="less" scoped>
  107. .login-box {
  108. display: flex;
  109. width: 100vw;
  110. height: 100vh;
  111. padding-top: 180px;
  112. background: url('~@/assets/login.svg');
  113. background-size: 100%;
  114. flex-direction: column;
  115. align-items: center;
  116. .login-logo {
  117. display: flex;
  118. margin-bottom: 30px;
  119. align-items: center;
  120. .svg-icon {
  121. font-size: 48px;
  122. }
  123. }
  124. :deep(.ant-form) {
  125. width: 400px;
  126. .ant-col {
  127. width: 100%;
  128. }
  129. .ant-form-item-label {
  130. padding-right: 6px;
  131. }
  132. }
  133. }
  134. </style>