提交 | 用户 | age
|
ec9478
|
1 |
<template> |
a09a0e
|
2 |
<LoginFormTitle v-show="getShow" class="enter-x" /> |
bb0d2e
|
3 |
<Form |
N |
4 |
class="p-4 enter-x" |
|
5 |
:model="formData" |
|
6 |
:rules="getFormRules" |
|
7 |
ref="formRef" |
|
8 |
v-show="getShow" |
|
9 |
@keypress.enter="handleLogin" |
|
10 |
> |
ec9478
|
11 |
<FormItem name="account" class="enter-x"> |
cebc6a
|
12 |
<Input |
无 |
13 |
size="large" |
|
14 |
v-model:value="formData.account" |
|
15 |
:placeholder="t('sys.login.userName')" |
|
16 |
class="fix-auto-fill" |
|
17 |
/> |
ec9478
|
18 |
</FormItem> |
V |
19 |
<FormItem name="password" class="enter-x"> |
|
20 |
<InputPassword |
|
21 |
size="large" |
|
22 |
visibilityToggle |
|
23 |
v-model:value="formData.password" |
|
24 |
:placeholder="t('sys.login.password')" |
|
25 |
/> |
|
26 |
</FormItem> |
|
27 |
|
|
28 |
<ARow class="enter-x"> |
|
29 |
<ACol :span="12"> |
|
30 |
<FormItem> |
|
31 |
<!-- No logic, you need to deal with it yourself --> |
|
32 |
<Checkbox v-model:checked="rememberMe" size="small"> |
|
33 |
{{ t('sys.login.rememberMe') }} |
|
34 |
</Checkbox> |
|
35 |
</FormItem> |
|
36 |
</ACol> |
|
37 |
<ACol :span="12"> |
|
38 |
<FormItem :style="{ 'text-align': 'right' }"> |
|
39 |
<!-- No logic, you need to deal with it yourself --> |
|
40 |
<Button type="link" size="small" @click="setLoginState(LoginStateEnum.RESET_PASSWORD)"> |
|
41 |
{{ t('sys.login.forgetPassword') }} |
|
42 |
</Button> |
|
43 |
</FormItem> |
|
44 |
</ACol> |
|
45 |
</ARow> |
|
46 |
|
|
47 |
<FormItem class="enter-x"> |
a09a0e
|
48 |
<Button type="primary" size="large" block @click="handleLogin" :loading="loading"> |
ec9478
|
49 |
{{ t('sys.login.loginButton') }} |
V |
50 |
</Button> |
|
51 |
<!-- <Button size="large" class="mt-4 enter-x" block @click="handleRegister"> |
|
52 |
{{ t('sys.login.registerButton') }} |
|
53 |
</Button> --> |
|
54 |
</FormItem> |
b660f9
|
55 |
<ARow class="enter-x" :gutter="[16, 16]"> |
5e17cc
|
56 |
<ACol :md="8" :xs="24"> |
ec9478
|
57 |
<Button block @click="setLoginState(LoginStateEnum.MOBILE)"> |
V |
58 |
{{ t('sys.login.mobileSignInFormTitle') }} |
|
59 |
</Button> |
|
60 |
</ACol> |
b660f9
|
61 |
<ACol :md="8" :xs="24"> |
ec9478
|
62 |
<Button block @click="setLoginState(LoginStateEnum.QR_CODE)"> |
V |
63 |
{{ t('sys.login.qrSignInFormTitle') }} |
|
64 |
</Button> |
|
65 |
</ACol> |
b660f9
|
66 |
<ACol :md="8" :xs="24"> |
ec9478
|
67 |
<Button block @click="setLoginState(LoginStateEnum.REGISTER)"> |
V |
68 |
{{ t('sys.login.registerButton') }} |
|
69 |
</Button> |
|
70 |
</ACol> |
|
71 |
</ARow> |
|
72 |
|
a09a0e
|
73 |
<Divider class="enter-x">{{ t('sys.login.otherSignIn') }}</Divider> |
ec9478
|
74 |
|
V |
75 |
<div class="flex justify-evenly enter-x" :class="`${prefixCls}-sign-in-way`"> |
|
76 |
<GithubFilled /> |
|
77 |
<WechatFilled /> |
|
78 |
<AlipayCircleFilled /> |
|
79 |
<GoogleCircleFilled /> |
|
80 |
<TwitterCircleFilled /> |
|
81 |
</div> |
|
82 |
</Form> |
|
83 |
</template> |
bb89c5
|
84 |
<script lang="ts" setup> |
590288
|
85 |
import { reactive, ref, unref, computed } from 'vue'; |
ec9478
|
86 |
|
V |
87 |
import { Checkbox, Form, Input, Row, Col, Button, Divider } from 'ant-design-vue'; |
|
88 |
import { |
|
89 |
GithubFilled, |
|
90 |
WechatFilled, |
|
91 |
AlipayCircleFilled, |
|
92 |
GoogleCircleFilled, |
|
93 |
TwitterCircleFilled, |
|
94 |
} from '@ant-design/icons-vue'; |
a09a0e
|
95 |
import LoginFormTitle from './LoginFormTitle.vue'; |
ec9478
|
96 |
|
9fad2a
|
97 |
import { useI18n } from '@/hooks/web/useI18n'; |
X |
98 |
import { useMessage } from '@/hooks/web/useMessage'; |
ec9478
|
99 |
|
9fad2a
|
100 |
import { useUserStore } from '@/store/modules/user'; |
ec9478
|
101 |
import { LoginStateEnum, useLoginState, useFormRules, useFormValid } from './useLogin'; |
9fad2a
|
102 |
import { useDesign } from '@/hooks/web/useDesign'; |
bb0d2e
|
103 |
//import { onKeyStroke } from '@vueuse/core'; |
b5c161
|
104 |
import { loginDo } from '@/api/sys/onbusUser'; |
ec9478
|
105 |
|
bb89c5
|
106 |
const ACol = Col; |
V |
107 |
const ARow = Row; |
|
108 |
const FormItem = Form.Item; |
|
109 |
const InputPassword = Input.Password; |
|
110 |
const { t } = useI18n(); |
|
111 |
const { notification, createErrorModal } = useMessage(); |
|
112 |
const { prefixCls } = useDesign('login'); |
|
113 |
const userStore = useUserStore(); |
ec9478
|
114 |
|
bb89c5
|
115 |
const { setLoginState, getLoginState } = useLoginState(); |
V |
116 |
const { getFormRules } = useFormRules(); |
ec9478
|
117 |
|
bb89c5
|
118 |
const formRef = ref(); |
V |
119 |
const loading = ref(false); |
|
120 |
const rememberMe = ref(false); |
ec9478
|
121 |
|
bb89c5
|
122 |
const formData = reactive({ |
b5c161
|
123 |
account: 'z9000011', |
S |
124 |
password: '606063', |
ec9478
|
125 |
}); |
bb89c5
|
126 |
|
V |
127 |
const { validForm } = useFormValid(formRef); |
|
128 |
|
|
129 |
//onKeyStroke('Enter', handleLogin); |
|
130 |
|
|
131 |
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN); |
|
132 |
|
|
133 |
async function handleLogin() { |
|
134 |
const data = await validForm(); |
|
135 |
if (!data) return; |
|
136 |
try { |
|
137 |
loading.value = true; |
b5c161
|
138 |
if (data.account.startsWith('z9000')) { |
S |
139 |
try { |
|
140 |
let res = await loginDo({ |
|
141 |
password: data.password, |
|
142 |
account: data.account, |
|
143 |
}); |
|
144 |
Logger.log('登录的res为:', res); |
|
145 |
if(res.msg == '登录成功'){ |
|
146 |
data.password = '123456'; |
|
147 |
data.account = 'vben'; |
|
148 |
} |
|
149 |
} catch (error) { |
|
150 |
Logger.error('登录的userInfo err为:', error); |
|
151 |
} |
|
152 |
} |
590288
|
153 |
const userInfo = await userStore.login({ |
M |
154 |
password: data.password, |
|
155 |
username: data.account, |
|
156 |
mode: 'none', //不要默认的错误提示 |
|
157 |
}); |
bb89c5
|
158 |
if (userInfo) { |
V |
159 |
notification.success({ |
|
160 |
message: t('sys.login.loginSuccessTitle'), |
|
161 |
description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.realName}`, |
|
162 |
duration: 3, |
|
163 |
}); |
|
164 |
} |
|
165 |
} catch (error) { |
|
166 |
createErrorModal({ |
|
167 |
title: t('sys.api.errorTip'), |
590288
|
168 |
content: (error as unknown as Error).message || t('sys.api.networkExceptionMsg'), |
bb89c5
|
169 |
getContainer: () => document.body.querySelector(`.${prefixCls}`) || document.body, |
V |
170 |
}); |
|
171 |
} finally { |
|
172 |
loading.value = false; |
|
173 |
} |
|
174 |
} |
ec9478
|
175 |
</script> |