Login.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <div class="login">
  3. <div class="opacity-0 login-mask lg:opacity-100"></div>
  4. <div class="justify-center login-form-wrap lg:justify-end">
  5. <div class="mx-6 login-form">
  6. <AppLocalePicker v-if="showLocale" class="login-form__locale" />
  7. <div class="px-2 py-10 login-form__content">
  8. <header>
  9. <img :src="logo" class="mr-4" />
  10. <h1>{{ title }}</h1>
  11. </header>
  12. <a-form class="login-form__main" :model="formData" :rules="formRules" ref="formRef">
  13. <a-form-item name="account">
  14. <a-input size="large" v-model:value="formData.account" placeholder="username: vben" />
  15. </a-form-item>
  16. <a-form-item name="password">
  17. <a-input-password
  18. size="large"
  19. visibilityToggle
  20. v-model:value="formData.password"
  21. placeholder="password: 123456"
  22. />
  23. </a-form-item>
  24. <a-row>
  25. <a-col :span="12">
  26. <a-form-item>
  27. <!-- No logic, you need to deal with it yourself -->
  28. <a-checkbox v-model:checked="autoLogin" size="small">{{
  29. t('sys.login.autoLogin')
  30. }}</a-checkbox>
  31. </a-form-item>
  32. </a-col>
  33. <a-col :span="12">
  34. <a-form-item :style="{ 'text-align': 'right' }">
  35. <!-- No logic, you need to deal with it yourself -->
  36. <a-button type="link" size="small">
  37. {{ t('sys.login.forgetPassword') }}
  38. </a-button>
  39. </a-form-item>
  40. </a-col>
  41. </a-row>
  42. <a-form-item>
  43. <a-button
  44. type="primary"
  45. size="large"
  46. class="rounded-sm"
  47. :block="true"
  48. @click="login"
  49. :loading="formState.loading"
  50. >
  51. {{ t('sys.login.loginButton') }}
  52. </a-button>
  53. </a-form-item>
  54. </a-form>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. </template>
  60. <script lang="ts">
  61. import { defineComponent, reactive, ref, unref, toRaw } from 'vue';
  62. import { Checkbox, Form, Input, Row, Col } from 'ant-design-vue';
  63. import { Button } from '/@/components/Button';
  64. import { AppLocalePicker } from '/@/components/Application';
  65. import { userStore } from '/@/store/modules/user';
  66. import { useMessage } from '/@/hooks/web/useMessage';
  67. import { useGlobSetting, useProjectSetting } from '/@/hooks/setting';
  68. import logo from '/@/assets/images/logo.png';
  69. import { useI18n } from '/@/hooks/web/useI18n';
  70. export default defineComponent({
  71. components: {
  72. [Checkbox.name]: Checkbox,
  73. [Form.name]: Form,
  74. [Form.Item.name]: Form.Item,
  75. [Input.name]: Input,
  76. [Input.Password.name]: Input.Password,
  77. AButton: Button,
  78. AppLocalePicker,
  79. [Row.name]: Row,
  80. [Col.name]: Col,
  81. },
  82. setup() {
  83. const formRef = ref<any>(null);
  84. const autoLoginRef = ref(false);
  85. const globSetting = useGlobSetting();
  86. const { locale } = useProjectSetting();
  87. const { notification } = useMessage();
  88. const { t } = useI18n();
  89. const formData = reactive({
  90. account: 'vben',
  91. password: '123456',
  92. });
  93. const formState = reactive({
  94. loading: false,
  95. });
  96. const formRules = reactive({
  97. account: [{ required: true, message: t('sys.login.accountPlaceholder'), trigger: 'blur' }],
  98. password: [
  99. { required: true, message: t('sys.login.passwordPlaceholder'), trigger: 'blur' },
  100. ],
  101. });
  102. async function handleLogin() {
  103. const form = unref(formRef);
  104. if (!form) return;
  105. formState.loading = true;
  106. try {
  107. const data = await form.validate();
  108. const userInfo = await userStore.login(
  109. toRaw({
  110. password: data.password,
  111. username: data.account,
  112. })
  113. );
  114. if (userInfo) {
  115. notification.success({
  116. message: t('sys.login.loginSuccessTitle'),
  117. description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.realName}`,
  118. duration: 3,
  119. });
  120. }
  121. } catch (error) {
  122. } finally {
  123. formState.loading = false;
  124. }
  125. }
  126. return {
  127. formRef,
  128. formData,
  129. formState,
  130. formRules,
  131. login: handleLogin,
  132. autoLogin: autoLoginRef,
  133. title: globSetting && globSetting.title,
  134. logo,
  135. t,
  136. showLocale: locale.show,
  137. };
  138. },
  139. });
  140. </script>
  141. <style lang="less">
  142. .login-form__locale {
  143. position: absolute;
  144. top: 14px;
  145. right: 14px;
  146. z-index: 1;
  147. }
  148. .login {
  149. position: relative;
  150. height: 100vh;
  151. background: url(../../../assets/images/login/login-bg.png) no-repeat;
  152. background-size: 100% 100%;
  153. &-mask {
  154. height: 100%;
  155. background: url(../../../assets/images/login/login-in.png) no-repeat;
  156. background-position: 30% 30%;
  157. background-size: 80% 80%;
  158. }
  159. &-form {
  160. position: relative;
  161. bottom: 60px;
  162. width: 400px;
  163. background: @white;
  164. border: 10px solid rgba(255, 255, 255, 0.5);
  165. border-width: 8px;
  166. border-radius: 4px;
  167. background-clip: padding-box;
  168. &__main {
  169. margin: 30px auto 0 auto !important;
  170. }
  171. &-wrap {
  172. position: absolute;
  173. top: 0;
  174. right: 0;
  175. display: flex;
  176. width: 100%;
  177. height: 100%;
  178. align-items: center;
  179. }
  180. &__content {
  181. position: relative;
  182. width: 100%;
  183. height: 100%;
  184. padding: 60px 0 40px 0;
  185. border: 1px solid #999;
  186. border-radius: 2px;
  187. header {
  188. display: flex;
  189. justify-content: center;
  190. align-items: center;
  191. img {
  192. display: inline-block;
  193. width: 48px;
  194. }
  195. h1 {
  196. margin-bottom: 0;
  197. font-size: 24px;
  198. text-align: center;
  199. }
  200. }
  201. form {
  202. width: 80%;
  203. }
  204. }
  205. }
  206. }
  207. </style>