|
|
@@ -64,45 +64,46 @@
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
- import { ref, reactive } from 'vue';
|
|
|
- import { useRouter } from 'vue-router';
|
|
|
- import { Message } from '@arco-design/web-vue';
|
|
|
- import { ValidatedError } from '@arco-design/web-vue/es/form/interface';
|
|
|
- import { useI18n } from 'vue-i18n';
|
|
|
- import { useStorage } from '@vueuse/core';
|
|
|
- import { useUserStore } from '@/store';
|
|
|
- import useLoading from '@/hooks/loading';
|
|
|
- import type { LoginData } from '@/api/user';
|
|
|
+import { ref, reactive } from 'vue';
|
|
|
+import { useRouter } from 'vue-router';
|
|
|
+import { Message } from '@arco-design/web-vue';
|
|
|
+import { ValidatedError } from '@arco-design/web-vue/es/form/interface';
|
|
|
+import { useI18n } from 'vue-i18n';
|
|
|
+import { useStorage } from '@vueuse/core';
|
|
|
+import { useUserStore } from '@/store';
|
|
|
+import useLoading from '@/hooks/loading';
|
|
|
+import type { LoginData } from '@/api/user';
|
|
|
|
|
|
- const router = useRouter();
|
|
|
- const { t } = useI18n();
|
|
|
- const errorMessage = ref('');
|
|
|
- const { loading, setLoading } = useLoading();
|
|
|
- const userStore = useUserStore();
|
|
|
+const router = useRouter();
|
|
|
+const { t } = useI18n();
|
|
|
+const errorMessage = ref('');
|
|
|
+const { loading, setLoading } = useLoading();
|
|
|
+const userStore = useUserStore();
|
|
|
|
|
|
- const loginConfig = useStorage('login-config', {
|
|
|
- rememberPassword: true,
|
|
|
- username: 'admin', // 演示默认值
|
|
|
- password: 'admin', // demo default value
|
|
|
- });
|
|
|
- const userInfo = reactive({
|
|
|
- username: loginConfig.value.username,
|
|
|
- password: loginConfig.value.password,
|
|
|
- });
|
|
|
+const loginConfig = useStorage('login-config', {
|
|
|
+ rememberPassword: true,
|
|
|
+ username: 'admin', // 演示默认值
|
|
|
+ password: 'admin', // demo default value
|
|
|
+});
|
|
|
+const userInfo = reactive({
|
|
|
+ username: loginConfig.value.username,
|
|
|
+ password: loginConfig.value.password,
|
|
|
+});
|
|
|
|
|
|
- const handleSubmit = async ({
|
|
|
- errors,
|
|
|
- values,
|
|
|
- }: {
|
|
|
- errors: Record<string, ValidatedError> | undefined;
|
|
|
- values: Record<string, any>;
|
|
|
- }) => {
|
|
|
- if (loading.value) return;
|
|
|
- if (!errors) {
|
|
|
- setLoading(true);
|
|
|
- try {
|
|
|
- await userStore.login(values as LoginData);
|
|
|
- const { redirect, ...othersQuery } = router.currentRoute.value.query;
|
|
|
+const handleSubmit = async ({
|
|
|
+ errors,
|
|
|
+ values,
|
|
|
+}: {
|
|
|
+ errors: Record<string, ValidatedError> | undefined;
|
|
|
+ values: Record<string, any>;
|
|
|
+}) => {
|
|
|
+ if (loading.value) return;
|
|
|
+ if (!errors) {
|
|
|
+ setLoading(true);
|
|
|
+ try {
|
|
|
+ const res = await userStore.login(values as LoginData);
|
|
|
+ const { redirect, ...othersQuery } = router.currentRoute.value.query;
|
|
|
+ if (res.success) {
|
|
|
router.push({
|
|
|
name: (redirect as string) || 'Workplace',
|
|
|
query: {
|
|
|
@@ -116,50 +117,53 @@
|
|
|
// The actual production environment requires encrypted storage.
|
|
|
loginConfig.value.username = rememberPassword ? username : '';
|
|
|
loginConfig.value.password = rememberPassword ? password : '';
|
|
|
- } catch (err) {
|
|
|
- errorMessage.value = (err as Error).message;
|
|
|
- } finally {
|
|
|
- setLoading(false);
|
|
|
+ } else {
|
|
|
+ Message.error(res.message);
|
|
|
}
|
|
|
+ } catch (err) {
|
|
|
+ errorMessage.value = (err as Error).message;
|
|
|
+ } finally {
|
|
|
+ setLoading(false);
|
|
|
}
|
|
|
- };
|
|
|
- const setRememberPassword = (value: boolean) => {
|
|
|
- loginConfig.value.rememberPassword = value;
|
|
|
- };
|
|
|
+ }
|
|
|
+};
|
|
|
+const setRememberPassword = (value: boolean) => {
|
|
|
+ loginConfig.value.rememberPassword = value;
|
|
|
+};
|
|
|
</script>
|
|
|
|
|
|
<style lang="less" scoped>
|
|
|
- .login-form {
|
|
|
- &-wrapper {
|
|
|
- width: 320px;
|
|
|
- }
|
|
|
+.login-form {
|
|
|
+ &-wrapper {
|
|
|
+ width: 320px;
|
|
|
+ }
|
|
|
|
|
|
- &-title {
|
|
|
- color: var(--color-text-1);
|
|
|
- font-weight: 500;
|
|
|
- font-size: 24px;
|
|
|
- line-height: 32px;
|
|
|
- }
|
|
|
+ &-title {
|
|
|
+ color: var(--color-text-1);
|
|
|
+ font-weight: 500;
|
|
|
+ font-size: 24px;
|
|
|
+ line-height: 32px;
|
|
|
+ }
|
|
|
|
|
|
- &-sub-title {
|
|
|
- color: var(--color-text-3);
|
|
|
- font-size: 16px;
|
|
|
- line-height: 24px;
|
|
|
- }
|
|
|
+ &-sub-title {
|
|
|
+ color: var(--color-text-3);
|
|
|
+ font-size: 16px;
|
|
|
+ line-height: 24px;
|
|
|
+ }
|
|
|
|
|
|
- &-error-msg {
|
|
|
- height: 32px;
|
|
|
- color: rgb(var(--red-6));
|
|
|
- line-height: 32px;
|
|
|
- }
|
|
|
+ &-error-msg {
|
|
|
+ height: 32px;
|
|
|
+ color: rgb(var(--red-6));
|
|
|
+ line-height: 32px;
|
|
|
+ }
|
|
|
|
|
|
- &-password-actions {
|
|
|
- display: flex;
|
|
|
- justify-content: space-between;
|
|
|
- }
|
|
|
+ &-password-actions {
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+ }
|
|
|
|
|
|
- &-register-btn {
|
|
|
- color: var(--color-text-3) !important;
|
|
|
- }
|
|
|
+ &-register-btn {
|
|
|
+ color: var(--color-text-3) !important;
|
|
|
}
|
|
|
+}
|
|
|
</style>
|