perf: 优化锁屏组件
This commit is contained in:
parent
cdf44a43a0
commit
4f8330a4fa
|
@ -1,12 +1,12 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { ref, unref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { Dialog } from '@/components/Dialog'
|
import { Dialog } from '@/components/Dialog'
|
||||||
import { Form } from '@/components/Form'
|
import { Form } from '@/components/Form'
|
||||||
import { useForm } from '@/hooks/web/useForm'
|
import { useForm } from '@/hooks/web/useForm'
|
||||||
import { reactive, computed } from 'vue'
|
import { reactive, computed } from 'vue'
|
||||||
import { useValidator } from '@/hooks/web/useValidator'
|
import { useValidator } from '@/hooks/web/useValidator'
|
||||||
import { FormSchema } from '@/types/form'
|
import { FormSchema } from '@/components/Form'
|
||||||
import { ElButton } from 'element-plus'
|
import { ElButton } from 'element-plus'
|
||||||
import { useDesign } from '@/hooks/web/useDesign'
|
import { useDesign } from '@/hooks/web/useDesign'
|
||||||
import { useLockStore } from '@/store/modules/lock'
|
import { useLockStore } from '@/store/modules/lock'
|
||||||
|
@ -54,14 +54,13 @@ const schema: FormSchema[] = reactive([
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
const { register, formRef, methods } = useForm({
|
const { formRegister, formMethods } = useForm()
|
||||||
schema
|
|
||||||
})
|
|
||||||
|
|
||||||
const { getFormData } = methods
|
const { getFormData, getElFormExpose } = formMethods
|
||||||
|
|
||||||
const handleLock = () => {
|
const handleLock = async () => {
|
||||||
unref(formRef)?.validate(async (valid) => {
|
const formExpose = await getElFormExpose()
|
||||||
|
formExpose?.validate(async (valid) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false
|
||||||
const formData = await getFormData()
|
const formData = await getFormData()
|
||||||
|
@ -86,7 +85,7 @@ const handleLock = () => {
|
||||||
<img src="@/assets/imgs/avatar.jpg" alt="" class="w-70px h-70px rounded-[50%]" />
|
<img src="@/assets/imgs/avatar.jpg" alt="" class="w-70px h-70px rounded-[50%]" />
|
||||||
<span class="text-14px my-10px text-[var(--top-header-text-color)]">Archer</span>
|
<span class="text-14px my-10px text-[var(--top-header-text-color)]">Archer</span>
|
||||||
</div>
|
</div>
|
||||||
<Form :is-col="false" :rules="rules" @register="register" />
|
<Form :is-col="false" :schema="schema" :rules="rules" @register="formRegister" />
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<ElButton type="primary" @click="handleLock">{{ t('lock.lock') }}</ElButton>
|
<ElButton type="primary" @click="handleLock">{{ t('lock.lock') }}</ElButton>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { useRouter } from 'vue-router'
|
||||||
import { useCache } from '@/hooks/web/useCache'
|
import { useCache } from '@/hooks/web/useCache'
|
||||||
import { useLockStore } from '@/store/modules/lock'
|
import { useLockStore } from '@/store/modules/lock'
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { useNow } from './useNow'
|
import { useNow } from '@/hooks/web/useNow'
|
||||||
import { useDesign } from '@/hooks/web/useDesign'
|
import { useDesign } from '@/hooks/web/useDesign'
|
||||||
import { Icon } from '@/components/Icon'
|
import { Icon } from '@/components/Icon'
|
||||||
import { loginOutApi } from '@/api/login'
|
import { loginOutApi } from '@/api/login'
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { dateUtil } from '@/utils/dateUtil'
|
||||||
import { reactive, toRefs } from 'vue'
|
import { reactive, toRefs } from 'vue'
|
||||||
import { tryOnMounted, tryOnUnmounted } from '@vueuse/core'
|
import { tryOnMounted, tryOnUnmounted } from '@vueuse/core'
|
||||||
|
|
||||||
export function useNow(immediate = true) {
|
export const useNow = (immediate = true) => {
|
||||||
let timer: IntervalHandle
|
let timer: IntervalHandle
|
||||||
|
|
||||||
const state = reactive({
|
const state = reactive({
|
Loading…
Reference in New Issue