Login.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <div class="login-wrap">
  3. <div class="login-container">
  4. <p class="title-font title">{{title}}</p>
  5. <a-form :model="forms"
  6. v-bind="layout">
  7. <a-form-item>
  8. <a-input v-model:value="forms.account"
  9. size="large"
  10. placeholder="请输入用户名">
  11. <template #prefix>
  12. <user-outlined />
  13. </template>
  14. </a-input>
  15. </a-form-item>
  16. <a-form-item>
  17. <a-input-password v-model:value="forms.passwd"
  18. size="large"
  19. type="password"
  20. placeholder="请输入密码">
  21. <template #prefix>
  22. <lock-outlined />
  23. </template>
  24. </a-input-password>
  25. </a-form-item>
  26. <a-form-item>
  27. <a-button type="primary"
  28. block
  29. size="large"
  30. shape="round"
  31. :loading="loading"
  32. @click="onLogin">登录</a-button>
  33. </a-form-item>
  34. </a-form>
  35. </div>
  36. </div>
  37. </template>
  38. <script lang="ts">
  39. import { computed, defineComponent, inject, reactive, ref, toRefs } from "vue";
  40. import { UserOutlined, LockOutlined } from "@ant-design/icons-vue";
  41. import useFormLayout from "@/hooks/useFormLayout";
  42. import useApp from "@/hooks/useApp";
  43. import { ActionType } from "@/store/modules/app/_type";
  44. const Login = defineComponent({
  45. name: "Login",
  46. components: {
  47. UserOutlined,
  48. LockOutlined,
  49. },
  50. setup() {
  51. const { router, store } = useApp();
  52. const formLayout = useFormLayout(0);
  53. const data = reactive({
  54. forms: {
  55. account: "",
  56. passwd: "",
  57. },
  58. title: computed(() => store.getters.pageTitle),
  59. loading: false,
  60. layout: formLayout,
  61. });
  62. // TODO 测试账号
  63. if (process.env.NODE_ENV === "development") {
  64. data.forms.account = process.env.VUE_APP_LOGIN_ACCOUNT as string;
  65. data.forms.passwd = process.env.VUE_APP_LOGIN_PASSWORD as string;
  66. }
  67. const onLogin = async () => {
  68. data.loading = true;
  69. await store.dispatch(ActionType.doLogin, data.forms);
  70. data.loading = false;
  71. router.replace("/");
  72. };
  73. return { ...toRefs(data), onLogin };
  74. },
  75. });
  76. export default Login;
  77. </script>
  78. <style lang="scss" scoped>
  79. .login-wrap {
  80. height: 100vh;
  81. background: url(//firemanage.oss-cn-hangzhou.aliyuncs.com/FE-resource/images/background.svg)
  82. #f0f2f5 no-repeat top left / contain;
  83. .title {
  84. font-size: 40px;
  85. text-align: center;
  86. margin-bottom: 30px;
  87. }
  88. .login-container {
  89. padding-top: 120px;
  90. margin: auto;
  91. width: 20vw;
  92. }
  93. }
  94. </style>