main.vue
8.97 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<template>
<gl-row :gutter="150">
<gl-col :span='8'>
<div class="menu-box box">
<div class="title" v-html="title"></div>
<div class="console-btn">
<div><gl-button @click="openAll(openOrClose)">{{openOrClose ? '全部展开' : '全部收起'}}</gl-button></div>
<div><gl-button @click="pushSublings" type='primary' :disabled="push">添加同级菜单</gl-button></div>
<div><gl-button @click="pushChildren" type='primary' :disabled="push">添加子菜单</gl-button></div>
</div>
<tree
ref='tree'
@node-click='nodeClick'
></tree>
</div>
</gl-col>
<gl-col :span='16' v-show="showDetails">
<div class="details box">
<div class="title">详情</div>
<gl-form :model='form' class="content" label-width="150px">
<gl-form-item label="名称" >
<gl-input v-model="form.name" ref="name"></gl-input>
</gl-form-item>
<gl-form-item label="主机自定义名称">
<gl-input v-model="form.newName"></gl-input>
</gl-form-item>
<gl-form-item label="打开模式">
<gl-select v-model="form.open" style="width:100%">
<gl-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value">
</gl-option>
</gl-select>
</gl-form-item>
<gl-form-item label="功能类型">
<gl-select v-model="form.type" style="width:100%" placeholder="请选择功能类型">
<gl-option
v-for="item in options2"
:key="item.value"
:label="item.label"
:value="item.value">
</gl-option>
</gl-select>
</gl-form-item>
<gl-form-item label="上级菜单">
<gl-input v-model="form.upMenu" disabled></gl-input>
</gl-form-item>
<gl-form-item label="菜单路径">
<gl-input v-model="form.url" disabled></gl-input>
</gl-form-item>
<gl-form-item label="路由">
<gl-input v-model="form.router"></gl-input>
</gl-form-item>
<gl-form-item label="基础路径">
<gl-input v-model="form.defaultUrl"></gl-input>
</gl-form-item>
<gl-form-item label="排序">
<gl-input v-model="form.index"></gl-input>
</gl-form-item>
<gl-form-item label="是否隐藏">
<gl-switch v-model="form.Show"></gl-switch>
</gl-form-item>
<gl-form-item label="创建时间">
<gl-input v-model="form.createTime" disabled></gl-input>
</gl-form-item>
<gl-form-item label="修改时间">
<gl-input v-model="form.changeTime" disabled></gl-input>
</gl-form-item>
<gl-form-item>
<gl-button type="primary" @click="submit">{{btnTxt}}</gl-button>
<gl-button type="danger" v-show='del' @click="delData">删除</gl-button>
<gl-button @click="showDetails = false" style="float:right">取消</gl-button>
</gl-form-item>
</gl-form>
</div>
</gl-col>
</gl-row>
</template>
<script>
var timeTip = '系统自动生成(格式yyyy-MM-dd HH:mm:ss)'
export default {
name: 'MenuManager',
data() {
return {
data: [],
props: null,
openOrClose: true,
node: null,
btnTxt: '修改',
allNode: null,
push: true,
del: true,
showDetails: false,
_children: false,
_sublings: false,
form: {
name: '',
newName: '',
open: '新系统',
type: '',
upMenu: '',
url: '',
router: '',
defaultUrl: '',
index: '',
Show: true,
createTime: null,
changeTime: null
},
options: [
{
value: '选项1',
label: '本系统'
},
{
value: '选项2',
label: '新系统'
}
],
options2: [
{
value: '选项1',
label: '菜单路由'
},
{
value: '选项2',
label: '菜单'
},
{
value: '选项3',
label: '按钮'
}
]
}
},
props: {
title: {
type: String,
default: '标题'
}
},
watch: {
'form.name'(val) {
if (val !== '') this.$refs.name.$el.classList.remove('err')
}
},
methods: {
nodeClick(data, node, that, props) {
if (node.level === 1) this.data = node.parent.data
this.btnTxt = '修改'
this.node = node
this.allNode = data
this.props = props
this._sublings = false
this._children = false
this.del = true
this.push = false
this.showDetails = true
this.form.name = data.label || data[props.label]
this.form.upMenu = node.level === 1 ? '顶级菜单' : node.parent.data.label || node.parent.data[props.label]
this.form.defaultUrl = data.path
this.form.index = node.data.id
this.form.createTime = data.createTime
this.form.changeTime = data.changeTime
},
// 展开与关闭
openAll(val) {
this.searchChildren(this.$refs.tree.$children[0].$children[0].store._getAllNodes(), val)
this.openOrClose = !this.openOrClose
},
searchChildren(data, val) {
data.forEach(el => {
el.expanded = val
if (el.childNodes) {
this.searchChildren(el.childNodes, val)
}
})
},
// 添加同级菜单
pushSublings() {
this.btnTxt = '保存'
this._sublings = true
this._children = false
this.del = false
this.showDetails = true
for (const key in this.form) {
this.form[key] = null
}
this.form.createTime = timeTip
this.form.changeTime = timeTip
},
// 添加子菜单
pushChildren() {
this.btnTxt = '保存'
this._children = true
this._sublings = false
this.del = false
this.showDetails = true
for (const key in this.form) {
this.form[key] = null
}
this.form.createTime = timeTip
this.form.changeTime = timeTip
},
// 删除
delData() {
for (let index = 0; index < this.node.parent.childNodes.length; index++) {
if (this.node.parent.childNodes[index] === this.node) this.node.level === 1 ? this.node.parent.data.splice(index, 1) : this.node.parent.data.children.splice(index, 1)
}
this.$notify({
title: '删除成功',
type: 'success'
})
this.$set_session_config(this.data)
this.showDetails = false
},
// 保存修改
submit() {
if (this.form.name !== '' && this.form.name !== null) {
let arr = {}
// 添加同级
if (this._sublings) {
arr = {
id: this.form.index,
level: this.node.level,
createTime: new Date().format('yyyy-MM-dd HH:mm:ss')
}
arr[this.props.label] = this.form.name
if (this.node.level === 1) {
this.data.push(arr)
} else {
if (this.node.parent.data.children === undefined) this.$set(this.node.parent.data, 'children', [])
this.node.parent.data.children.push(arr)
}
} else if (this._children) { // 添加子级
arr = {
id: this.form.index,
level: this.node.level + 1,
createTime: new Date().format('yyyy-MM-dd HH:mm:ss')
}
arr[this.props.label] = this.form.name
if (this.allNode.children === undefined) this.$set(this.allNode, 'children', [])
this.allNode.children.push(arr)
} else { // 修改
this.node.data.id = this.form.index
this.node.data[this.props.label] = this.form.name
if (this.node.data.changeTime === undefined) this.$set(this.node.data, 'changeTime', '')
this.node.data.changeTime = new Date().format('yyyy-MM-dd HH:mm:ss')
}
this.showDetails = false
this.$notify({
title: '操作成功',
type: 'success'
})
this.$set_session_config(this.data)
} else {
this.$refs.name.$el.classList.add('err')
}
}
}
}
</script>
<style scoped>
.content{
padding: 15px;
}
.box{
margin-bottom: 20px;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 4px;
}
.title{
color: #333;
background-color: #f5f5f5;
border-color: #ddd;
padding: 10px 15px;
border-bottom: 1px solid transparent;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
}
.el-form-item{
margin-bottom: 15px;
}
.console-btn{
padding: 15px;
display: flex;
flex-wrap:wrap;
width: 100%;
box-sizing: border-box;
}
.console-btn div{
flex: 1;
height: 40px;
margin-bottom: 10px;
}
.err::after{
content: '请填写列表名称';
display: block;
color: red;
}
</style>