/** * * @author Ray * * @date 2023-06-20 * * @workspace ray-template * * @remark 今天也是元气满满撸代码的一天 */ /** 解锁界面 */ import { NInput, NForm, NFormItem, NButton, NFlex } from 'naive-ui' import AppAvatar from '@/app-components/app/AppAvatar' import dayjs from 'dayjs' import { useSigningActions, useSettingActions } from '@/store' import { rules, useCondition } from '@/app-components/app/AppLockScreen/shared' import useAppLockScreen from '@/app-components/app/AppLockScreen/appLockVar' import { useDevice } from '@/hooks' import type { FormInst, InputInst } from 'naive-ui' export default defineComponent({ name: 'UnlockScreen', setup() { const formRef = ref(null) const inputInstRef = ref(null) const { logout } = useSigningActions() const { updateSettingState } = useSettingActions() const { setLockAppScreen } = useAppLockScreen() const { isTabletOrSmaller } = useDevice() const HH_MM_FORMAT = 'HH:mm' const AM_PM_FORMAT = 'A' const YY_MM_DD_FORMAT = 'YY年MM月DD日' const DDD_FORMAT = 'ddd' const state = reactive({ lockCondition: useCondition(), HH_MM: dayjs().format(HH_MM_FORMAT), AM_PM: dayjs().locale('en').format(AM_PM_FORMAT), YY_MM_DD: dayjs().format(YY_MM_DD_FORMAT), DDD: dayjs().format(DDD_FORMAT), }) const dayInterval = setInterval(() => { state.HH_MM = dayjs().format(HH_MM_FORMAT) state.AM_PM = dayjs().format(AM_PM_FORMAT) }, 6_000) const yearInterval = setInterval(() => { state.YY_MM_DD = dayjs().format(YY_MM_DD_FORMAT) state.DDD = dayjs().format(DDD_FORMAT) }, 86_400_000) /** 退出登陆并且回到登陆页 */ const backToSigning = () => { window.$dialog.warning({ title: '警告', content: '是否返回到登陆页?', positiveText: '确定', negativeText: '取消', onPositiveClick: () => { logout() setTimeout(() => { updateSettingState('lockScreenSwitch', false) }) }, }) } /** 解锁 */ const unlockScreen = () => { formRef.value?.validate((error) => { if (!error) { setLockAppScreen(false) updateSettingState('lockScreenSwitch', false) state.lockCondition = useCondition() } }) } onBeforeUnmount(() => { clearInterval(dayInterval) clearInterval(yearInterval) }) return { ...toRefs(state), backToSigning, unlockScreen, formRef, inputInstRef, isTabletOrSmaller, } }, render() { const { isTabletOrSmaller } = this const { HH_MM, AM_PM, YY_MM_DD, DDD } = this const hmSplit = HH_MM.split(':') const { unlockScreen, backToSigning } = this return (
{hmSplit[0]}
{hmSplit[1]}
{ if (e.code === 'Enter') { unlockScreen() } }} /> 返回登陆 进入系统
) }, })