Login.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. <div class="login-form__content px-2 py-10">
  7. <AppLocalPicker class="login-form__locale" />
  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 { AppLocalPicker } from '/@/components/Application';
  65. // import { BasicDragVerify, DragVerifyActionType } from '/@/components/Verify/index';
  66. import { userStore } from '/@/store/modules/user';
  67. import { useI18n } from 'vue-i18n';
  68. // import { appStore } from '/@/store/modules/app';
  69. import { useMessage } from '/@/hooks/web/useMessage';
  70. import { useGlobSetting } from '/@/hooks/setting';
  71. import logo from '/@/assets/images/logo.png';
  72. export default defineComponent({
  73. components: {
  74. // BasicDragVerify,
  75. AButton: Button,
  76. ACheckbox: Checkbox,
  77. AppLocalPicker,
  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 { notification } = useMessage();
  85. const { t } = useI18n();
  86. // const openLoginVerifyRef = computed(() => appStore.getProjectConfig.openLoginVerify);
  87. const formData = reactive({
  88. account: 'vben',
  89. password: '123456',
  90. // verify: undefined,
  91. });
  92. const formState = reactive({
  93. loading: false,
  94. });
  95. const formRules = reactive({
  96. account: [{ required: true, message: t('sys.login.accountPlaceholder'), trigger: 'blur' }],
  97. password: [
  98. { required: true, message: t('sys.login.passwordPlaceholder'), trigger: 'blur' },
  99. ],
  100. // verify: unref(openLoginVerifyRef) ? [{ required: true, message: '请通过验证码校验' }] : [],
  101. });
  102. // function resetVerify() {
  103. // const verify = unref(verifyRef);
  104. // if (!verify) return;
  105. // formData.verify && verify.$.resume();
  106. // formData.verify = undefined;
  107. // }
  108. async function handleLogin() {
  109. const form = unref(formRef);
  110. if (!form) return;
  111. formState.loading = true;
  112. try {
  113. const data = await form.validate();
  114. const userInfo = await userStore.login(
  115. toRaw({
  116. password: data.password,
  117. username: data.account,
  118. })
  119. );
  120. if (userInfo) {
  121. notification.success({
  122. message: t('sys.login.loginSuccessTitle'),
  123. description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.realName}`,
  124. duration: 3,
  125. });
  126. }
  127. } catch (error) {
  128. } finally {
  129. // resetVerify();
  130. formState.loading = false;
  131. }
  132. }
  133. return {
  134. formRef,
  135. // verifyRef,
  136. formData,
  137. formState,
  138. formRules,
  139. login: handleLogin,
  140. autoLogin: autoLoginRef,
  141. // openLoginVerify: openLoginVerifyRef,
  142. title: globSetting && globSetting.title,
  143. logo,
  144. t,
  145. };
  146. },
  147. });
  148. </script>
  149. <style lang="less" scoped>
  150. @import (reference) '../../../design/index.less';
  151. .login {
  152. position: relative;
  153. height: 100vh;
  154. background: url(../../../assets/images/login/login-bg.png) no-repeat;
  155. background-size: 100% 100%;
  156. &-mask {
  157. display: none;
  158. height: 100%;
  159. background: url(../../../assets/images/login/login-in.png) no-repeat;
  160. background-position: 30% 30%;
  161. background-size: 80% 80%;
  162. .respond-to(xlarge, { display: block;});
  163. }
  164. &-form {
  165. width: 520px;
  166. background: @white;
  167. border: 10px solid rgba(255, 255, 255, 0.5);
  168. border-width: 8px;
  169. border-radius: 4px;
  170. background-clip: padding-box;
  171. .respond-to(xlarge, { margin: 0 120px 0 50px});
  172. &-wrap {
  173. position: absolute;
  174. top: 0;
  175. right: 0;
  176. display: flex;
  177. width: 100%;
  178. height: 90%;
  179. justify-content: center;
  180. align-items: center;
  181. .respond-to(large, {
  182. width: 600px;
  183. right: calc(50% - 270px);
  184. });
  185. .respond-to(xlarge, { width: 540px; right:0});
  186. }
  187. &__locale {
  188. position: absolute;
  189. top: 10px;
  190. right: 10px;
  191. }
  192. &__content {
  193. position: relative;
  194. width: 100%;
  195. height: 100%;
  196. border: 1px solid #999;
  197. border-radius: 2px;
  198. header {
  199. display: flex;
  200. justify-content: center;
  201. align-items: center;
  202. img {
  203. display: inline-block;
  204. width: 48px;
  205. }
  206. h1 {
  207. margin-bottom: 0;
  208. font-size: 24px;
  209. // color: @primary-color;
  210. text-align: center;
  211. }
  212. }
  213. form {
  214. width: 80%;
  215. }
  216. }
  217. }
  218. }
  219. </style>