LockPage.vue 6.6 KB
Newer Older
V
vben 已提交
1
<template>
V
vben 已提交
2 3 4 5 6 7 8 9 10 11
  <div
    :class="prefixCls"
    class="fixed inset-0 flex h-screen w-screen bg-black items-center justify-center"
  >
    <div
      :class="`${prefixCls}__unlock`"
      class="absolute top-0 left-1/2 flex pt-5 h-16 items-center justify-center sm:text-md xl:text-xl text-white flex-col cursor-pointer transform translate-x-1/2"
      @click="handleShowForm(false)"
      v-show="showDate"
    >
V
vben 已提交
12 13 14 15
      <LockOutlined />
      <span>{{ t('sys.lock.unlock') }}</span>
    </div>

V
vben 已提交
16 17 18 19 20 21
    <div class="flex w-screen h-screen justify-center items-center">
      <div :class="`${prefixCls}__hour`" class="relative mr-5 md:mr-20 w-2/5 h-2/5 md:h-4/5">
        <span>{{ hour }}</span>
        <span class="meridiem absolute left-5 top-5 text-md xl:text-xl" v-show="showDate">
          {{ meridiem }}
        </span>
V
vben 已提交
22
      </div>
V
vben 已提交
23 24
      <div :class="`${prefixCls}__minute w-2/5 h-2/5 md:h-4/5 `">
        <span> {{ minute }}</span>
V
vben 已提交
25
      </div>
V
vben 已提交
26 27 28 29
    </div>
    <transition name="fade-slide">
      <div :class="`${prefixCls}-entry`" v-show="!showDate">
        <div :class="`${prefixCls}-entry-content`">
V
vben 已提交
30
          <div :class="`${prefixCls}-entry__header enter-x`">
V
vben 已提交
31
            <img :src="headerImg" :class="`${prefixCls}-entry__header-img`" />
V
vben 已提交
32 33 34
            <p :class="`${prefixCls}-entry__header-name`">
              {{ realName }}
            </p>
V
vben 已提交
35
          </div>
V
vben 已提交
36 37 38 39 40
          <InputPassword
            :placeholder="t('sys.lock.placeholder')"
            class="enter-x"
            v-model:value="password"
          />
V
Vben 已提交
41
          <span :class="`${prefixCls}-entry__err-msg enter-x`" v-if="errMsg">
V
vben 已提交
42 43
            {{ t('sys.lock.alert') }}
          </span>
V
vben 已提交
44
          <div :class="`${prefixCls}-entry__footer enter-x`">
V
vben 已提交
45 46 47
            <a-button
              type="link"
              size="small"
V
vben 已提交
48
              class="mt-2 mr-2 enter-x"
V
Vben 已提交
49
              :disabled="loading"
V
vben 已提交
50 51
              @click="handleShowForm(true)"
            >
V
vben 已提交
52
              {{ t('common.back') }}
V
vben 已提交
53 54 55 56
            </a-button>
            <a-button
              type="link"
              size="small"
V
vben 已提交
57
              class="mt-2 mr-2 enter-x"
V
Vben 已提交
58
              :disabled="loading"
V
vben 已提交
59 60 61 62
              @click="goLogin"
            >
              {{ t('sys.lock.backToLogin') }}
            </a-button>
V
Vben 已提交
63
            <a-button class="mt-2" type="link" size="small" @click="unLock()" :loading="loading">
V
vben 已提交
64 65 66 67 68 69 70
              {{ t('sys.lock.entry') }}
            </a-button>
          </div>
        </div>
      </div>
    </transition>

V
vben 已提交
71 72 73
    <div class="absolute bottom-5 w-full text-gray-300 xl:text-xl 2xl:text-3xl text-center enter-y">
      <div class="text-5xl mb-4 enter-x" v-show="!showDate">
        {{ hour }}:{{ minute }} <span class="text-3xl">{{ meridiem }}</span>
V
vben 已提交
74
      </div>
V
vben 已提交
75
      <div class="text-2xl"> {{ year }}/{{ month }}/{{ day }} {{ week }} </div>
V
vben 已提交
76 77 78 79 80
    </div>
  </div>
</template>
<script lang="ts">
  import { defineComponent, ref, computed } from 'vue';
V
vben 已提交
81
  import { Input } from 'ant-design-vue';
V
vben 已提交
82

V
Vben 已提交
83 84
  import { useUserStore } from '/@/store/modules/user';
  import { useLockStore } from '/@/store/modules/lock';
V
vben 已提交
85 86 87 88 89 90
  import { useI18n } from '/@/hooks/web/useI18n';

  import { useNow } from './useNow';
  import { useDesign } from '/@/hooks/web/useDesign';

  import { LockOutlined } from '@ant-design/icons-vue';
V
vben 已提交
91
  import headerImg from '/@/assets/images/header.jpg';
V
vben 已提交
92 93 94

  export default defineComponent({
    name: 'LockPage',
V
vben 已提交
95
    components: { LockOutlined, InputPassword: Input.Password },
V
vben 已提交
96 97

    setup() {
V
Vben 已提交
98 99 100
      const password = ref('');
      const loading = ref(false);
      const errMsg = ref(false);
V
vben 已提交
101 102 103
      const showDate = ref(true);

      const { prefixCls } = useDesign('lock-page');
V
Vben 已提交
104 105
      const lockStore = useLockStore();
      const userStore = useUserStore();
V
vben 已提交
106

V
vben 已提交
107
      const { ...state } = useNow(true);
V
vben 已提交
108 109 110 111

      const { t } = useI18n();

      const realName = computed(() => {
V
Vben 已提交
112
        const { realName } = userStore.getUserInfo || {};
V
vben 已提交
113 114 115 116 117 118 119
        return realName;
      });

      /**
       * @description: unLock
       */
      async function unLock() {
V
Vben 已提交
120
        if (!password.value) {
V
vben 已提交
121 122
          return;
        }
V
Vben 已提交
123
        let pwd = password.value;
V
vben 已提交
124
        try {
V
Vben 已提交
125 126 127
          loading.value = true;
          const res = await lockStore.unLock(pwd);
          errMsg.value = !res;
V
vben 已提交
128
        } finally {
V
Vben 已提交
129
          loading.value = false;
V
vben 已提交
130 131 132 133
        }
      }

      function goLogin() {
134
        userStore.logout(true);
V
vben 已提交
135 136 137 138 139 140 141 142 143 144 145
        lockStore.resetLockInfo();
      }

      function handleShowForm(show = false) {
        showDate.value = show;
      }

      return {
        goLogin,
        realName,
        unLock,
V
Vben 已提交
146 147
        errMsg,
        loading,
V
vben 已提交
148 149 150
        t,
        prefixCls,
        showDate,
V
Vben 已提交
151
        password,
V
vben 已提交
152
        handleShowForm,
V
vben 已提交
153
        headerImg,
V
vben 已提交
154 155 156 157 158 159 160 161 162
        ...state,
      };
    },
  });
</script>
<style lang="less" scoped>
  @prefix-cls: ~'@{namespace}-lock-page';

  .@{prefix-cls} {
V
vben 已提交
163
    z-index: @lock-page-z-index;
V
vben 已提交
164 165 166 167 168 169 170 171 172 173

    &__unlock {
      transform: translate(-50%, 0);
    }

    &__hour,
    &__minute {
      display: flex;
      font-weight: 700;
      color: #bababa;
V
Vben 已提交
174
      background-color: #141313;
V
vben 已提交
175 176 177 178
      border-radius: 30px;
      justify-content: center;
      align-items: center;

V
vben 已提交
179 180 181 182
      @media screen and (max-width: @screen-md) {
        span:not(.meridiem) {
          font-size: 160px;
        }
V
vben 已提交
183
      }
V
vben 已提交
184

V
vben 已提交
185 186 187
      @media screen and (min-width: @screen-md) {
        span:not(.meridiem) {
          font-size: 160px;
V
vben 已提交
188
        }
V
vben 已提交
189
      }
V
vben 已提交
190

V
vben 已提交
191 192 193
      @media screen and (max-width: @screen-sm) {
        span:not(.meridiem) {
          font-size: 90px;
V
vben 已提交
194
        }
V
vben 已提交
195
      }
V
vben 已提交
196 197 198
      @media screen and (min-width: @screen-lg) {
        span:not(.meridiem) {
          font-size: 220px;
V
vben 已提交
199 200 201
        }
      }

V
vben 已提交
202 203 204 205 206 207 208 209 210
      @media screen and (min-width: @screen-xl) {
        span:not(.meridiem) {
          font-size: 260px;
        }
      }
      @media screen and (min-width: @screen-2xl) {
        span:not(.meridiem) {
          font-size: 320px;
        }
V
vben 已提交
211 212 213 214 215 216 217 218 219 220
      }
    }

    &-entry {
      position: absolute;
      top: 0;
      left: 0;
      display: flex;
      width: 100%;
      height: 100%;
V
Vben 已提交
221
      background-color: rgba(0, 0, 0, 0.5);
V
vben 已提交
222 223 224 225 226 227 228 229 230 231 232 233 234
      backdrop-filter: blur(8px);
      justify-content: center;
      align-items: center;

      &-content {
        width: 260px;
      }

      &__header {
        text-align: center;

        &-img {
          width: 70px;
235
          margin: 0 auto;
V
vben 已提交
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
          border-radius: 50%;
        }

        &-name {
          margin-top: 5px;
          font-weight: 500;
          color: #bababa;
        }
      }

      &__err-msg {
        display: inline-block;
        margin-top: 10px;
        color: @error-color;
      }

      &__footer {
        display: flex;
        justify-content: space-between;
      }
    }
  }
</style>