Blame view

src/views/sys/lock/index.vue 3.76 KB
陈文彬 authored
1
2
3
4
5
6
7
8
<template>
  <div class="lock-page">
    <div class="lock-page__entry">
      <div class="lock-page__header">
        <img src="../../../assets/images/header.jpg" class="lock-page__header-img" />
        <p class="lock-page__header-name">{{ realName }}</p>
      </div>
      <BasicForm @register="register" v-if="!getIsNotPwd" />
vben authored
9
      <Alert v-if="errMsgRef" type="error" :message="t('alert')" banner />
陈文彬 authored
10
11
      <div class="lock-page__footer">
        <a-button type="default" class="mt-2 mr-2" @click="goLogin" v-if="!getIsNotPwd">
vben authored
12
          {{ t('sys.lock.backToLogin') }}
陈文彬 authored
13
14
        </a-button>
        <a-button type="primary" class="mt-2" @click="unLock(!getIsNotPwd)" :loading="loadingRef">
vben authored
15
          {{ t('sys.lock.entry') }}
陈文彬 authored
16
17
18
19
20
21
22
23
        </a-button>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
  import { defineComponent, ref, computed } from 'vue';
  import { Alert } from 'ant-design-vue';
vben authored
24
陈文彬 authored
25
26
27
28
  import { BasicForm, useForm } from '/@/components/Form';

  import { userStore } from '/@/store/modules/user';
  import { appStore } from '/@/store/modules/app';
vben authored
29
  import { useI18n } from '/@/hooks/web/useI18n';
vben authored
30
陈文彬 authored
31
32
33
34
35
36
37
  export default defineComponent({
    name: 'LockPage',
    components: { Alert, BasicForm },

    setup() {
      const loadingRef = ref(false);
      const errMsgRef = ref(false);
vben authored
38
39
      const { t } = useI18n();
陈文彬 authored
40
41
42
43
44
45
46
47
48
      const [register, { validateFields }] = useForm({
        showActionButtonGroup: false,
        schemas: [
          {
            field: 'password',
            label: '',
            component: 'InputPassword',
            componentProps: {
              style: { width: '100%' },
49
              placeholder: t('sys.lock.placeholder'),
陈文彬 authored
50
51
52
53
54
55
56
57
58
            },
            rules: [{ required: true }],
          },
        ],
      });
      const realName = computed(() => {
        const { realName } = userStore.getUserInfoState || {};
        return realName;
      });
vben authored
59
60
61
62
63
64
65
66

      const getIsNotPwd = computed(() => {
        if (!appStore.getLockInfo) {
          return true;
        }
        return appStore.getLockInfo.pwd === undefined;
      });
陈文彬 authored
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
      /**
       * @description: unLock
       */
      async function unLock(valid = true) {
        let password = '';
        if (valid) {
          try {
            const values = (await validateFields()) as any;
            password = values.password;
          } catch (error) {
            return;
          }
        }
        try {
          loadingRef.value = true;
          const res = await appStore.unLockAction({ password, valid });
          errMsgRef.value = !res;
        } finally {
          loadingRef.value = false;
        }
      }
vben authored
88
陈文彬 authored
89
90
91
92
      function goLogin() {
        userStore.loginOut(true);
        appStore.resetLockInfo();
      }
vben authored
93
陈文彬 authored
94
95
96
97
98
99
100
101
      return {
        register,
        getIsNotPwd,
        goLogin,
        realName,
        unLock,
        errMsgRef,
        loadingRef,
vben authored
102
        t,
陈文彬 authored
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
      };
    },
  });
</script>
<style lang="less" scoped>
  @import (reference) '../../../design/index.less';

  .lock-page {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 999999;
    display: flex;
    width: 100vw;
    height: 100vh;
    background: url(../../../assets/images/lock-page.jpg) no-repeat;
    background-size: 100% 100%;
    align-items: center;
    justify-content: flex-end;

    &__entry {
      position: relative;
      width: 400px;
vben authored
126
127
      // height: 260px;
      padding: 80px 50px 50px 50px;
陈文彬 authored
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
      margin-right: 50px;
      background: #fff;
      border-radius: 6px;
    }

    &__header {
      position: absolute;
      top: -35px;
      left: calc(50% - 45px);
      width: auto;
      text-align: center;

      &-img {
        width: 70px;
        border-radius: 50%;
      }

      &-name {
        margin-top: 5px;
      }
    }

    &__footer {
      text-align: center;
    }
  }
</style>