完善版本

This commit is contained in:
葛林强 2024-08-30 08:13:40 +08:00
parent ba6af100be
commit f02524af06
2 changed files with 156 additions and 2 deletions

View File

@ -1,8 +1,9 @@
import { createRouter, createWebHashHistory } from 'vue-router'
const routes = [
{ path: '/', redirect: '/login' },
{ path: '/', redirect: '/jump' },
{ path: '/login', name: 'login', component: () => import('../view/page/LoginPage.vue') },
{ path: '/jump', name: 'jump', component: () => import('../view/page/JumpPage.vue') },
{
path: '/wcs',
name: 'wcs',
@ -57,7 +58,7 @@ const router = createRouter({
// 导航守卫
router.beforeEach((to, from, next) => {
// 登陆页和错误页允许访问
if(to.name === 'login' || to.name === 'limit') {
if(to.name === 'login' || to.name === 'limit' || to.name === 'jump') {
next()
return
}

153
src/view/page/JumpPage.vue Normal file
View File

@ -0,0 +1,153 @@
<!-- -->
<template>
<div>
</div><div class='formBorderMid'>
<div class='mainTitle'>WCS 设备控制系统</div>
<div>您的管理员已经禁止直接登陆请使用主程序跳转</div>
</div>
</template>
<script>
// import from ' ';
import {ElMessage, ElMessageBox} from "element-plus";
import userApi from "@/axios/user";
import router from "@/router";
export default {
// import 使
components: {},
props: [],
emits: [],
data() {
//
return {
loginUser: {
userId: '',
userPassword: ''
},
loading: false
}
},
// data
computed: {},
// data
watch: {},
//
methods: {
//
onSubmit(userName) {
this.loading = true
userApi.login(this.loginUser).then((response) => {
const data = response.data
if(data.code !== 0) {
//
ElMessageBox.alert(`登陆失败,信息:${data.msg}`, '登陆失败', {
confirmButtonText: '确定'
}).catch(()=>{ })
} else {
//
ElMessage({
message: '登陆成功',
type: 'success',
})
const returnData = data['returnData']
window.sessionStorage.setItem("userName", returnData.userName)
window.sessionStorage.setItem("token", returnData.token)
let userInfo = { userId: this.loginUser.userId, userName: userName}
this.$store.commit('setUserInfo', userInfo)
this.loadMenu(returnData.menu) //
router.push({name: 'wcs'})
}
this.loading = false
}).catch((err) => {
ElMessageBox.alert(`请求登陆失败,异常信息:${err}`, '登陆失败', {
type: 'warning',
confirmButtonText: '确定'
}).catch(()=>{ })
this.loading = false
})
},
//
loadMenu(menu) {
if(menu === undefined || menu.length < 1) {
return
}
this.$store.commit('setMenuData', menu)
let menuList = []
menu.forEach((menuItem, index) => {
const minor = menuItem.minor
if(minor === undefined || minor.length < 1) {
return
}
minor.forEach((minorItem, index) => {
menuList.push(minorItem)
})
})
this.$store.commit('setMenuList', menuList)
window.sessionStorage.setItem("menuList", JSON.stringify(menuList))
}
},
// API
setup() {
},
//
beforeCreate() {
},
// (访 this )
created() {
this.$store.commit('resetMenuData');
this.$store.commit('resetTabs');
// url
const url = window.location.href
if (url.includes("?")) {
const info = url.split("?")[1];
const userNameInfo = info.split("=");
if (userNameInfo.length < 1) {
return;
}
const userName = userNameInfo[1];
this.loginUser.userPassword = 'user';
this.loginUser.userId = 'user';
this.onSubmit(userName);
}
},
// -
beforeMount() {
},
// - 访 DOM
mounted() {
},
//
beforeUpdate() {
},
//
updated() {
},
//
beforeUnmount() {
},
//
unmounted() {
}
}
</script>
<style lang="scss" scoped>
.formBorderMid {
border: #6b778c50 1px solid;
border-radius: 15px;
margin: 250px auto auto auto;
padding: 30px;
width: 500px;
}
.mainTitle {
font-size: 25px;
margin: auto auto 45px auto;
text-align: center;
}
</style>