Login.vue 7.0 KB

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