Login.vue 7.0 KB
Newer Older
陈文彬 已提交
1
<template>
N
nebv 已提交
2 3 4 5
  <div class="login">
    <div class="login-mask" />
    <div class="login-form-wrap">
      <div class="login-form mx-6">
V
vben 已提交
6
        <AppLocalePicker v-if="showLocale" class="login-form__locale" />
N
nebv 已提交
7 8
        <div class="login-form__content px-2 py-10">
          <header>
V
vben 已提交
9
            <img :src="logo" class="mr-4" />
N
nebv 已提交
10
            <h1>{{ title }}</h1>
陈文彬 已提交
11 12
          </header>

N
nebv 已提交
13
          <a-form class="mx-auto mt-10" :model="formData" :rules="formRules" ref="formRef">
陈文彬 已提交
14
            <a-form-item name="account">
V
vben 已提交
15
              <a-input size="large" v-model:value="formData.account" placeholder="username: vben" />
陈文彬 已提交
16 17 18 19 20 21
            </a-form-item>
            <a-form-item name="password">
              <a-input-password
                size="large"
                visibilityToggle
                v-model:value="formData.password"
V
vben 已提交
22
                placeholder="password: 123456"
陈文彬 已提交
23 24
              />
            </a-form-item>
25 26

            <!-- <a-form-item name="verify" v-if="openLoginVerify">
陈文彬 已提交
27
              <BasicDragVerify v-model:value="formData.verify" ref="verifyRef" />
28 29 30 31
            </a-form-item> -->
            <a-row>
              <a-col :span="12">
                <a-form-item>
V
vben 已提交
32
                  <!-- No logic, you need to deal with it yourself -->
V
vben 已提交
33 34 35
                  <a-checkbox v-model:checked="autoLogin" size="small">{{
                    t('sys.login.autoLogin')
                  }}</a-checkbox>
36 37 38 39
                </a-form-item>
              </a-col>
              <a-col :span="12">
                <a-form-item :style="{ 'text-align': 'right' }">
V
vben 已提交
40
                  <!-- No logic, you need to deal with it yourself -->
V
vben 已提交
41
                  <a-button type="link" size="small">{{ t('sys.login.forgetPassword') }}</a-button>
42 43 44
                </a-form-item>
              </a-col>
            </a-row>
陈文彬 已提交
45 46 47 48 49
            <a-form-item>
              <a-button
                type="primary"
                size="large"
                class="rounded-sm"
V
vben 已提交
50
                :block="true"
陈文彬 已提交
51 52
                @click="login"
                :loading="formState.loading"
V
vben 已提交
53
                >{{ t('sys.login.loginButton') }}</a-button
陈文彬 已提交
54 55 56 57 58 59 60 61 62
              >
            </a-form-item>
          </a-form>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
V
vben 已提交
63
  import { defineComponent, reactive, ref, unref, toRaw } from 'vue';
64 65
  import { Checkbox } from 'ant-design-vue';

V
vben 已提交
66
  import { Button } from '/@/components/Button';
V
vben 已提交
67
  import { AppLocalePicker } from '/@/components/Application';
68 69
  // import { BasicDragVerify, DragVerifyActionType } from '/@/components/Verify/index';

陈文彬 已提交
70
  import { userStore } from '/@/store/modules/user';
V
vben 已提交
71

72
  // import { appStore } from '/@/store/modules/app';
陈文彬 已提交
73
  import { useMessage } from '/@/hooks/web/useMessage';
V
vben 已提交
74
  import { useGlobSetting, useProjectSetting } from '/@/hooks/setting';
V
vben 已提交
75
  import logo from '/@/assets/images/logo.png';
V
vben 已提交
76
  import { useI18n } from '/@/hooks/web/useI18n';
V
vben 已提交
77

陈文彬 已提交
78
  export default defineComponent({
79 80 81 82
    components: {
      //  BasicDragVerify,
      AButton: Button,
      ACheckbox: Checkbox,
V
vben 已提交
83
      AppLocalePicker,
84
    },
陈文彬 已提交
85
    setup() {
86 87 88 89
      const formRef = ref<any>(null);
      const autoLoginRef = ref(false);
      // const verifyRef = ref<RefInstanceType<DragVerifyActionType>>(null);

V
vben 已提交
90
      const globSetting = useGlobSetting();
V
vben 已提交
91
      const { locale } = useProjectSetting();
陈文彬 已提交
92
      const { notification } = useMessage();
V
vben 已提交
93
      const { t } = useI18n('sys.login');
陈文彬 已提交
94

95
      // const openLoginVerifyRef = computed(() => appStore.getProjectConfig.openLoginVerify);
陈文彬 已提交
96 97

      const formData = reactive({
V
vben 已提交
98 99
        account: 'vben',
        password: '123456',
100
        // verify: undefined,
陈文彬 已提交
101 102 103 104 105 106
      });
      const formState = reactive({
        loading: false,
      });

      const formRules = reactive({
V
vben 已提交
107 108
        account: [{ required: true, message: t('accountPlaceholder'), trigger: 'blur' }],
        password: [{ required: true, message: t('passwordPlaceholder'), trigger: 'blur' }],
109
        // verify: unref(openLoginVerifyRef) ? [{ required: true, message: '请通过验证码校验' }] : [],
陈文彬 已提交
110 111
      });

112 113 114 115 116 117
      // function resetVerify() {
      //   const verify = unref(verifyRef);
      //   if (!verify) return;
      //   formData.verify && verify.$.resume();
      //   formData.verify = undefined;
      // }
陈文彬 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132

      async function handleLogin() {
        const form = unref(formRef);
        if (!form) return;
        formState.loading = true;
        try {
          const data = await form.validate();
          const userInfo = await userStore.login(
            toRaw({
              password: data.password,
              username: data.account,
            })
          );
          if (userInfo) {
            notification.success({
V
vben 已提交
133 134
              message: t('loginSuccessTitle'),
              description: `${t('loginSuccessDesc')}: ${userInfo.realName}`,
陈文彬 已提交
135 136 137 138 139
              duration: 3,
            });
          }
        } catch (error) {
        } finally {
140
          // resetVerify();
陈文彬 已提交
141 142 143 144 145
          formState.loading = false;
        }
      }
      return {
        formRef,
146
        // verifyRef,
陈文彬 已提交
147 148 149 150
        formData,
        formState,
        formRules,
        login: handleLogin,
151 152
        autoLogin: autoLoginRef,
        // openLoginVerify: openLoginVerifyRef,
N
nebv 已提交
153
        title: globSetting && globSetting.title,
V
vben 已提交
154
        logo,
V
vben 已提交
155
        t,
V
vben 已提交
156
        showLocale: locale.show,
陈文彬 已提交
157 158 159 160
      };
    },
  });
</script>
V
vben 已提交
161
<style lang="less">
N
nebv 已提交
162 163
  @import (reference) '../../../design/index.less';

V
vben 已提交
164 165 166 167 168 169 170
  .login-form__locale {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 1;
  }

陈文彬 已提交
171
  .login {
N
nebv 已提交
172 173
    position: relative;
    height: 100vh;
陈文彬 已提交
174 175 176 177
    background: url(../../../assets/images/login/login-bg.png) no-repeat;
    background-size: 100% 100%;

    &-mask {
N
nebv 已提交
178 179
      display: none;
      height: 100%;
陈文彬 已提交
180
      background: url(../../../assets/images/login/login-in.png) no-repeat;
V
vben 已提交
181
      background-position: 30% 30%;
182
      background-size: 80% 80%;
N
nebv 已提交
183

184
      .respond-to(xlarge, { display: block;});
陈文彬 已提交
185 186 187
    }

    &-form {
V
vben 已提交
188 189 190
      position: relative;
      bottom: 60px;
      width: 400px;
N
nebv 已提交
191 192
      background: @white;
      border: 10px solid rgba(255, 255, 255, 0.5);
193
      border-width: 8px;
N
nebv 已提交
194 195
      border-radius: 4px;
      background-clip: padding-box;
196
      .respond-to(xlarge, { margin: 0 120px 0 50px});
N
nebv 已提交
197 198 199 200 201 202 203

      &-wrap {
        position: absolute;
        top: 0;
        right: 0;
        display: flex;
        width: 100%;
V
vben 已提交
204 205
        height: 100%;
        // height: 90%;
N
nebv 已提交
206 207
        justify-content: center;
        align-items: center;
V
vben 已提交
208 209
        .respond-to(xlarge, {
        justify-content: flex-end;
210
          });
V
vben 已提交
211 212
      }

N
nebv 已提交
213
      &__content {
V
vben 已提交
214
        position: relative;
N
nebv 已提交
215 216
        width: 100%;
        height: 100%;
V
vben 已提交
217
        padding: 60px 0 40px 0;
N
nebv 已提交
218 219 220 221 222 223 224 225 226 227
        border: 1px solid #999;
        border-radius: 2px;

        header {
          display: flex;
          justify-content: center;
          align-items: center;

          img {
            display: inline-block;
228
            width: 48px;
N
nebv 已提交
229 230 231 232 233 234 235 236 237 238 239 240 241
          }

          h1 {
            margin-bottom: 0;
            font-size: 24px;
            text-align: center;
          }
        }

        form {
          width: 80%;
        }
      }
陈文彬 已提交
242 243 244
    }
  }
</style>