Login.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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';
  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();
  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('sys.login.accountPlaceholder'), trigger: 'blur' }],
  98. password: [
  99. { required: true, message: t('sys.login.passwordPlaceholder'), trigger: 'blur' },
  100. ],
  101. // verify: unref(openLoginVerifyRef) ? [{ required: true, message: '请通过验证码校验' }] : [],
  102. });
  103. // function resetVerify() {
  104. // const verify = unref(verifyRef);
  105. // if (!verify) return;
  106. // formData.verify && verify.$.resume();
  107. // formData.verify = undefined;
  108. // }
  109. async function handleLogin() {
  110. const form = unref(formRef);
  111. if (!form) return;
  112. formState.loading = true;
  113. try {
  114. const data = await form.validate();
  115. const userInfo = await userStore.login(
  116. toRaw({
  117. password: data.password,
  118. username: data.account,
  119. })
  120. );
  121. if (userInfo) {
  122. notification.success({
  123. message: t('sys.login.loginSuccessTitle'),
  124. description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.realName}`,
  125. duration: 3,
  126. });
  127. }
  128. } catch (error) {
  129. } finally {
  130. // resetVerify();
  131. formState.loading = false;
  132. }
  133. }
  134. return {
  135. formRef,
  136. // verifyRef,
  137. formData,
  138. formState,
  139. formRules,
  140. login: handleLogin,
  141. autoLogin: autoLoginRef,
  142. // openLoginVerify: openLoginVerifyRef,
  143. title: globSetting && globSetting.title,
  144. logo,
  145. t,
  146. showLocale: locale.show,
  147. };
  148. },
  149. });
  150. </script>
  151. <style lang="less">
  152. @import (reference) '../../../design/index.less';
  153. .login-form__locale {
  154. position: absolute;
  155. top: 14px;
  156. right: 14px;
  157. z-index: 1;
  158. }
  159. .login {
  160. position: relative;
  161. height: 100vh;
  162. background: url(../../../assets/images/login/login-bg.png) no-repeat;
  163. background-size: 100% 100%;
  164. &-mask {
  165. display: none;
  166. height: 100%;
  167. background: url(../../../assets/images/login/login-in.png) no-repeat;
  168. background-position: 30% 30%;
  169. background-size: 80% 80%;
  170. .respond-to(xlarge, { display: block;});
  171. }
  172. &-form {
  173. position: relative;
  174. bottom: 60px;
  175. width: 400px;
  176. background: @white;
  177. border: 10px solid rgba(255, 255, 255, 0.5);
  178. border-width: 8px;
  179. border-radius: 4px;
  180. background-clip: padding-box;
  181. .respond-to(xlarge, { margin: 0 120px 0 50px});
  182. &-wrap {
  183. position: absolute;
  184. top: 0;
  185. right: 0;
  186. display: flex;
  187. width: 100%;
  188. height: 100%;
  189. // height: 90%;
  190. justify-content: center;
  191. align-items: center;
  192. .respond-to(xlarge, {
  193. justify-content: flex-end;
  194. });
  195. }
  196. &__content {
  197. position: relative;
  198. width: 100%;
  199. height: 100%;
  200. padding: 60px 0 40px 0;
  201. border: 1px solid #999;
  202. border-radius: 2px;
  203. header {
  204. display: flex;
  205. justify-content: center;
  206. align-items: center;
  207. img {
  208. display: inline-block;
  209. width: 48px;
  210. }
  211. h1 {
  212. margin-bottom: 0;
  213. font-size: 24px;
  214. text-align: center;
  215. }
  216. }
  217. form {
  218. width: 80%;
  219. }
  220. }
  221. }
  222. }
  223. </style>