严智鑫
2024-04-16 e208aa1ef8e861dba168e8d83ab3066fc9f1e02d
UI-Project/src/layout/MainErpView.vue
@@ -1,66 +1,69 @@
<script setup>
import { RouterLink,useRouter} from 'vue-router'
import  useUserInfoStore from '@/stores/userInfo'
import {useRouter} from 'vue-router'
import useUserInfoStore from '@/stores/userInfo'
import userInfo from '@/stores/userInfo'
import request from "@/utils/request";
import {ElMessage} from "element-plus";
import {onMounted, reactive, ref, watch} from "vue"
import {ref, watch} from "vue"
import deepClone from "@/utils/deepClone"
import userInfo from '@/stores/userInfo'
import {Close, Grid, Histogram, MessageBox, SwitchButton} from "@element-plus/icons-vue";
const store=userInfo()
const store = userInfo()
const router = useRouter()
const userStore = useUserInfoStore()
const user = userStore.user.userName
// store.createWebSocket();
function quit(){
function quit() {
  userStore.$patch({
    user:null
    user: null
  })
  router.push("/login")
}
//提取模块列表
let menuList=$ref([])
request.get("/menu").then((res) => {
  if(res.code==200){
    menuList= deepClone(res.data)
  }else{
let menuList = $ref([])
request.get('/menu/sysMenu/list').then((res) => {
  if (res.code == 200) {
    menuList = deepClone(res.data)
  } else {
    ElMessage.warning(res.msg)
    router.push("/login")
    router.push('/login')
  }
})
//获取菜单列表
let menuItemList=$ref([])
request.get("/menuItem").then((res) => {
  if(res.code==200){
    menuItemList= deepClone(res.data)
  }else{
    ElMessage.warning(res.msg)
    router.push("/login")
  }
})
// let menuItemList = $ref([])
// request.get('/menuItem').then((res) => {
//   if (res.code == 200) {
//     menuItemList = deepClone(res.data)
//   } else {
//     ElMessage.warning(res.msg)
//     router.push('/login')
//   }
// })
const menu = ref(null)
let indexKey = ref(null)
function handleOpen(key) {
  indexKey.value=key
  indexKey.value = key
}
watch(indexKey,(newVal,oldVal) => {
  if(oldVal !== newVal && oldVal !== null){
    menu.value.close(oldVal)
  }
watch(indexKey, (newVal, oldVal) => {
      if (oldVal !== newVal && oldVal !== null) {
        menu.value.close(oldVal)
      }
},
    {deep:true}
)
router.beforeEach((to, from) => {
  //return false
})
let openFlag = $ref(null)
//原始菜单打开
const openMenu = (menuID) => {
@@ -70,10 +73,10 @@
      openFlag = menuID
    }
}
</script>
<template>
  <div id="all">
    <el-container>
@@ -81,53 +84,53 @@
        <div style="height: 100%;width: 100%;display: flex;background-color: #fff;">
          <img src="../assets/northGlass.ico" alt="" style="max-width: 100%;max-height: 100%">
          <h3 style="margin: 1rem  ;font-weight: bold;width: 20vw;"> 欢迎{{ user }}使用北玻MES系统!</h3>
          <span style="height: 70%;width: 78vw;margin-top: 1rem;" >
            <el-button  class="sys-quit" @click="quit" round>
              <el-icon size="large"><SwitchButton  size=""/></el-icon>
          <span style="height: 70%;width: 78vw;margin-top: 1rem;">
            <el-button class="sys-quit" @click="quit" round>
              <el-icon size="large"><SwitchButton size=""/></el-icon>
            </el-button>
          </span>
        </div>
      </el-header>
      <div id="line"></div>
      <el-container >
        <el-aside width="160px" style="height: 99%; background-color: #fff;" >
          <div class="menu"  >
             <div v-for="items in menuList">
                <div class='menu_title' @click="openMenu(items.id)"  >
              <!-- <span class='indicator' >⌵</span> -->
              <!-- <span class='indicator' >≡</span> -->
              <!-- <img src="../assets/9.png" alt="" style="max-width: 50%;max-height: 50%;"> -->
                  <span>☰</span>
              {{items.menuName}}
                </div>
                <ul class='enter-x-left' v-show="openFlag==items.id">
                  <li v-for="menuItem in menuItemList"
                      v-show="items.id==menuItem.menuID"
                      style="margin-bottom: 2px"
                  >
                    <router-link
                        :to="{path:menuItem.url}">
                      {{ menuItem.itemName}}
                    </router-link>
                  </li>
                </ul>
      <el-container>
        <el-aside width="160px"
                  style="height: 99%; background-color: #fff;">
          <div class="menu">
            <div v-for="items in menuList">
              <div class='menu_title'
                   @click="openMenu(items.id)">
                <!-- <span class='indicator' >⌵</span> -->
                <!-- <span class='indicator' >≡</span> -->
                <!-- <img src="../assets/9.png" alt="" style="max-width: 50%;max-height: 50%;"> -->
                <span>☰</span>
                {{ items.menuName }}
              </div>
              <ul class='enter-x-left'
                  v-show="openFlag==items.id">
                <li v-for="menuItem in items.children"
                    style="margin-bottom:2px">
                  <router-link :to="{path:menuItem.url}">
                    {{ menuItem.menuName }}
                  </router-link>
                </li>
              </ul>
            </div>
          </div>
        </el-aside>
        <el-main>
          <div id="main">
            <router-view></router-view>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<style scoped>
#all{
  background-color: #eee;
@@ -137,7 +140,7 @@
  height: 100vh;
  width: 99vw
}
*{
  padding: 0;
  margin: 0;
@@ -160,7 +163,7 @@
}
:deep(span){
  margin-right: 0;
}
.el-collapse{
  font-size: 16px;
@@ -173,9 +176,9 @@
  background-color: #fff;
}
/*------------*/
/* .menu div div{
  width: 138px;
  height: 35px;
  line-height: 35px;
@@ -197,29 +200,29 @@
  /* background-color:#5CADFE; */
  /* box-shadow: 0 8px 16px 0 rgba(0,0,0,0), 0 6px 5px 0 rgba(0,0,0,0.19); */
/* } */
.menu {
  width: 138px;
  height: 33px;
  line-height: 25px;
  color: #000000;
  font-size: 16px;
  padding-left: 15px;
  padding-right: 2px;
}
ul {
  height: auto;
  margin: 1px auto;
  text-align: center;
}
ul li {
  height: 28px;
  line-height: 30px;
  /* background: rgb(128, 128, 128); */
@@ -230,26 +233,26 @@
  text-align: left;
  /* border-radius:8px; */
  /*   outline: none; */
  /* background: #5CADFE; */
  /* box-shadow: 0 8px 16px 0 rgba(0,0,0,0), 0 6px 5px 0 rgba(0,0,0,0.19); */
}
ul li:hover {
  /* background:#5CADFE ; */
  color: #ffffff;
}
ul li a {
  text-decoration: none;
  color: #000000;
  font-size: 14px;
}
ul li a:hover {
  color: #1087ff;
}
.item_divider {
  width: 118px;
  height: 0px;
@@ -267,7 +270,7 @@
  font-size: 14px;
  text-decoration: none;
}
.menu_title {
  width: 140px;
  height: 45px;
@@ -281,14 +284,14 @@
  position: relative;
  font-weight: bold;
  overflow: hidden;
}
.menu_title:hover {
  /* background: #dedede; */
  color: #3b9af9;
}
.indicator {
  display: block;
  width: 40px;
@@ -300,9 +303,9 @@
  transition: all 0.3s ease;
  text-align: center;
}
/* 动画效果 */
.enter-x-left {
  z-index: 9;
@@ -330,6 +333,6 @@
    transform: translateX(0);
  }
}
</style>