hejianhao
2025-03-31 8790f99a94733c7c3836706c75a77f9bbb15c2ca
layout布局修改,标签卡,列表组件封装
8个文件已修改
7个文件已添加
645 ■■■■ 已修改文件
src/App.vue 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/assets/public/close-l@2x.png 补丁 | 查看 | 原始文档 | blame | 历史
src/assets/public/layoutsBG.png 补丁 | 查看 | 原始文档 | blame | 历史
src/assets/public/logOut.png 补丁 | 查看 | 原始文档 | blame | 历史
src/assets/public/photo.png 补丁 | 查看 | 原始文档 | blame | 历史
src/components/Table/index.vue 116 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/TableSlot/index.vue 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/layouts/components/AppContent.vue 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/layouts/components/ElMenu/MenuItem.vue 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/layouts/components/HeaderNav.vue 189 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/layouts/index.vue 81 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main.js 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/router/index.js 82 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/store/index.js 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/projectList/index.vue 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/App.vue
@@ -13,10 +13,11 @@
}
</script>
<style>
<style lang="less">
::-webkit-scrollbar {
  display: none;
}
html,
body,
#app {
@@ -25,4 +26,8 @@
  padding: 0;
  background-color: rgb(245, 245, 245);
}
.selected {
  color: #049C9A !important;
}
</style>
src/assets/public/close-l@2x.png
src/assets/public/layoutsBG.png
src/assets/public/logOut.png
src/assets/public/photo.png
src/components/Table/index.vue
New file
@@ -0,0 +1,116 @@
<template>
    <div class="table-container">
        <el-table border :data="tableData" :height="height">
            <slot></slot>
        </el-table>
        <div>
            <el-pagination layout="slot,  prev, pager, next, sizes, jumper" :page-size="queryForm.pageSize"
                :current-page="queryForm.pageNum" :total="total" class="pagination">
                <div class="pagination-info">第 {{ (queryForm.pageNum == 1) ? 1 : (queryForm.pageNum - 1) *
                    queryForm.pageSize + 1 }}-{{
                        queryForm.pageNum * queryForm.pageSize }} 条/总共 {{ total }} 条</div>
            </el-pagination>
        </div>
    </div>
</template>
<script>
export default {
    props: {
        tableData: {
            type: Array,
            default: () => []
        },
        total: {
            type: Number,
            default: 20
        },
        queryForm: {
            type: Object,
            default: () => {
                return {
                    pageSize: 10,
                    pageNum: 1
                }
            }
        }
    },
    computed: {
        height() {
            return this.$baseTableHeight()
        },
    },
}
</script>
<style scoped lang="less">
.el-table--border,
.el-table--group {
    border-radius: 8px 8px 0px 0px;
    ::v-deep thead {
        tr {
            th {
                background: #FAFAFA !important;
            }
        }
    }
}
.pagination {
    display: flex;
    justify-content: flex-end;
    margin-top: 16px;
    .pagination-info {
        font-weight: 400;
        font-size: 14px;
        color: rgba(0, 0, 0, 0.88);
        line-height: 24px;
    }
    ::v-deep .el-pager li {
        padding: 0 !important;
        min-width: 24px !important;
        height: 24px !important;
        line-height: 24px !important;
        &:hover {
            color: #049C9A !important;
        }
    }
    ::v-deep .el-pager .active {
        color: #049C9A !important;
        border-radius: 6px !important;
        border: 1px solid #049C9A !important;
    }
    ::v-deep .el-pagination__jump {
        margin-left: 0 !important;
        .el-input__inner:focus {
            border: 1px solid #049C9A !important;
        }
    }
    ::v-deep .el-pagination__sizes .el-input .el-input__inner {
        color: #049C9A !important;
        border-color: #049C9A !important;
        &:hover {
            color: #049C9A !important;
            border-color: #049C9A !important;
        }
        &:focus {
            color: #049C9A !important;
            border-color: #049C9A !important;
        }
    }
    ::v-deep button:hover {
        color: #049C9A !important;
    }
}
</style>
src/components/TableSlot/index.vue
New file
@@ -0,0 +1,52 @@
<template>
    <div class="table-slot">
        <div class="search">
            <slot name="search"></slot>
        </div>
        <div class="table">
            <Table :tableData="tableData">
                <slot name="table"></slot>
            </Table>
        </div>
    </div>
</template>
<script>
import Table from '../Table/index.vue'
export default {
    components: {
        Table,
    },
    props: {
        tableData: {
            type: Array,
            default: () => []
        }
    }
}
</script>
<style scoped lang="less">
.table-slot {
    height: 100%;
    display: flex;
    flex-direction: column;
}
.search {
    padding: 34px 30px 15px 30px;
    box-shadow: 0px 10px 19px 0px rgba(0, 0, 0, 0.06);
    border-radius: 16px;
    border: 4px solid #FFFFFF;
    background: rgba(255, 255, 255, 0.8);
    margin-bottom: 30px;
}
.table {
    flex: 1;
    padding: 20px;
    background: rgba(255, 255, 255, 0.8);
    box-shadow: 0px 10px 19px 0px rgba(0, 0, 0, 0.06);
    border-radius: 16px;
    border: 4px solid #FFFFFF;
}
</style>
src/layouts/components/AppContent.vue
@@ -1,5 +1,21 @@
<template>
  <div>
    <router-view />
  <div style="height: 100%;">
    <keep-alive :include="keepAliveList">
      <router-view />
    </keep-alive>
  </div>
</template>
<script>
import { mapState } from 'vuex'
export default {
  name: 'AppContent',
  data() {
    return {
    }
  },
  computed: {
    ...mapState(['keepAliveList'])
  }
}
</script>
src/layouts/components/ElMenu/MenuItem.vue
@@ -1,7 +1,7 @@
<template>
  <!-- 判断当前页面是否显示,如果hide为true,则不渲染该菜单 -->
  <div v-if="!item.meta.hide && menus.includes(item.meta.privilege)">
  <!-- <div v-if="!item.meta.hide"> -->
  <!-- <div v-if="!item.meta.hide && menus.includes(item.meta.privilege)"> -->
  <div v-if="!item.meta.hide">
    <!-- 根菜单 -->
    <MenuLink :to="resolvePath()" v-if="!item.children">
      <el-menu-item :index="resolvePath()">
@@ -77,13 +77,22 @@
};
</script>
<style lang="less" scoped>
.is-active {
  background-color: rgb(245, 245, 245);
::v-deep .router-link-exact-active .is-active {
  background: #EFF8FA;
  border-radius: 8px;
  font-weight: bold;
  color: #000;
  color: #05908E;
}
.el-menu {
  border-right: unset !important;
::v-deep .el-menu-item,
::v-deep .el-submenu__title {
  border-radius: 8px;
  height: 40px;
  line-height: 40px;
}
::v-deep .el-menu-item:hover,
::v-deep .el-submenu__title:hover {
  background: #EFF8FA;
}
</style>
src/layouts/components/HeaderNav.vue
@@ -2,45 +2,77 @@
  <div>
    <!-- 右侧用户登录图标 -->
    <div class="user-logininfo">
      <el-dropdown @command="clickmenu">
        <span class="el-dropdown-link right-userName">
          <div style="margin-left: 10px;">{{ userInfo.nickName }}</div>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="outlogin">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <div class="user-logininfo-icon">
        <!-- 折叠 -->
        <!-- <i @click="clickFold" class="el-icon-s-fold"></i> -->
        <!-- 标签列表 -->
        <div class="tag-list-container">
          <div class="tag-list" v-for="tag in tagList" :key="tag.name">
            <div @click="goTag(tag)" :class="{ 'activeTag': tag.path === $route.path }">
              {{ tag.meta.title }}
            </div>
            <i @click="closeTag(tag)" v-if="tagList.length > 1" class="el-icon-close"></i>
          </div>
        </div>
      </div>
      <div class="user-info">
        <img src="@/assets/public/photo.png" />
        <div class="user-info-text">欢迎您,admin</div>
        <div class="user-info-line"></div>
        <div @click="outLogin" class="user-info-out">
          <img src="@/assets/public/logOut.png" />
          <div class="user-info-out-text">退出登录</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { mapState } from 'vuex'
export default {
  data() {
    return {
      userInfo: '',
    }
  },
  computed: {
    ...mapState(['tagList', 'isFold'])
  },
  mounted() {
    // 获取用户信息
    this.getUserInfo()
  },
  methods: {
    // 点击折叠按钮
    clickFold() {
      this.$store.commit('SET_ISFOLD', !this.isFold)
    },
    // 获取用户信息
    getUserInfo() {
      this.userInfo = JSON.parse(localStorage.getItem('userInfo'))
    },
    // 点击下拉菜单回调
    clickmenu(e) {
      if (e === 'outlogin') {
        this.outLogin()
      }
    },
    // 退出登录
    outLogin() {
      localStorage.clear()
      this.$router.replace({ path: "/" });
    },
    // 关闭标签
    closeTag(tag) {
      this.$store.commit('SET_TAGLIST', this.tagList.filter(item => item.path !== tag.path))
      // 判断是否是当前标签
      if (tag.path === this.$route.path) {
        // if (this.tagList.length > 1) {
        this.$router.push(this.tagList[this.tagList.length - 1].path)
        // } else {
        //   // this.$router.push('/welcome')
        // }
      }
    },
    // 跳转标签
    goTag(tag) {
      this.$router.push(tag.path)
    }
  },
}
</script>
@@ -49,16 +81,131 @@
// 右侧用户头像
.user-logininfo {
  height: 100%;
  padding-right: 40px;
  cursor: pointer;
  padding-left: 32px;
  padding-right: 20px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  justify-content: space-between;
}
  .user-logininfo-icon {
    flex: 1;
    flex-shrink: 0;
    display: flex;
    align-items: center;
.right-userName {
  display: flex;
  align-items: center;
    i:first-child {
      margin-right: 21px;
    }
    i {
      cursor: pointer;
    }
    .tag-list-container {
      display: flex;
      align-items: center;
      overflow-x: auto;
      .tag-list {
        flex-shrink: 0;
        display: flex;
        align-items: center;
        cursor: pointer;
        font-weight: 400;
        font-size: 18px;
        color: rgba(0, 0, 0, .6);
        margin-right: 40px;
        div:hover {
          font-weight: bold;
          color: #049C9A;
        }
        i {
          margin-left: 10px;
          &:hover {
            color: #049C9A;
          }
        }
      }
      .activeTag {
        font-weight: bold;
        color: #049C9A;
      }
    }
  }
  .user-info {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    img {
      width: 26px;
      height: 26px;
      border-radius: 50%;
    }
    .user-info-text {
      margin-left: 16px;
      font-size: 14px;
      color: #303133;
      font-weight: 400;
    }
    .user-info-line {
      width: 1px;
      height: 12px;
      background-color: #979797;
      margin: 0 20px;
    }
    .user-info-out {
      display: flex;
      align-items: center;
      padding: 0 11px;
      border-radius: 12px;
      position: relative;
      background: transparent;
      cursor: pointer;
      &::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 12px;
        padding: 1px;
        background: linear-gradient(180deg, rgba(10, 203, 202, 1), rgba(4, 156, 154, 1));
        -webkit-mask:
          linear-gradient(#fff 0 0) content-box,
          linear-gradient(#fff 0 0);
        -webkit-mask-composite: xor;
        mask-composite: exclude;
      }
      .user-info-out-text {
        font-weight: 400;
        font-size: 14px;
        color: #049C9A;
        line-height: 21px;
        position: relative;
        z-index: 1;
      }
      img {
        width: 14px;
        height: 14px;
        margin-right: 7px;
        position: relative;
        z-index: 1;
      }
    }
  }
}
</style>
src/layouts/index.vue
@@ -3,23 +3,24 @@
    <!-- 判断是否在空白页打开 -->
    <template v-if="!isOneself">
      <div class="app-wrapper">
        <div class="left">
        <div class="left" :style="{ width: isFold ? '100px' : '258px' }">
          <!-- 系统标题 -->
          <div class="system-title">
            <div class="image">
              <img src="../assets/logo.jpg" alt="" srcset="" />
            </div>
            <div class="title">职评网管理系统</div>
            <div v-if="!isFold" class="title">实验室流程</div>
          </div>
          <!-- 左侧菜单 -->
          <div class="sidebar-container">
            <ElMenu />
          </div>
          <div v-if="!isFold" class="sidebar-left-bg"></div>
          <div v-if="!isFold" class="sidebar-bottom-bg"></div>
        </div>
        <!-- 右侧展示内容 -->
        <div class="main-container">
          <HeaderNav class="header-main" />
          <div v-if="nowRouteName" class="router_name">{{ nowRouteName }}</div>
          <AppContent class="app-main" />
        </div>
      </div>
@@ -35,6 +36,7 @@
import ElMenu from './components/ElMenu/index.vue'
import HeaderNav from './components/HeaderNav.vue'
import AppContent from './components/AppContent.vue'
import { mapState } from 'vuex'
export default {
  data() {
    return {
@@ -43,6 +45,9 @@
      // 获取当前页面名称
      nowRouteName: '',
    }
  },
  computed: {
    ...mapState(['isFold'])
  },
  components: {
    ElMenu,
@@ -77,66 +82,98 @@
  height: 100%;
  width: 100%;
  display: flex;
  background-image: url('../assets/public/layoutsBG.png');
  background-size: cover;
  background-position: center;
  .left {
    width: 200px;
    display: flex;
    flex-direction: column;
    position: relative;
    background-color: white;
    transition: width 0.3s ease-in-out;
    // 系统标题
    .system-title {
      display: flex;
      justify-content: space-around;
      flex-direction: column;
      align-items: center;
      background-color: white;
      height: 50px;
      padding: 0px 10px;
      height: 240px;
      box-sizing: border-box;
      .image {
        width: 40px;
        height: 40px;
        margin-top: 40px;
        width: 100px;
        height: 100px;
        img {
          width: 100%;
          height: 100%;
          border-radius: 50%;
        }
      }
      .title {
        font-weight: 700;
        margin-top: 7px;
        font-weight: bold;
        line-height: 43px;
        font-size: 25px;
      }
    }
    // 左侧菜单
    .sidebar-container {
      z-index: 2;
      padding: 0 19px;
      overflow-y: auto;
      flex: 1;
      background-color: white;
      box-shadow: 0px 3px 13px 0px rgba(94, 131, 245, 0.1);
      ::v-deep .el-menu {
        border-right: unset !important;
      }
    }
    .sidebar-left-bg {
      z-index: 1;
      position: absolute;
      top: 338px;
      left: 0;
      width: 183px;
      height: 316px;
      background: #FFFCE5;
      opacity: 0.56;
      filter: blur(76.141290103688px);
    }
    .sidebar-bottom-bg {
      z-index: 1;
      position: absolute;
      bottom: 0;
      left: 0;
      width: 129px;
      height: 289px;
      background: #66FFFF;
      opacity: 0.4;
      filter: blur(76.141290103688px);
    }
  }
  .main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    .header-main {
      background-color: white;
      height: 50px;
    }
    .router_name {
      padding-top: 8px;
      padding-left: 23px;
      font-size: 24px;
      font-weight: bold;
      height: 70px;
    }
    .app-main {
      height: calc(100% - 120px);
      flex: 1;
      overflow: auto;
      border-radius: 10px;
      margin: 16px 23px;
      padding: 10px 21px 0 21px;
    }
  }
src/main.js
@@ -4,9 +4,11 @@
import App from "./App.vue";
import router from "./router";
import store from './store'
import TableCustom from '@/components/TableSlot/index.vue'
Vue.config.productionTip = false;
Vue.use(ElementUI, { size: 'small' })
Vue.component('TableCustom', TableCustom)
Vue.prototype.msgsuccess = function (msg) {
  this.$message({
@@ -33,6 +35,19 @@
  this.$message.info(msg);
}
Vue.prototype.$baseTableHeight = (formType) => {
  let height = window.innerHeight
  let paddingHeight = 400
  const formHeight = 50
  if ('number' == typeof formType) {
    height = height - paddingHeight - formHeight * formType
  } else {
    height = height - paddingHeight
  }
  return height
}
new Vue({
  router,
  store,
src/router/index.js
@@ -13,17 +13,19 @@
/**
 *  path: "/login",   ------页面地址
    component: () => import("../views/login"),  ------组件地址
    name: "Login",  ------组件名称 缓存时需要 唯一性
    meta: {
      title: "登录",    ------页面标题
      icon: "el-icon-user-solid",  ------菜单图标
      oneself: true,  ------是否在单独页面打开
      hide: true,  ------是否隐藏改菜单
      keepAlive: true,  ------是否缓存
    }
 */
const routes = [
    {
        path: "",
        path: "/",
        redirect: "login",
        component: Layouts,
        children: [
@@ -33,9 +35,26 @@
                    title: "登录",
                    oneself: true,
                    hide: true,
                    privilege: 'login'
                },
                component: () => import("../views/login"),
            },
            {
                path: "/projectList",
                meta: {
                    title: "项目组管理",
                },
                component: Parent,
                children: [
                    {
                        path: "list",
                        name: "ProjectList",
                        meta: {
                            title: "项目组管理",
                            keepAlive: true,
                        },
                        component: () => import("../views/projectList"),
                    }
                ]
            },
        ],
    },
@@ -50,27 +69,48 @@
// 前置路由拦截器
router.beforeEach((to, from, next) => {
    // 设置当前页签名称
    document.title = to.meta.title || '职评网管理系统';
    // 没有登录并且要去的页面不是登录页面,在强制跳转到登录
    if (to.path === "/login") {
        localStorage.removeItem('userInfo')
        next()
    } else if (!localStorage.getItem('userInfo')) {
        next('/login')
    } else {
        // 判断是否拥有要跳转菜单权限
        let menus = store.state.menus
    document.title = to.meta.title || '实验室流程';
        // console.log(store.state.menus);
        // console.log(to.meta);
        // console.log(to.meta.hasOwnProperty('privilege'));
        // console.log(!menus.includes(to.meta.privilege));
        if (to.meta.hasOwnProperty('privilege') && !menus.includes(to.meta.privilege)) {
            return
        }
        next()
    // 判断是否需要缓存
    if (to.meta.keepAlive) {
        store.commit('SET_KEEPALIVELIST', [...store.state.keepAliveList, to.name])
    }
    // 设置标签列表
    if (!to.meta.hide || !to.meta.oneself) {
        // 判断是否存在
        let isExist = store.state.tagList.some(item => item.path === to.path)
        if (!isExist) {
            store.commit('SET_TAGLIST', [...store.state.tagList, to])
        }
    }
    next()
    // 没有登录并且要去的页面不是登录页面,在强制跳转到登录
    // if (to.path === "/login") {
    //     localStorage.removeItem('userInfo')
    //     next()
    // } else if (!localStorage.getItem('userInfo')) {
    //     next('/login')
    // } else {
    //     // 判断是否拥有要跳转菜单权限
    //     let menus = store.state.menus
    //     if (to.meta.hasOwnProperty('privilege') && !menus.includes(to.meta.privilege)) {
    //         return
    //     }
    // 设置标签列表
    // if (!to.meta.hide || !to.meta.oneself) {
    //     // 判断是否存在
    //     let isExist = store.state.tagList.some(item => item.path === to.path)
    //     if (!isExist) {
    //         store.commit('SET_TAGLIST', [...store.state.tagList, to])
    //     }
    // }
    //     // 判断是否需要缓存
    //     if (to.meta.keepAlive) {
    //         store.commit('SET_KEEPALIVELIST', [...store.state.keepAliveList, to.name])
    //     }
    //     next()
    // }
});
export default router;
src/store/index.js
@@ -5,15 +5,36 @@
const store = new Vuex.Store({
  state: {
    menus: localStorage.getItem('menuList') ? JSON.parse(localStorage.getItem('menuList')) : [],
    keepAliveList: [],//缓存页面
    tagList: [],//标签列表
    isFold: false,//是否折叠
  },
  mutations: {
    SET_MENUS(state, data) {
      state.menus = data;
    },
    SET_KEEPALIVELIST(state, data) {
      state.keepAliveList = data;
    },
    SET_TAGLIST(state, data) {
      state.tagList = data;
    },
    SET_ISFOLD(state, data) {
      state.isFold = data;
    },
  },
  actions: {
    setMenus({ commit }, data) {
      commit('SET_MENUS', data);
    },
    setKeepAliveList({ commit }, data) {
      commit('SET_KEEPALIVELIST', data);
    },
    setTagList({ commit }, data) {
      commit('SET_TAGLIST', data);
    },
    setIsFold({ commit }, data) {
      commit('SET_ISFOLD', data);
    }
  }
})
src/views/projectList/index.vue
New file
@@ -0,0 +1,39 @@
<template>
    <div class="list">
        <TableCustom>
            <template #search>
                <el-form :model="form" label-width="100px" inline>
                    <el-form-item label="姓名">
                        <el-input v-model="form.name"></el-input>
                    </el-form-item>
                    <el-form-item label="姓名">
                        <el-input v-model="form.name"></el-input>
                    </el-form-item>
                </el-form>
            </template>
            <template #table>
                <el-table-column prop="name" label="姓名"></el-table-column>
                <el-table-column prop="age" label="年龄"></el-table-column>
            </template>
        </TableCustom>
    </div>
</template>
<script>
export default {
    name: 'ProjectList',
    data() {
        return {
            form: {
                name: ''
            }
        }
    },
}
</script>
<style scoped lang="less">
.list {
    height: 100%;
}
</style>