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();
陈文彬 已提交
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 107
      const formState = reactive({
        loading: false,
      });

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

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

      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 已提交
136 137
              message: t('sys.login.loginSuccessTitle'),
              description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.realName}`,
陈文彬 已提交
138 139 140 141 142
              duration: 3,
            });
          }
        } catch (error) {
        } finally {
143
          // resetVerify();
陈文彬 已提交
144 145 146 147 148
          formState.loading = false;
        }
      }
      return {
        formRef,
149
        // verifyRef,
陈文彬 已提交
150 151 152 153
        formData,
        formState,
        formRules,
        login: handleLogin,
154 155
        autoLogin: autoLoginRef,
        // openLoginVerify: openLoginVerifyRef,
N
nebv 已提交
156
        title: globSetting && globSetting.title,
V
vben 已提交
157
        logo,
V
vben 已提交
158
        t,
V
vben 已提交
159
        showLocale: locale.show,
陈文彬 已提交
160 161 162 163
      };
    },
  });
</script>
V
vben 已提交
164 165 166 167 168 169 170 171
<style lang="less">
  .login-form__locale {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 1;
  }

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

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

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

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

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

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

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

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

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

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