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
<template>
    <el-menu
        class="common-side-bar"
        :default-active="$store.state.routerName"
        background-color="#F5F5F5"
        text-color="#262626"
        active-text-color="#318DF1"
        @select="select"
    >
        <el-menu-item index="ProjectList">
            <i class="iconfont">&#xe631;</i>&nbsp;&nbsp;首 页
        </el-menu-item>
 
        <template v-for="item of side_menu">
            <el-menu-item
                v-if="!item.children"
                :key="item.url"
                :index="item.url"
                :disabled="$store.state.routerName === 'ProjectList'"
            >
                <span class="iconfont" v-html="item.code"></span>&nbsp;&nbsp;{{
                    item.name
                }}
            </el-menu-item>
 
            <el-submenu
                v-if="item.children"
                :key="item.url"
                :index="item.url"
                :disabled="$store.state.routerName === 'ProjectList'"
            >
                <template slot="title">
                    <span class="iconfont" v-html="item.code"></span
                    >&nbsp;&nbsp;{{ item.name }}
                </template>
                <el-menu-item
                    v-for="subItem in item.children"
                    :key="subItem.url"
                    :index="subItem.url"
                >
                    {{ subItem.name }}
                </el-menu-item>
            </el-submenu>
        </template>
    </el-menu>
</template>
 
<script>
export default {
    name: "Side",
    data() {
        return {
            side_menu: [
                { name: "项目概况", url: "ProjectDetail", code: "&#xe64a;" },
                { name: "接口管理", url: "RecordApi", code: "&#xe74a;" },
                {
                    name: "测试用例",
                    url: "TestCase",
                    code: "&#xe6da;",
                    children: [
                        { name: "添加用例", url: "AutoTest" },
                        { name: "录制用例", url: "RecordCase" }
                    ]
                },
                { name: "配置管理", url: "RecordConfig", code: "&#xee32;" },
                { name: "全局变量", url: "GlobalEnv", code: "&#xe692;" },
                { name: "驱动代码", url: "DebugTalk", code: "&#xe7ca;" },
                { name: "定时任务", url: "Tasks", code: "&#xe61e;" },
                { name: "测试报告", url: "Reports", code: "&#xe66e;" },
                {
                    name: "日志管理",
                    url: "Logging",
                    code: "&#59266;",
                    children: [{ name: "登录日志", url: "LoginLog" }]
                }
            ]
        };
    },
    methods: {
        select(url) {
            this.$store.commit("setRouterName", url);
            this.$router.push({ name: url }).catch(err => {
                // 忽略NavigationDuplicated错误
                if (err.name !== "NavigationDuplicated") {
                    // 如果错误不是NavigationDuplicated,则继续抛出错误
                    throw err;
                }
            });
            this.setLocalValue("routerName", url);
            let projectName = "";
            if (url !== "ProjectList") {
                projectName = this.$store.state.projectName;
            }
            this.$store.commit("setProjectName", projectName);
        }
    },
    mounted() {
        if (this.$store.state.show_hosts) {
            this.side_menu.splice(5, 0, {
                name: "Hosts管理",
                url: "HostIP",
                code: "&#xe609;"
            });
        }
    }
};
</script>
 
<style scoped>
.common-side-bar {
    position: fixed;
    top: 48px;
    border-right: 1px solid #eaeaea;
    height: calc(100% - 48px);
    width: 200px;
    background-color: #fff;
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.03);
    border-radius: 0 12px 12px 0;
    z-index: 10;
}
 
.el-menu {
    border-right: none;
    padding: 8px 0;
}
 
.el-menu-item, .el-submenu__title {
    height: 44px;
    line-height: 44px;
    margin: 4px 12px;
    border-radius: 6px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 14px;
    font-weight: 500;
}
 
.el-menu-item:hover, .el-submenu__title:hover {
    background-color: #f5f9ff !important;
    color: #318DF1 !important;
    transform: translateX(2px);
}
 
.el-menu-item.is-active {
    background-color: #e6f0ff !important;
    color: #318DF1 !important;
    font-weight: 600;
}
 
.iconfont {
    font-size: 18px;
    vertical-align: middle;
    margin-right: 8px;
}
 
.el-submenu .el-menu-item {
    padding-left: 48px !important;
    height: 36px;
    line-height: 36px;
    margin: 2px 12px;
    font-size: 13px;
    min-width: 0;  /* 添加这行防止宽度溢出 */
    width: auto;   /* 添加这行让宽度自适应 */
}
 
.el-submenu /deep/ .el-submenu__title {
    min-width: 0;  /* 添加这行防止标题宽度溢出 */
}
 
.el-submenu .el-menu-item:hover {
    background-color: #f0f7ff !important;
}
</style>