mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-manage.git
synced 2025-12-13 04:46:46 +08:00
--添加登录页面
This commit is contained in:
13
src/App.vue
13
src/App.vue
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div id="container">
|
<div id="container" v-if="!isLogin">
|
||||||
<nav-top />
|
<nav-top />
|
||||||
<div style="display: flex">
|
<div style="display: flex">
|
||||||
<nav-left />
|
<nav-left />
|
||||||
@@ -14,9 +14,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="container" v-if="isLogin">
|
||||||
|
<router-view/>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { computed, defineComponent } from "vue";
|
import {computed, defineComponent, ref, watch} from "vue";
|
||||||
import { useRouter, useRoute } from "vue-router";
|
import { useRouter, useRoute } from "vue-router";
|
||||||
import { useStore } from "vuex";
|
import { useStore } from "vuex";
|
||||||
import NavLeft from "@/components/NavLeft";
|
import NavLeft from "@/components/NavLeft";
|
||||||
@@ -36,11 +39,16 @@ export default defineComponent({
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
|
const isLogin = ref(false)
|
||||||
// console.log("router", router.getRoutes(), route);
|
// console.log("router", router.getRoutes(), route);
|
||||||
const routes = computed(() => {
|
const routes = computed(() => {
|
||||||
return router.getRoutes().filter((e) => e.meta?.isLink);
|
return router.getRoutes().filter((e) => e.meta?.isLink);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch(() => route.path, () => {
|
||||||
|
route.path === '/login' && (isLogin.value = true)
|
||||||
|
})
|
||||||
|
|
||||||
const currentRouteName = computed(() => route.name);
|
const currentRouteName = computed(() => route.name);
|
||||||
|
|
||||||
//获取组织树
|
//获取组织树
|
||||||
@@ -68,6 +76,7 @@ export default defineComponent({
|
|||||||
getOrgTree();
|
getOrgTree();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
isLogin,
|
||||||
routes,
|
routes,
|
||||||
name: currentRouteName,
|
name: currentRouteName,
|
||||||
zhCN,
|
zhCN,
|
||||||
|
|||||||
@@ -75,3 +75,5 @@ export const getTemplateDetail = (obj) => http.get('/admin/project/template/deta
|
|||||||
//获取项目统计
|
//获取项目统计
|
||||||
export const getProjectCount = (projectId) => http.get('/admin/project/projectCount', { params: { projectId: projectId } })
|
export const getProjectCount = (projectId) => http.get('/admin/project/projectCount', { params: { projectId: projectId } })
|
||||||
|
|
||||||
|
export const login = (obj) => http.post('/admin/CheckUser/userLogin', obj)
|
||||||
|
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ const setCookie = (name, value, perpetual) => {
|
|||||||
console.log('存储token到cookie')
|
console.log('存储token到cookie')
|
||||||
let exdate = new Date()
|
let exdate = new Date()
|
||||||
exdate.setDate(perpetual * 24 * 60 * 60 * 1000) //exdate.setDate(exdate.getDate() + 365)
|
exdate.setDate(perpetual * 24 * 60 * 60 * 1000) //exdate.setDate(exdate.getDate() + 365)
|
||||||
document.cookie = name + '=' + value + ';expires=' + exdate.toGMTString()
|
document.cookie = `${name}=${value};expires=${exdate.toGMTString()};path=/`
|
||||||
//永久有效
|
//永久有效
|
||||||
//document.cookie = name + '=' + value + ';expires=' + 'Fri, 31 Dec 9999 23:59:59 GMT'
|
//document.cookie = name + '=' + value + ';expires=' + 'Fri, 31 Dec 9999 23:59:59 GMT'
|
||||||
}
|
}
|
||||||
|
|||||||
51
src/views/login.vue
Normal file
51
src/views/login.vue
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<template>
|
||||||
|
<div :style="{
|
||||||
|
margin: 'auto',
|
||||||
|
background: 'url(http://img.gz2c.com/FoTcLY8ww-ISCFlwyCoYuLim1BMt) no-repeat',
|
||||||
|
backgroundSize: '100% 100%',
|
||||||
|
width: '100%',
|
||||||
|
height: '100vh',
|
||||||
|
display:'flex'
|
||||||
|
}">
|
||||||
|
<div
|
||||||
|
:style="{width:'300px', height: '300px', margin:'10% auto',padding:'20px 30px',textAlign:'center', borderRadius:'10px', background:'#e0e0e0',boxShadow:'20px 20px 60px #bebebe,-20px -20px 60px #ffffff'}">
|
||||||
|
<div :style="{fontSize:'24px',paddingBottom:'30px'}">用户登录</div>
|
||||||
|
<div>
|
||||||
|
<a-input placeholder='用户名' v-model:value="form.account"/>
|
||||||
|
<a-input placeholder='密码' v-model:value="form.password" :style="{marginTop: '30px'}" type='password'/>
|
||||||
|
<a-button :style="{marginTop:'30px'}" @click="loginUser">登录</a-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
import {reactive, toRefs} from "vue";
|
||||||
|
import * as api from "@/api";
|
||||||
|
import {setCookie} from "@/api/method";
|
||||||
|
import {useRouter} from "vue-router";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "loginPage",
|
||||||
|
setup() {
|
||||||
|
const router = useRouter()
|
||||||
|
const state = reactive({
|
||||||
|
form: {
|
||||||
|
account: '10181461',
|
||||||
|
password: '1234567890Aa'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
async function loginUser() {
|
||||||
|
const {data: {data: token}} = await api.login(state.form)
|
||||||
|
setCookie("token", token, 10)
|
||||||
|
await router.push({path: '/learningpath'})
|
||||||
|
location.reload()
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...toRefs(state),
|
||||||
|
loginUser
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user