胡思旗
2023-08-29 b80ee8c883f279e843071e6b53ab9cddec3f88a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<template>
  <div
    class="login flex-column flex-justify-center flex-align-center m0 b0">
    <a-image
      style="width: 17vw; height: 10vw; margin-bottom: 50px"
      :src="djiLogo"
    />
    <p class="fz35 pb50" style="color: #2d8cf0">Cloud API Demo</p>
    <a-form
      layout="inline"
      :model="formState"
      class="flex-row flex-justify-center flex-align-center"
    >
      <a-form-item>
        <a-input v-model:value="formState.username" placeholder="Username">
          <template #prefix
            ><UserOutlined style="color: rgba(0, 0, 0, 0.25)"
          /></template>
        </a-input>
      </a-form-item>
      <a-form-item>
        <a-input
          v-model:value="formState.password"
          type="password"
          placeholder="Password"
        >
          <template #prefix
            ><LockOutlined style="color: rgba(0, 0, 0, 0.25)"
          /></template>
        </a-input>
      </a-form-item>
      <a-form-item>
        <a-button
          class="m0"
          type="primary"
          html-type="submit"
          :disabled="loginBtnDisabled"
          @click="onSubmit"
        >
          Login
        </a-button>
      </a-form-item>
    </a-form>
  </div>
 
</template>
 
<script lang="ts" setup>
import djiLogo from '/@/assets/icons/dji_logo.png'
import { LockOutlined, UserOutlined } from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
import { reactive, computed, UnwrapRef } from 'vue'
import { login, LoginBody } from '/@/api/manage'
import { getRoot } from '/@/root'
import { ELocalStorageKey, ERouterName, EUserType } from '/@/types'
import { encrypt, decrypt } from '/@/utils/crypto'
import router from '/@/router'
 
const root = getRoot()
 
const formState: UnwrapRef<LoginBody> = reactive({
  username: 'admin',
  password: 'Yes@!#$20230523',
  // flag: EUserType.Web,
})
 
const loginBtnDisabled = computed(() => {
  return !formState.username || !formState.password
})
 
const onSubmit = async (e: any) => {
  const password = encrypt(formState.password)
  const result = await login({ ...formState, password })
  if (result.success) {
    localStorage.setItem(ELocalStorageKey.Token, result.data.token)
    localStorage.setItem(ELocalStorageKey.Username, result.data.user.username)
    localStorage.setItem(ELocalStorageKey.UserInfo, result.data.user)
    console.log(root)
    root.$router.push(ERouterName.PROJECT_LIST)
  }
}
 
</script>
 
<style lang="scss" scoped>
@import '/@/styles/index.scss';
.login {
  background-color: $dark-highlight;
  height: 100vh;
}
</style>