提交 | 用户 | 时间
|
820397
|
1 |
<script setup lang="ts"> |
H |
2 |
import { useValidator } from '@/hooks/web/useValidator' |
|
3 |
import { useDesign } from '@/hooks/web/useDesign' |
|
4 |
import { useLockStore } from '@/store/modules/lock' |
|
5 |
import avatarImg from '@/assets/imgs/avatar.gif' |
|
6 |
import { useUserStore } from '@/store/modules/user' |
|
7 |
|
|
8 |
const { getPrefixCls } = useDesign() |
|
9 |
const prefixCls = getPrefixCls('lock-dialog') |
|
10 |
|
|
11 |
const { required } = useValidator() |
|
12 |
|
|
13 |
const { t } = useI18n() |
|
14 |
|
|
15 |
const lockStore = useLockStore() |
|
16 |
|
|
17 |
const props = defineProps({ |
|
18 |
modelValue: { |
|
19 |
type: Boolean |
|
20 |
} |
|
21 |
}) |
|
22 |
|
|
23 |
const userStore = useUserStore() |
3e359e
|
24 |
const avatar = computed(() => userStore.user.avatar || avatarImg) |
820397
|
25 |
const userName = computed(() => userStore.user.nickname ?? 'Admin') |
H |
26 |
|
|
27 |
const emit = defineEmits(['update:modelValue']) |
|
28 |
|
|
29 |
const dialogVisible = computed({ |
|
30 |
get: () => props.modelValue, |
|
31 |
set: (val) => { |
|
32 |
console.log('set: ', val) |
|
33 |
emit('update:modelValue', val) |
|
34 |
} |
|
35 |
}) |
|
36 |
|
|
37 |
const dialogTitle = ref(t('lock.lockScreen')) |
|
38 |
|
|
39 |
const formData = ref({ |
|
40 |
password: undefined |
|
41 |
}) |
|
42 |
const formRules = reactive({ |
|
43 |
password: [required()] |
|
44 |
}) |
|
45 |
|
|
46 |
const formRef = ref() // 表单 Ref |
|
47 |
const handleLock = async () => { |
|
48 |
// 校验表单 |
|
49 |
if (!formRef) return |
|
50 |
const valid = await formRef.value.validate() |
|
51 |
if (!valid) return |
|
52 |
// 提交请求 |
|
53 |
dialogVisible.value = false |
|
54 |
lockStore.setLockInfo({ |
|
55 |
...formData.value, |
|
56 |
isLock: true |
|
57 |
}) |
|
58 |
} |
|
59 |
</script> |
|
60 |
|
|
61 |
<template> |
|
62 |
<Dialog |
|
63 |
v-model="dialogVisible" |
|
64 |
width="500px" |
|
65 |
max-height="170px" |
|
66 |
:class="prefixCls" |
|
67 |
:title="dialogTitle" |
|
68 |
> |
|
69 |
<div class="flex flex-col items-center"> |
|
70 |
<img :src="avatar" alt="" class="w-70px h-70px rounded-[50%]" /> |
|
71 |
<span class="text-14px my-10px text-[var(--top-header-text-color)]"> |
|
72 |
{{ userName }} |
|
73 |
</span> |
|
74 |
</div> |
|
75 |
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="80px"> |
|
76 |
<el-form-item :label="t('lock.lockPassword')" prop="password"> |
|
77 |
<el-input |
|
78 |
type="password" |
|
79 |
v-model="formData.password" |
|
80 |
:placeholder="'请输入' + t('lock.lockPassword')" |
|
81 |
clearable |
|
82 |
show-password |
|
83 |
/> |
|
84 |
</el-form-item> |
|
85 |
</el-form> |
|
86 |
<template #footer> |
|
87 |
<ElButton type="primary" @click="handleLock">{{ t('lock.lock') }}</ElButton> |
|
88 |
</template> |
|
89 |
</Dialog> |
|
90 |
</template> |
|
91 |
|
|
92 |
<style lang="scss" scoped> |
|
93 |
:global(.v-lock-dialog) { |
|
94 |
@media (max-width: 767px) { |
|
95 |
max-width: calc(100vw - 16px); |
|
96 |
} |
|
97 |
} |
|
98 |
</style> |