Skip to content

Commit 4e264c5

Browse files
committed
fix: 锁屏和解锁密码输入框自动聚焦
1 parent 32051e9 commit 4e264c5

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

packages/effects/layouts/src/widgets/lock-screen/lock-screen-modal.vue

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,30 @@ const emit = defineEmits<{
2727
submit: [Recordable<any>];
2828
}>();
2929
30-
const [Form, { resetForm, validate, getValues }] = useVbenForm(
31-
reactive({
32-
commonConfig: {
33-
hideLabel: true,
34-
hideRequiredMark: true,
35-
},
36-
schema: computed(() => [
37-
{
38-
component: 'VbenInputPassword' as const,
39-
componentProps: {
40-
placeholder: $t('ui.widgets.lockScreen.placeholder'),
41-
},
42-
fieldName: 'lockScreenPassword',
43-
formFieldProps: { validateOnBlur: false },
44-
label: $t('authentication.password'),
45-
rules: z
46-
.string()
47-
.min(1, { message: $t('ui.widgets.lockScreen.placeholder') }),
30+
const [Form, { resetForm, validate, getValues, getFieldComponentRef }] =
31+
useVbenForm(
32+
reactive({
33+
commonConfig: {
34+
hideLabel: true,
35+
hideRequiredMark: true,
4836
},
49-
]),
50-
showDefaultActions: false,
51-
}),
52-
);
37+
schema: computed(() => [
38+
{
39+
component: 'VbenInputPassword' as const,
40+
componentProps: {
41+
placeholder: $t('ui.widgets.lockScreen.placeholder'),
42+
},
43+
fieldName: 'lockScreenPassword',
44+
formFieldProps: { validateOnBlur: false },
45+
label: $t('authentication.password'),
46+
rules: z
47+
.string()
48+
.min(1, { message: $t('ui.widgets.lockScreen.placeholder') }),
49+
},
50+
]),
51+
showDefaultActions: false,
52+
}),
53+
);
5354
5455
const [Modal] = useVbenModal({
5556
onConfirm() {
@@ -60,6 +61,13 @@ const [Modal] = useVbenModal({
6061
resetForm();
6162
}
6263
},
64+
onOpened() {
65+
requestAnimationFrame(() => {
66+
getFieldComponentRef('lockScreenPassword')
67+
?.$el?.querySelector('[name="lockScreenPassword"]')
68+
?.focus();
69+
});
70+
},
6371
});
6472
6573
async function handleSubmit() {

packages/effects/layouts/src/widgets/lock-screen/lock-screen.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const date = useDateFormat(now, 'YYYY-MM-DD dddd', { locales: locale.value });
3737
const showUnlockForm = ref(false);
3838
const { lockScreenPassword } = storeToRefs(accessStore);
3939
40-
const [Form, { form, validate }] = useVbenForm(
40+
const [Form, { form, validate, getFieldComponentRef }] = useVbenForm(
4141
reactive({
4242
commonConfig: {
4343
hideLabel: true,
@@ -75,6 +75,13 @@ async function handleSubmit() {
7575
7676
function toggleUnlockForm() {
7777
showUnlockForm.value = !showUnlockForm.value;
78+
if (showUnlockForm.value) {
79+
requestAnimationFrame(() => {
80+
getFieldComponentRef('password')
81+
?.$el?.querySelector('[name="password"]')
82+
?.focus();
83+
});
84+
}
7885
}
7986
8087
useScrollLock();

0 commit comments

Comments
 (0)