VirtualHost.vue
28.6 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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
<template>
<el-container>
<el-main>
<el-card style="background-color: #F5F7FA">
<!-- 搜素区域 -->
<div>
<el-row>
<el-col :span="7">
<el-input v-model="queryInfo.virtualHostName" size="medium"
placeholder="虚拟主机名称" clearable>
<template slot="prepend"><i class="el-icon-s-operation"></i>虚拟主机名称</template>
</el-input>
</el-col>
<el-col :span="7">
<el-select v-model="queryInfo.serverId" placeholder="请选择所属服务器"
prefix-icon="el-icon-search" clearable size="medium" filterable >
<el-option
v-for="item in (virtualHost_config.serverList)"
:key="item.id"
:label="item.serverName"
:value="item.id">
</el-option>
</el-select>
</el-col>
<el-col :span="8">
<el-button type="warning" style="width:150px" icon="el-icon-search" size="medium" @click="getVirtualHostList">
查询虚拟主机
</el-button>
<el-button type="primary" style="width:150px" icon="el-icon-plus" size="medium" @click="toAddDialog">
添加虚拟主机
</el-button>
</el-col>
</el-row>
</div>
<!-- 列表区域 -->
<div style="margin-top: 20px;">
<el-table :data="virtualHostList" border v-loading="virtualHost_loading.listLoading"
@selection-change="selectChange" size="small"
element-loading-text="获取虚拟主机列表,拼命加载中"
:header-cell-style="{background:'#6F8294',color:'#FFFFFF'}"
style="border-radius: 10px 10px 0px 0px;line-height: 25px;">
<el-table-column type="selection" width="55" align="center"></el-table-column>
<el-table-column type="index" align="center"></el-table-column>
<el-table-column label="虚拟主机名称" prop="virtualHostName" align="center"
width="220"></el-table-column>
<el-table-column label="所属服务器" prop="busServer.serverName" align="center" width="220">
</el-table-column>
<el-table-column label="相关描述" prop="description" align="center" width="300"></el-table-column>
<el-table-column label="操作" align="center" >
<template slot-scope="scope">
<el-row>
<!-- 交换机-->
<el-tooltip effect="dark" content="交换机" placement="top-start" :enterable="false">
<el-button type="warning" icon="el-icon-link" size="small"
style="width:97px;margin-left: 1px;"
@click="toExchange(scope.$index,scope.row)">交换机
</el-button>
</el-tooltip>
<!-- 编辑按钮-->
<el-tooltip effect="dark" content="编辑" placement="top-start" :enterable="false">
<el-button type="primary" icon="el-icon-edit" size="small"
style="width:97px;margin-left: 1px;"
@click="toEditDialog(scope.$index,scope.row)">编辑
</el-button>
</el-tooltip>
</el-row>
<el-row>
<!-- 队列-->
<el-tooltip effect="dark" content="队列" placement="top-start" :enterable="false">
<el-button type="success" icon="el-icon-link" size="small"
style="width:97px;margin-left: 1px;margin-top: 3px;"
@click="toQueue(scope.$index,scope.row)">队列
</el-button>
</el-tooltip>
<!-- 删除按钮-->
<el-tooltip effect="dark" content="删除" placement="top-start" :enterable="false">
<el-button type="danger" icon="el-icon-delete" size="small"
style="width:97px;margin-left: 1px;"
:loading="virtualHost_loading.delLoading"
@click="removeVirtualHostInfo(scope.$index,scope.row)">删除
</el-button>
</el-tooltip>
</el-row>
</template>
</el-table-column>
</el-table>
<!--分页区域-->
<div style="margin-top: 10px">
<el-row :gutter="24">
<el-col :span="5">
<el-button type="danger" icon="el-icon-delete"
:disabled="this.selectList.length===0"
@click="batchDeleteVirtualHost">批量删除
</el-button>
</el-col>
<el-col :span="10" style="margin-top: 5px">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="queryInfo.pageNum"
:page-sizes="[10,20,30,50]"
:page-size="queryInfo.pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="total">
</el-pagination>
</el-col>
</el-row>
</div>
</div>
</el-card>
<!-- 对话框 —> 添加虚拟主机信息 -->
<div>
<el-dialog title="添加虚拟主机信息"
:visible.sync="virtualHostDialog.addDialog"
style="margin-top: -50px"
width="50%" text-align="center" @close="virtualHostAddDialogClosed">
<el-form :inline="true" :model="addVirtualHostForm" label-width="130px" status-icon
:rules="addVirtualHostFormRules" ref="addVirtualHostRef"
align="center">
<el-row>
<el-form-item label="" prop="virtualHostName">
<el-input v-model="addVirtualHostForm.virtualHostName" style="width:300px" size="small"
clearable
placeholder="请输入虚拟主机名称">
<template slot="prepend" >虚拟主机名称</template>
</el-input>
</el-form-item>
</el-row>
<el-row>
<el-form-item label="" prop="serverId">
<el-select v-model="addVirtualHostForm.serverId" clearable style="width:300px" size="small"
filterable placeholder="请选择服务器名称">
<el-option
v-for="item in (virtualHost_config.serverList)"
:key="item.id"
:label="item.serverName"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</el-row>
<el-row>
<el-form-item label="" prop="description">
<el-input v-model="addVirtualHostForm.description" placeholder="请输入相关描述"
style="width:300px" clearable size="small"
type="textarea" autosize :rows="1">
</el-input>
</el-form-item>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer" style="text-align: center">
<el-button type="info" @click="virtualHostDialog.addDialog = false" size="medium"
style="width: 100px;background-color: #6F8294;color: #ffffff">取消
</el-button>
<el-button type="primary" @click="addVirtualHostInfo" :loading="virtualHost_loading.addLoading"
size="medium"
style="width: 100px">
添加
</el-button>
</div>
</el-dialog>
</div>
<!-- 对话框 —> 编辑虚拟主机信息 -->
<div>
<el-dialog title="编辑虚拟主机"
:visible.sync="virtualHostDialog.editDialog"
style="margin-top: -50px"
width="50%" text-align="center" @close="virtualHostEditDialogClosed">
<el-form :inline="true" :model="editVirtualHostForm" label-width="120px" status-icon
:rules="editVirtualHostFormRules" ref="editVirtualHostRef"
align="center">
<el-row>
<el-form-item label="" prop="virtualHostName">
<el-input v-model="editVirtualHostForm.virtualHostName" style="width:300px" clearable
readonly disabled size="small"
placeholder="请输入虚拟主机名称">
<template slot="prepend" >虚拟主机名称</template>
</el-input>
</el-form-item>
</el-row>
<el-row>
<el-form-item label="" prop="serverId">
<el-select v-model="editVirtualHostForm.serverId" placeholder="请选择服务器名称"
size="small" clearable disabled style="width:300px">
<el-option
v-for="item in (virtualHost_config.serverList)"
:key="item.id"
:label="item.serverName"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
</el-row>
<el-row>
<el-form-item label="" prop="description">
<el-input v-model="editVirtualHostForm.description" placeholder="请输入相关描述"
style="width:300px" clearable size="small"
type="textarea" autosize :rows="1"/>
</el-form-item>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer" style="text-align: center">
<el-button type="info" @click="virtualHostDialog.editDialog = false" size="medium"
style="width: 100px;background-color: #6F8294;color: #ffffff">取消
</el-button>
<el-button type="primary" @click="editVirtualHostInfo" :loading="virtualHost_loading.addLoading"
size="medium"
style="width: 100px">
编辑
</el-button>
</div>
</el-dialog>
</div>
</el-main>
</el-container>
</template>
<script>
import {
selectVirtualHostList,
insertVirtualHost,
updateVirtualHost,
deleteVirtualHost,
batchRemoveVirtualHost,
getServerList,
} from "../../api/message_bus";
export default {
name: "VirtualHost",
data() {
return {
/**
* 搜索参数
*/
queryInfo: {
// 所属服务器ID
serverId: '',
// 虚拟主机名称
virtualHostName: '',
// 当前页数
pageNum: 1,
// 每页条数
pageSize: 10
},
/**
* 虚拟机,配置参数
*/
virtualHost_config: {
// 所属服务器的名称
serverName: '',
serverList: [],
},
/**
* 添加虚拟主机的表单
*/
addVirtualHostForm: {
// 虚拟主机名称
virtualHostName: '',
// 所属服务器ID
serverId: '',
// 相关描述
description: '',
},
/**
* 列表记录的总条数
*/
total: 0,
/**
* 批量删除的选中列表
*/
selectList: [],
/**
* 虚拟主机列表
*/
virtualHostList: [],
/**
* 编辑虚拟主机,表单
*/
editVirtualHostForm: {},
/**
* virtualHost,对话框管理
*/
virtualHostDialog: {
// 添加对话框
addDialog: false,
// 编辑对话框
editDialog: false,
},
/**
* virtualHost,加载
*/
virtualHost_loading: {
// 列表加载
listLoading: false,
// 添加加载
addLoading: false,
// 编辑加载
editLoading: false,
// 删除加载
delLoading: false,
// 批量删除加载
batchDelLoading: false,
},
/**
* 添加虚拟主机,表单的验证规则对象
*/
addVirtualHostFormRules: {
virtualHostName: [
{required: true, message: '请输入虚拟主机名称', trigger: ['blur', 'change']},
],
serverId: [
{required: true, message: '请选择所属服务器', trigger: ['blur']},
],
description: [
{required: true, message: '请输入虚拟主机相关描述', trigger: ['blur', 'change']},
],
},
/**
* 编辑虚拟主机,表单的验证规则对象
*/
editVirtualHostFormRules: {
virtualHostName: [
{required: true, message: '请输入虚拟主机名称', trigger: ['blur', 'change']},
],
serverId: [
{required: true, message: '请选择所属服务器', trigger: ['blur', 'change']},
],
description: [
{required: true, message: '请输入虚拟主机相关描述', trigger: ['blur', 'change']},
],
},
}
},
methods: {
/**
* 分页查询,监听 pageSize 改变的事件
*/
handleSizeChange(newSize) {
this.queryInfo.pageSize = newSize;
//刷新列表
this.getVirtualHostList();
},
/**
* 分页查询,监听 pageNum 改变的事件
*/
handleCurrentChange(newPage) {
this.queryInfo.pageNum = newPage;
//刷新列表
this.getVirtualHostList();
},
/**
* 分页查询,虚拟主机
*/
getVirtualHostList() {
if (this.virtualHost_config.serverName !== undefined) {
this.virtualHost_config.serverName = undefined;
}
// 开启加载
this.virtualHost_loading.listLoading = true;
selectVirtualHostList(this.queryInfo).then((response) => {
let res = response.data;
if (res.code !== '200') {
// 关闭加载
this.virtualHost_loading.listLoading = false;
return this.$message.error(res.msg);
}
console.log(res.data.list);
// 获取列表数据
this.virtualHostList = res.data.list;
// 获取列表的总记录数
this.total = res.data.total;
// 关闭加载
this.virtualHost_loading.listLoading = false;
this.$message.success(res.msg);
}).catch(error => {
// 关闭加载
this.virtualHost_loading.listLoading = false;
this.$message.error(error.toString());
});
},
/**
* 虚拟主机信息,添加对话框,打开事件
*/
toAddDialog() {
this.virtualHostDialog.addDialog = true;
},
/**
* 虚拟主机信息,添加对话框,关闭事件
*/
virtualHostAddDialogClosed() {
//重置对话框
this.$refs.addVirtualHostRef.resetFields();
},
/**
* 虚拟主机信息,添加功能
*/
addVirtualHostInfo() {
// 进行表单的预验证
this.$refs.addVirtualHostRef.validate(valid => {
// 未通过,表单预校验
if (!valid) return;
// 通过,表单预检验
this.virtualHost_loading.addLoading = true;
insertVirtualHost(this.addVirtualHostForm).then((response) => {
let res = response.data;
// 添加失败
if (res.code !== '200') {
// 关闭加载
this.virtualHost_loading.addLoading = false;
return this.$message.error(res.msg);
}
// 添加,成功
this.$message.success(res.msg);
// 关闭加载
this.virtualHost_loading.addLoading = false;
// 隐藏对话框
this.virtualHostDialog.addDialog = false;
// 刷新列表
this.getVirtualHostList();
}).catch(error => {
this.virtualHost_loading.addLoading = false;
this.$message.error(error.toString());
});
})
},
/**
* 虚拟主机信息,编辑对话框,打开事件
*/
toEditDialog(index, row) {
this.editVirtualHostForm = Object.assign({}, row);
this.virtualHostDialog.editDialog = true;
},
/**
* 虚拟主机信息,编辑对话框,关闭事件
*/
virtualHostEditDialogClosed() {
//重置对话框
this.$refs.editVirtualHostRef.resetFields();
},
/**
* 虚拟主机信息,编辑功能
*/
editVirtualHostInfo() {
//进行表单的预验证
this.$refs.editVirtualHostRef.validate(valid => {
// 未通过,表单预校验
if (!valid) return;
// 通过,表单预检验
this.virtualHost_loading.editLoading = true;
updateVirtualHost(this.editVirtualHostForm).then((response) => {
let res = response.data;
if (res.code !== '200') {
//关闭加载
this.virtualHost_loading.editLoading = false;
return this.$message.error(res.msg);
}
// 关闭加载
this.virtualHost_loading.editLoading = false;
this.$message.success(res.msg);
// 隐藏对话框
this.virtualHostDialog.editDialog = false;
// 刷新列表
this.getVirtualHostList();
}).catch(error => {
this.virtualHost_loading.editLoading = false;
this.$message.error(error.toString());
});
})
},
/**
* 虚拟主机信息,删除
*/
removeVirtualHostInfo(index, row) {
// 弹框询问是否删除?
this.$confirm('此操作永久删除该虚拟主机信息, 是否继续?', '警告', {
confirmButtonText: '确定删除',
cancelButtonText: '取消',
type: 'warning'
}
).then(() => {
// 开启加载
this.virtualHost_loading.delLoading = true;
deleteVirtualHost(row).then((response) => {
let res = response.data;
if (res.code !== '200') {
//关闭加载
this.virtualHost_loading.delLoading = false;
return this.$message.error(res.msg);
}
//关闭加载
this.virtualHost_loading.delLoading = false;
this.$message.success(res.msg);
//刷新列表
this.getVirtualHostList();
}).catch(error => {
this.virtualHost_loading.delLoading = false;
this.$message.error(error.toString());
});
}).catch(() => {
});
},
/**
* 批量删除,之前的选中
*/
selectChange: function (selectList) {
this.selectList = selectList;
},
/**
* 批量删除-虚拟主机
*/
batchDeleteVirtualHost() {
const ids = this.selectList.map(item => item.id).toString();
this.$confirm('此操作将永久删除选中的虚拟主机信息, 是否继续?', '警告', {
confirmButtonText: '确定删除',
cancelButtonText: '取消',
type: 'warning'
}
).then(() => {
// 开启加载
this.virtualHost_loading.batchDelLoading = true;
let params = {ids: ids};
batchRemoveVirtualHost(params).then(response => {
let res = response.data;
if (res.code !== '200') {
// 关闭加载
this.virtualHost_loading.batchDelLoading = false;
return this.$message.error(res.msg);
}
this.$message.success(res.msg);
// 关闭加载
this.virtualHost_loading.batchDelLoading = false;
// 刷新列表
this.getVirtualHostList();
}).catch(error => {
// 关闭加载
this.virtualHost_loading.batchDelLoading = false;
this.$message.error(error.toString());
});
}).catch(() => {
});
},
/**
* 获取服务器列表
*/
selectServerList() {
getServerList().then((response) => {
let res = response.data;
if (res.code !== '200') {
return this.$message.error(res.msg);
}
this.virtualHost_config.serverList = res.data;
}).catch(error => {
this.$message.error(error.toString());
});
},
/**
* 携带参数,跳转至交换机界面
*/
toExchange(index, row) {
this.$confirm('查看该虚拟主机下的交换机, 是否继续?', '提示', {
confirmButtonText: '查看',
cancelButtonText: '取消',
type: 'warning'
}
).then(() => {
this.$router.push({name: "交换机管理", params: {virtualHost_scopeRow: row}})
}).catch(() => {
});
},
/**
* 携带参数,跳转至队列界面
*/
toQueue(index, row) {
this.$confirm('查看该交换机下的队列, 是否继续?', '提示', {
confirmButtonText: '查看',
cancelButtonText: '取消',
type: 'warning'
}
).then(() => {
this.$router.push({name: "队列管理", params: {virtualHost_scopeRow: row}})
}).catch(() => {
});
},
},
created() {
if (this.$route.params.server_scopeRow !== undefined) {
// 参数,服务器id
this.queryInfo.serverId = this.$route.params.server_scopeRow.id;
// 刷新列表
this.getVirtualHostList();
// 参数,服务器名称
this.virtualHost_config.serverName = this.$route.params.server_scopeRow.serverName;
} else {
// 刷新列表
// this.getVirtualHostList();
}
},
mounted() {
this.selectServerList();
},
computed: {},
}
</script>
<style scoped>
</style>