Blame view

src/layouts/default/header/components/lock/LockAction.tsx 2.03 KB
vben authored
1
import './LockAction.less';
vben authored
2
陈文彬 authored
3
4
import { defineComponent } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal/index';
vben authored
5
import { Button } from '/@/components/Button';
陈文彬 authored
6
7
8
9
10
import { BasicForm, useForm } from '/@/components/Form/index';

import headerImg from '/@/assets/images/header.jpg';

import { userStore } from '/@/store/modules/user';
vben authored
11
import { useI18n } from '/@/hooks/web/useI18n';
12
import { lockStore } from '/@/store/modules/lock';
vben authored
13
陈文彬 authored
14
15
16
17
const prefixCls = 'lock-modal';
export default defineComponent({
  name: 'LockModal',
  setup(_, { attrs }) {
18
    const { t } = useI18n();
vben authored
19
20
    const [register, { closeModal }] = useModalInner();
陈文彬 authored
21
22
23
24
25
    const [registerForm, { validateFields, resetFields }] = useForm({
      showActionButtonGroup: false,
      schemas: [
        {
          field: 'password',
26
          label: t('layout.header.lockScreenPassword'),
陈文彬 authored
27
          component: 'InputPassword',
vben authored
28
          required: true,
陈文彬 authored
29
30
31
        },
      ],
    });
vben authored
32
33
34
35
36
    async function lock() {
      const values = (await validateFields()) as any;
      const password: string | undefined = values.password;
      closeModal();
陈文彬 authored
37
38
39
40
41
42
      lockStore.commitLockInfoState({
        isLock: true,
        pwd: password,
      });
      await resetFields();
陈文彬 authored
43
    }
vben authored
44
陈文彬 authored
45
    return () => (
vben authored
46
47
      <BasicModal
        footer={null}
48
        title={t('layout.header.lockScreen')}
vben authored
49
50
51
52
        {...attrs}
        class={prefixCls}
        onRegister={register}
      >
陈文彬 authored
53
54
55
56
57
58
        {() => (
          <div class={`${prefixCls}__entry`}>
            <div class={`${prefixCls}__header`}>
              <img src={headerImg} class={`${prefixCls}__header-img`} />
              <p class={`${prefixCls}__header-name`}>{userStore.getUserInfoState.realName}</p>
            </div>
vben authored
59
vben authored
60
            <BasicForm onRegister={registerForm} />
vben authored
61
陈文彬 authored
62
63
            <div class={`${prefixCls}__footer`}>
              <Button type="primary" block class="mt-2" onClick={lock}>
64
                {() => t('layout.header.lockScreenBtn')}
陈文彬 authored
65
66
67
68
69
70
71
72
              </Button>
            </div>
          </div>
        )}
      </BasicModal>
    );
  },
});