Login.vue
2.65 KB
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
<template>
<a-form :model="loginForm">
<a-form-item label="用户名">
<a-input v-model:value="loginForm.username"/>
</a-form-item>
<a-form-item label="密码">
<a-input v-model:value="loginForm.password"/>
</a-form-item>
<a-form-item>
<a-button type="primary" @click="onSubmit">登录</a-button>
</a-form-item>
</a-form>
</template>
<script>
import {defineComponent, reactive, toRaw} from 'vue'
import {getAccessedMenu, setAccessedMenu} from '@/PublicUtil/PublicUtil'
import loginApi from '@/views/Login/LoginApi'
import Cookies from "js-cookie"
import {useRouter} from 'vue-router'
import {getUrlByTitle} from '@/router'
import {ElMessage} from 'element-plus'
export default defineComponent({
setup() {
const router = useRouter()
const loginForm = reactive(
{
username: window.location.hostname === "localhost" ? 'vion' : '',
password: window.location.hostname === "localhost" ? 'VION20050620' : '',
}
)
const onSubmit = () => {
const data = {
username: loginForm.username,
password: loginForm.password
}
loginApi.login(data).then(
(r) => {
const message = r.msg
if (message === 'success')
{
const data = r.data
const token = data.tokenInfo.tokenValue
Cookies.set("token", token)
// store.commit("setAccessedRouteList", getAccessedRouteList(r.data.menu))
setAccessedMenu(data.menu)
localStorage.setItem('currentUserId', data.id)
localStorage.setItem('currentUserType', data.type)
localStorage.setItem('currentAccountId', data.accountId)
const accessedMenu = getAccessedMenu()
const firstTitle = accessedMenu[Object.keys(accessedMenu)[0]][0]
router.push(
getUrlByTitle(firstTitle)
)
}
else
{
ElMessage(
{
message: `${message}`,
type: 'error'
}
)
}
}
)
}
return {
loginForm,
onSubmit,
}
},
})
</script>
<style scoped>
</style>