LockModal.vue 3.0 KB

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