()
| 21 | const timeOut = 60 * 60 * 1000 |
| 22 | |
| 23 | const LockSleep: FC = () => { |
| 24 | const { formatMessage } = useIntl(); |
| 25 | const { initialState } = useModel('@@initialState'); |
| 26 | // hooks 调用 |
| 27 | const { message } = App.useApp(); |
| 28 | // 弹窗显示 |
| 29 | const [openModal, { setTrue, setFalse }] = useBoolean(false); |
| 30 | // 表单实例 |
| 31 | const [form] = Form.useForm() |
| 32 | // 获取 LOCK_SLEEP 信息 |
| 33 | const LOCK_SLEEP = getLocalStorageItem<LockSleepTypes>(LOCAL_STORAGE.LOCK_SLEEP) |
| 34 | // 判断用户未操作时间是否拆过设定值 |
| 35 | const checkTimeout = () => { |
| 36 | const currentTime = new Date().getTime() |
| 37 | // 判断是否超时 |
| 38 | if (LOCK_SLEEP && (currentTime - LOCK_SLEEP.last_time > timeOut)) { |
| 39 | setTrue() |
| 40 | setLocalStorageItem(LOCAL_STORAGE.LOCK_SLEEP, { ...LOCK_SLEEP, isSleep: true }) |
| 41 | } |
| 42 | } |
| 43 | // 提交表单 |
| 44 | const hanlderSubmit = () => { |
| 45 | // 触发表单校验 |
| 46 | form.validateFields().then((values: { password: string }) => { |
| 47 | if (LOCK_SLEEP && initialState?.CurrentUser?.password === encryptionAesPsd(values.password)) { |
| 48 | setFalse() |
| 49 | setLocalStorageItem(LOCAL_STORAGE.LOCK_SLEEP, { ...LOCK_SLEEP, isSleep: false }) |
| 50 | } else { |
| 51 | message.error(formatMessage({ id: `${INTERNATION.BASICLAYOUT}.LockSleep.password.error` })) |
| 52 | } |
| 53 | }) |
| 54 | }; |
| 55 | |
| 56 | useInterval(() => { |
| 57 | checkTimeout() |
| 58 | }, timeOut); |
| 59 | |
| 60 | // 监听用户是否有操作行为 |
| 61 | useEventListener('mousemove', () => { |
| 62 | if (LOCK_SLEEP) { |
| 63 | setLocalStorageItem(LOCAL_STORAGE.LOCK_SLEEP, { ...LOCK_SLEEP, last_time: new Date().getTime() }) |
| 64 | } |
| 65 | }) |
| 66 | |
| 67 | // 一开始就检测 |
| 68 | useMount(() => { |
| 69 | if (LOCK_SLEEP?.isSleep) { |
| 70 | setTrue() |
| 71 | } |
| 72 | setLocalStorageItem(LOCAL_STORAGE.LOCK_SLEEP, { |
| 73 | last_time: new Date().getTime(), |
| 74 | isSleep: false, |
| 75 | }) |
| 76 | }) |
| 77 | return ( |
| 78 | <Modal |
| 79 | title={formatMessage({ id: `${INTERNATION.BASICLAYOUT}.LockSleep.title` })} |
| 80 | open={openModal} |
nothing calls this directly
no test coverage detected