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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<template>
  <el-container>
 
    <div style="width: 200px;background-color: #222f3e" :style="{width: isCollapse?'70px':'250px'}">
      <el-aside :width="isCollapse?'70px':'250px'">
        <el-col :gutter="20">
          <el-row :span="4">
            <div class="logo">
              <div class="sys-name" v-show="!isCollapse">{{ $t('northglassMESsystem') }}</div>
            </div>
          </el-row>
          <el-row :span="20">
            <el-menu :default-active="activePath" class="el-menu-vertical-demo"
                     background-color="#222f3e" text-color="#fff" active-text-color="#ffd04b"
                     :collapse="isCollapse" :unique-opened="true"
                     :collapse-transition="false" :router="true">
              <!--一级菜单-->
              <el-submenu :index="item.id.toString()" v-for="item in menuList" :key="item.id">
                <!--一级菜单模板区域-->
                <template slot="title">
                  <!--图标-->
                  <i :class="item.icon"></i>
                  <!--文本-->
                  <span>{{ item.name }}</span>
                </template>
                <!--二级菜单-->
                <el-menu-item :index="'/'+menu.router"
                              v-for="menu in item.menuLists" :key="menu.id"
                              @click="saveNavState('/'+menu.router)">
                  <template slot="title">
                    <!--图标-->
                    <i :class="menu.icon"></i>
                    <!--文本-->
                    <span>{{ menu.name }}</span>
                  </template>
                </el-menu-item>
              </el-submenu>
            </el-menu>
          </el-row>
        </el-col>
      </el-aside>
    </div>
    <el-container>
     
      <el-header class="header-container">
       
        <el-menu :default-active="activePath1" class="el-menu-demo" mode="horizontal"
                 background-color="#576574" text-color="#fff" active-text-color="#ffd04b">
                 <div class="header-left">
          <el-button :icon="isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'" @click="toggleCollapse"></el-button>
        </div>
          <el-submenu index="1" class="user-icon">
        
            <template slot="title">
              <el-avatar src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png">
              </el-avatar>
            </template>
            <el-menu-item index="1-1" @click="logout">{{ $t('exit') }}</el-menu-item>
          </el-submenu>
        
        </el-menu>
      </el-header>
      <el-main>
        <router-view/>
      </el-main>
    </el-container>
  </el-container>
</template>
 
<script>
import {selectList} from '../api/menuList'
import {removeToken} from "../utils/auth";
import LanguageMixin from '../lang/LanguageMixin'
 
export default {
  name: "Layout",
  mixins: [LanguageMixin],
  data() {
    return {
      
      menuList: [],
      isCollapse: false,
      activePath: '',
      activePath1: '',
      menuListForm: {
        pageSize: 1,
        pageNum: -1
      }
    }
  },
  created() {
    selectList(this.menuListForm).then(res => {
      this.menuList = res.data
     
      const language = this.$i18n.locale;
      if (language === 'en-US') {
        this.replaceChineseWithEnglish(this.menuList);
      }
      // 记录上一次激活的菜单
      this.activePath = window.sessionStorage.getItem('activePath')
    });
  },
  methods: {
    logout: function () {
      removeToken()
      this.$router.push('/login')
    },
    
    toggleCollapse: function () {
      this.isCollapse = !this.isCollapse;
    },
    saveNavState: function (activePath) {
      window.sessionStorage.setItem('activePath', activePath)
    },
    replaceChineseWithEnglish(menuData) {
      // 定义中英文对照关系对象
      const translation = {
        '用户管理': 'UserManagement',
        '用户列表': 'UserList',
        '设备管理': 'DeviceManagement',
        '报警信息': 'AlarmInformation',
        '下发参数': 'ParameterSetting',
        '开关控制': 'SwitchControl',
        'I/O状态': 'I/O Status',
        '权限管理': 'PermissionManagement',
        '权限列表': 'PermissionList',
        '角色管理': 'RoleManagement',
        '角色列表': 'RoleList'
        // 根据实际需求继续添加对照关系
      };
 
      menuData.forEach(menu => {
        menu.name = translation[menu.name] || menu.name;
        menu.menuLists && menu.menuLists.forEach(subMenu => {
          subMenu.name = translation[subMenu.name] || subMenu.name;
        });
      });
 
      
    }
    
  }
  
}
</script>
 
<style scoped lang="less">
.header-container {
  display: flex;
  justify-content: flex-start;
}
 
.header-left {
  margin-right: auto;
}
.el-aside {
  height: 100vh;
  background-color: #222f3e;
  line-height: 200px;
}
 
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
 
.el-menu-demo {
  display: flex;
  width: 100%;
  height: 100%;
  justify-content: flex-end;
  align-items: center;
 
}
 
.el-menu-vertical-demo {
  border: 0;
}
 
.logo {
  background-color: #222f3e;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 60px;
 
  .sys-name {
    font-size: 20px;
    color: #ffffff;
    margin-left: 10px;
  }
}
 
.el-header {
  padding: 0;
  background-color: #576574;
}
</style>