LockModal.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <BasicModal
  3. :footer="null"
  4. :title="t('layout.header.lockScreen')"
  5. v-bind="$attrs"
  6. :class="prefixCls"
  7. @register="register"
  8. >
  9. <div :class="`${prefixCls}__entry`">
  10. <div :class="`${prefixCls}__header`">
  11. <img :src="avatar" :class="`${prefixCls}__header-img`" />
  12. <p :class="`${prefixCls}__header-name`">
  13. {{ getRealName }}
  14. </p>
  15. </div>
  16. <BasicForm @register="registerForm" />
  17. <div :class="`${prefixCls}__footer`">
  18. <a-button type="primary" block class="mt-2" @click="handleLock">
  19. {{ t('layout.header.lockScreenBtn') }}
  20. </a-button>
  21. </div>
  22. </div>
  23. </BasicModal>
  24. </template>
  25. <script lang="ts" setup>
  26. import { computed } from 'vue';
  27. import { useI18n } from '@/hooks/web/useI18n';
  28. import { useDesign } from '@/hooks/web/useDesign';
  29. import { BasicModal, useModalInner } from '@/components/Modal';
  30. import { BasicForm, useForm } from '@/components/Form';
  31. import { useUserStore } from '@/store/modules/user';
  32. import { useLockStore } from '@/store/modules/lock';
  33. import headerImg from '@/assets/images/header.jpg';
  34. defineOptions({ name: 'LockModal' });
  35. const { t } = useI18n();
  36. const { prefixCls } = useDesign('header-lock-modal');
  37. const userStore = useUserStore();
  38. const lockStore = useLockStore();
  39. const getRealName = computed(() => userStore.getUserInfo?.realName);
  40. const [register, { closeModal }] = useModalInner();
  41. const [registerForm, { validate, resetFields }] = useForm({
  42. showActionButtonGroup: false,
  43. schemas: [
  44. {
  45. field: 'password',
  46. label: t('layout.header.lockScreenPassword'),
  47. colProps: {
  48. span: 24,
  49. },
  50. component: 'InputPassword',
  51. required: true,
  52. },
  53. ],
  54. });
  55. const handleLock = async () => {
  56. const { password = '' } = await validate<{
  57. password: string;
  58. }>();
  59. closeModal();
  60. lockStore.setLockInfo({
  61. isLock: true,
  62. pwd: password,
  63. });
  64. await resetFields();
  65. };
  66. const avatar = computed(() => {
  67. const { avatar } = userStore.getUserInfo;
  68. return avatar || headerImg;
  69. });
  70. </script>
  71. <style lang="less">
  72. @prefix-cls: ~'@{namespace}-header-lock-modal';
  73. .@{prefix-cls} {
  74. &__entry {
  75. position: relative;
  76. //height: 240px;
  77. padding: 130px 30px 30px;
  78. border-radius: 10px;
  79. }
  80. &__header {
  81. position: absolute;
  82. top: 0;
  83. left: calc(50% - 45px);
  84. width: auto;
  85. text-align: center;
  86. &-img {
  87. width: 70px;
  88. border-radius: 50%;
  89. }
  90. &-name {
  91. margin-top: 5px;
  92. }
  93. }
  94. &__footer {
  95. text-align: center;
  96. }
  97. }
  98. </style>