0%

django-models-serializer-view-demo

序列化Demo

code

models.py

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
class Service(BaseModel):
....

CHOICE_SERVICE_LEVEL = (
(1, "核心"),
(2, "重要"),
(3, "一般"),
(4, "边缘"),
)

......

name = models.CharField(
max_length=50, unique=True, blank=True, verbose_name="应用名称")

businessLine = models.ForeignKey(
BusinessLine, null=True, blank=True, verbose_name="业务线", on_delete=models.CASCADE)
webVersion = models.CharField(
max_length=20, null=True, blank=True, choices=CHOICE_WEB_VERSION, verbose_name="JDK版本")
developer = models.ForeignKey(
UserProfile, related_name="service_developer", null=True, blank=True, verbose_name="开发负责人", on_delete=models.CASCADE)
tester = models.ForeignKey(
UserProfile, related_name="service_tester", null=True, blank=True, verbose_name="测试负责人", on_delete=models.CASCADE)
serviceLevel = models.IntegerField(
choices=CHOICE_SERVICE_LEVEL, null=True, blank=True, verbose_name="服务等级")
isIndependentRD = models.BooleanField(default=False, verbose_name='是否自主研发')
domainPro = models.CharField(
max_length=100, null=True, blank=True, verbose_name="域名-生产")
ecsPro = models.ManyToManyField(
CMDBBase, related_name="service_ecspro", blank=True, through='ServiceEcsPro', through_fields=('service', 'ecs', 'port'), verbose_name="主机-生产")
dbPro = models.ManyToManyField(
Database, related_name="service_dbpro", blank=True, verbose_name="数据库-生产")
componentPro = models.ManyToManyField(
Component, related_name="service_componentpro", blank=True, verbose_name="组件-生产")


def __str__(self):
return self.name

class Meta:
verbose_name = "服务管理"
verbose_name_plural = verbose_name

serializers.py

1
2
3
4
5
6
7
8
9
class ServiceDetailSerializer(serializers.ModelSerializer):
developer = serializers.StringRelatedField(many=False)
tester = serializers.StringRelatedField(many=False)
businessLine = serializers.StringRelatedField(many=False)
serviceLevel = serializers.CharField(source='get_serviceLevel_display')

class Meta:
model = models.Service
fields = "__all__"

views.py

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
class ServiceViewset(BaseModelViewSet):
"""
应用管理
"""

def get_queryset(self):
name = self.request.query_params.get("name", None)
platform = self.request.query_params.get("platform", None)
if name or platform:
q_search = Q()
# q_search.connector = "OR"
q_search.connector = "AND"
if name:
q_search.children.append(("name__icontains", name))
if platform:
q_search.children.append(("platform", platform))
return models.Service.objects.filter(q_search).order_by('-id')

return models.Service.objects.all().order_by('id')

def get_serializer_class(self):
if self.action in ('_list', 'list'):
return serializers.ServiceListSerializer
if self.action in ('_detail'):
return serializers.ServiceDetailSerializer
return serializers.ServiceSerializer

@action(methods=['post'], detail=False)
def _create(self, request, *args, **kwargs):
"""
create
由于应用绑定的主机需要记录端口信息,所以需要额外处理。

ecsPro = [
{
'id': 1,
'port': 8080
},
{
'id': 2,
'port': 8080
}
]
"""
response = super(BaseModelViewSet, self).create(
request, *args, **kwargs)

ecsPro = request.data.get('ecsPro', None)
ecsPre = request.data.get('ecsPre', None)
ecsTest = request.data.get('ecsTest', None)
ecsDev = request.data.get('ecsDev', None)
id = response.data.get('id')
service = models.Service.objects.get(pk=id)
try:
if ecsPro:
for sub_ecs in ecsPro:
sub_ecs_id = sub_ecs.get('id')
sub_port = sub_ecs.get('port')
ecs = models.CMDBBase.objects.get(pk=sub_ecs_id)
models.ServiceEcsDev.objects.create(
service=service, ecs=ecs, port=sub_port)
response.data['ecsPro'] = ecsPro
if ecsPre:
for sub_ecs in ecsPre:
sub_ecs_id = sub_ecs.get('id')
sub_port = sub_ecs.get('port')
ecs = models.CMDBBase.objects.get(pk=sub_ecs_id)
models.ServiceEcsDev.objects.create(
service=service, ecs=ecs, port=sub_port)
response.data['ecsPre'] = ecsPre
if ecsTest:
for sub_ecs in ecsTest:
sub_ecs_id = sub_ecs.get('id')
sub_port = sub_ecs.get('port')
ecs = models.CMDBBase.objects.get(pk=sub_ecs_id)
models.ServiceEcsDev.objects.create(
service=service, ecs=ecs, port=sub_port)
response.data['ecsTest'] = ecsTest
if ecsDev:
for sub_ecs in ecsDev:
sub_ecs_id = sub_ecs.get('id')
sub_port = sub_ecs.get('port')
ecs = models.CMDBBase.objects.get(pk=sub_ecs_id)
models.ServiceEcsDev.objects.create(
service=service, ecs=ecs, port=sub_port)
response.data['ecsDev'] = ecsDev
except Exception as e:
service.delete()
print("Error", e.args)
return json_error_response(errMsg="error, {}".format(e.args))
return json_ok_response(response.data)

@action(methods=['post'], detail=False)
def _update(self, request, *args, **kwargs):
"""
update
"""
response = super(BaseModelViewSet, self).update(
request, *args, **kwargs)

ecsPro = request.data.get('ecsPro', None)
ecsPre = request.data.get('ecsPre', None)
ecsTest = request.data.get('ecsTest', None)
ecsDev = request.data.get('ecsDev', None)
id = response.data.get('id')
service = models.Service.objects.get(pk=id)
try:
if ecsPro:
# 如果更新的话,先将之前全部关联ecs移除
service.ecsPro.clear()
for sub_ecs in ecsPro:
sub_ecs_id = sub_ecs.get('id')
sub_port = sub_ecs.get('port')
ecs = models.CMDBBase.objects.get(pk=sub_ecs_id)
models.ServiceEcsPro.objects.create(
service=service, ecs=ecs, port=sub_port)
response.data['ecsPro'] = ecsPro
if ecsPre:
service.ecsPre.clear()
for sub_ecs in ecsPre:
sub_ecs_id = sub_ecs.get('id')
sub_port = sub_ecs.get('port')
ecs = models.CMDBBase.objects.get(pk=sub_ecs_id)
models.ServiceEcsPre.objects.create(
service=service, ecs=ecs, port=sub_port)
response.data['ecsPre'] = ecsPre
if ecsTest:
service.ecsTest.clear()
for sub_ecs in ecsTest:
sub_ecs_id = sub_ecs.get('id')
sub_port = sub_ecs.get('port')
ecs = models.CMDBBase.objects.get(pk=sub_ecs_id)
models.ServiceEcsTest.objects.create(
service=service, ecs=ecs, port=sub_port)
response.data['ecsTest'] = ecsTest
if ecsDev:
service.ecsDev.clear()
for sub_ecs in ecsDev:
sub_ecs_id = sub_ecs.get('id')
sub_port = sub_ecs.get('port')
ecs = models.CMDBBase.objects.get(pk=sub_ecs_id)
models.ServiceEcsDev.objects.create(
service=service, ecs=ecs, port=sub_port)
response.data['ecsDev'] = ecsDev
except Exception as e:
print("Error", e.args)
return json_error_response(errMsg="error, {}".format(e.args))
return json_ok_response(response.data)

@action(methods=['get'], detail=False)
def _enumerate(self, request):
"""
枚举值
"""
data = {
"CHOICE_LANGUAGE": models.Service.CHOICE_LANGUAGE,
"CHOICE_JDK_VERSION": models.Service.CHOICE_JDK_VERSION,
"CHOICE_WEB_VERSION": models.Service.CHOICE_WEB_VERSION,
"CHOICE_SERVICE_LEVEL": models.Service.CHOICE_SERVICE_LEVEL,
"CHOICE_PLATFORM": models.Service.CHOICE_PLATFORM,
"CHOICE_STATUS": models.Service.CHOICE_STATUS,
}
return json_ok_response(data)

@action(methods=['get'], detail=False)
def _detail(self, request, *args, **kwargs):
"""
detail
"""
queryset = self.get_object()
data = self.get_serializer(queryset, many=False).data

ecsPro = data.get('ecsPro')
ecsPre = data.get('ecsPre')
ecsTest = data.get('ecsTest')
ecsDev = data.get('ecsDev')

componentPro = data.get('componentPro')
componentPre = data.get('componentPre')
componentTest = data.get('componentTest')
componentDev = data.get('componentDev')

dbPro = data.get('dbPro')
dbPre = data.get('dbPre')
dbTest = data.get('dbTest')
dbDev = data.get('dbDev')

if ecsPro:
ecsPro_value = []
for ecs_id in ecsPro:
ecs = models.CMDBBase.objects.get(pk=ecs_id)
tmp_data = ServiceCmdbDetailSerializer(
instance=ecs, many=False).data
ecs_port = models.ServiceEcsPro.objects.get(
service=queryset, ecs=ecs).port
tmp_data['port'] = ecs_port
ecsPro_value.append(tmp_data)
data['ecsPro'] = ecsPro_value

if ecsPre:
ecsPre_value = []
for ecs_id in ecsPre:
ecs = models.CMDBBase.objects.get(pk=ecs_id)
tmp_data = ServiceCmdbDetailSerializer(
instance=ecs, many=False).data
ecs_port = models.ServiceEcsPre.objects.get(
service=queryset, ecs=ecs).port
tmp_data['port'] = ecs_port
ecsPre_value.append(tmp_data)
data['ecsPre'] = ecsPre_value

if ecsTest:
ecsTest_value = []
for ecs_id in ecsTest:
ecs = models.CMDBBase.objects.get(pk=ecs_id)
tmp_data = ServiceCmdbDetailSerializer(
instance=ecs, many=False).data
ecs_port = models.ServiceEcsTest.objects.get(
service=queryset, ecs=ecs).port
tmp_data['port'] = ecs_port
ecsTest_value.append(tmp_data)
data['ecsTest'] = ecsTest_value

if ecsDev:
ecsDev_value = []
for ecs_id in ecsDev:
ecs = models.CMDBBase.objects.get(pk=ecs_id)
tmp_data = ServiceCmdbDetailSerializer(
instance=ecs, many=False).data
ecs_port = models.ServiceEcsDev.objects.get(
service=queryset, ecs=ecs).port
tmp_data['port'] = ecs_port
ecsDev_value.append(tmp_data)
data['ecsDev'] = ecsDev_value

if componentPro:
componentPro_value = []
for component_id in componentPro:
component = models.Component.objects.get(pk=component_id)
componentPro_value.append(
{
'id': component_id,
'name': component.name
}
)
data['componentPro'] = componentPro_value

if componentPre:
componentPre_value = []
for component_id in componentPre:
component = models.Component.objects.get(pk=component_id)
componentPre_value.append(
{
'id': component_id,
'name': component.name
}
)
data['componentPre'] = componentPre_value

if componentTest:
componentTest_value = []
for component_id in componentTest:
component = models.Component.objects.get(pk=component_id)
componentTest_value.append(
{
'id': component_id,
'name': component.name
}
)
data['componentTest'] = componentTest_value

if componentDev:
componentDev_value = []
for component_id in componentDev:
component = models.Component.objects.get(pk=component_id)
componentDev_value.append(
{
'id': component_id,
'name': component.name
}
)
data['componentDev'] = componentDev_value

if dbPro:
tmp_data = []
for db_id in dbPro:
db = models.CMDBBase.objects.get(pk=component_id)
tmp_data.append(
{
'id': db_id,
'name': db.name
}
)
data['dbPro'] = tmp_data
if dbPre:
tmp_data = []
for db_id in dbPre:
db = models.CMDBBase.objects.get(pk=component_id)
tmp_data.append(
{
'id': db_id,
'name': db.name
}
)
data['dbPre'] = tmp_data
if dbTest:
tmp_data = []
for db_id in dbTest:
db = models.CMDBBase.objects.get(pk=component_id)
tmp_data.append(
{
'id': db_id,
'name': db.name
}
)
data['dbTest'] = tmp_data
if dbDev:
tmp_data = []
for db_id in dbDev:
db = models.CMDBBase.objects.get(pk=component_id)
tmp_data.append(
{
'id': db_id,
'name': db.name
}
)
data['dbDev'] = tmp_data

return json_ok_response(data)

接口信息

http://127.0.0.1:8080/api/v1/business/service/_detail?id=58

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
{
"code": "000000",
"showMsg": "Success",
"errMsg": null,
"data": {
"id": 58,
"developer": "admin",
"tester": "admin",
"businessLine": "业务线A",
"serviceLevel": "核心",
"createTime": "2021-06-21T17:10:06.984243",
"updateTime": "2021-06-21T17:10:06.984358",
"remark": null,
"name": "car-hailing-core",
"language": "Java",
"jdkVersion": "jdk-1.8.0_181",
"webVersion": "tomcat-8.5.39",
"webDir": "/data/servers/car-haling-core",
"codeDir": "/data/app/car-haling-core",
"isIndependentRD": true,
"gitUrl": "ssh://git@gitlab.zhaohongye.com:10022/sqzl_back_platform/car-hailing-core.git",
"status": "OnLine",
"thirdPartyCompany": null,
"desc": "sdasd功能描述",
"platform": "sjhl",
"domainPro": "https://prd-inside-car-hailing-core.zhaohongye.com/car-hailing-core",
"buildCommandPro": "clean package -Dmaven.test.skip=true -U -POnline",
"startCommandPro": "cataling.sh start",
"stopCommandPro": "cataling.sh stop",
"healthURLPro": "https://prd-inside-car-hailing-core.zhaohongye.com/car-hailing-core/asd",
"slbPro": "1.1.1.1",
"domainPre": null,
"buildCommandPre": null,
"startCommandPre": null,
"stopCommandPre": null,
"healthURLPre": null,
"slbPre": null,
"domainTest": null,
"buildCommandTest": null,
"startCommandTest": null,
"stopCommandTest": null,
"healthURLTest": null,
"slbTest": null,
"domainDev": null,
"buildCommandDev": null,
"startCommandDev": null,
"stopCommandDev": null,
"healthURLDev": null,
"slbDev": null,
"ecsPro": [
{
"id": 2,
"privateIp": "172.22.0.41",
"outIp": "211.151.0.4",
"type": "compute",
"platform": "",
"cpu": 1,
"mem": "64.261 G",
"capacity": "1.2 T",
"computeStatus": "",
"computeType": "",
"port": 8080
},
{
"id": 3,
"privateIp": "172.20.1.94",
"outIp": "211.151.0.4",
"type": "compute",
"platform": "",
"cpu": 32,
"mem": "64.261 G",
"capacity": "600.0 G",
"computeStatus": "",
"computeType": "",
"port": 8081
}
],
"dbPro": [
{
"id": 1,
"name": ""
},
{
"id": 2,
"name": ""
}
],
"componentPro": [
{
"id": 4,
"name": "ALI-Diamond4"
},
{
"id": 5,
"name": "ALI-Diamond5"
}
],
"ecsPre": [],
"dbPre": [],
"componentPre": [],
"ecsTest": [],
"dbTest": [],
"componentTest": [],
"ecsDev": [],
"dbDev": [],
"componentDev": []
}
}

前端展示

效果

列表页

详情页

vue代码

列表页index.vue
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
<template>
<div>
<el-container>
<el-aside width="200px">
<el-tree :data="data" :props="defaultProps" default-expand-all ref="tree" @node-click="handleNodeClick"></el-tree>
</el-aside>
<el-main>
<el-row>
<el-col :span="4">
<el-tooltip class="item" effect="dark" content="可根据 服务名称 模糊搜索" placement="bottom">
<el-input v-model="search_info" placeholder="请输入内容"></el-input>
</el-tooltip>
</el-col>
<el-col :span="2">
<el-button plain @click="handleSearch">搜索</el-button>
</el-col>
</el-row>
<br />
<div>
<!-- ('id', 'name', 'language', 'webVersion',
'platform', 'serviceLevel', 'developer') -->
<el-table :data="tableData" style="width: 100%" max-height="510">
<el-table-column fixed prop="name" label="应用名称" width="200"></el-table-column>
<el-table-column prop="language" label="开发语言"></el-table-column>
<el-table-column prop="webVersion" label="容器版本"></el-table-column>
<el-table-column prop="platform" label="应用来源"></el-table-column>
<el-table-column prop="serviceLevel" label="服务等级"></el-table-column>
<el-table-column prop="developer" label="开发负责人"></el-table-column>
<el-table-column fixed="right" label="操作" width="120">
<template slot-scope="scope">
<el-button size="mini" type="primary" @click="handleMore(scope.$index, scope.row)">More</el-button>
</template>
</el-table-column>
</el-table>
</div>
<br />
<br />
<div>
<div class="block">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="[10, 50, 100]"
:page-size="pagesize"
layout="total, sizes, prev, pager, next"
:total="total"
></el-pagination>
</div>
</div>
</el-main>
</el-container>
</div>
</template>

<script>
const axios = require("axios").default;
export default {
name: "asstes-index",
data() {
return {
data: [],
defaultProps: {
children: "children",
label: "name_cn",
},
tableData: [],
currentPage: 1,
pagesize: 10,
total: 10,
search_info: "",
serviceTreeNodeClicked: false,
serviceTreeNodeId: "",
};
},
created() {
this.requestdata(10, 1);
this.handtree();
},
methods: {
handleNodeClick(data) {
var id = data.id;
console.log(id);
this.serviceTreeNodeClicked = true;
this.serviceTreeNodeId = id;
this.requestnodedata(id, 10, 1);
},
handleMore(index, row) {
console.log(index, row);
this.$router.push({
path: "/service/detail",
query: { id: row.id },
});
},
handtree() {
const self = this;
axios({
method: "get",
url: "http://devops.zhaohongye.com/api/v1/service_tree/nodes",
responseType: "json",
}).then(function(response) {
var res = response.data.data;
console.log(res);
self.data = res;
console.log(self.data);
});
},
handleSearch() {
console.log(this.search_info, typeof this.search_info);
const self = this;
axios({
method: "get",
url: "http://polaris.vcg.cn/api/service/",
params: {
service_name: self.search_info,
},
responseType: "json",
}).then(function(response) {
console.log(response);
self.tableData = response.data.data;
self.total = response.data.page.totalCount;
self.currentPage = response.data.page.pageNo;
self.pagesize = response.data.page.pageSize;
self.$message({
showClose: true,
message: "共搜索到" + self.total + "条结果",
type: "success",
});
});
},
handleSizeChange(val) {
const self = this;
console.log(val, self.currentPage);
if (self.serviceTreeNodeClicked) {
self.requestnodedata(self.serviceTreeNodeId, val, self.currentPage);
} else {
self.requestdata(val, self.currentPage);
}
},
handleCurrentChange(val) {
const self = this;
console.log(self.pagesize, val);
if (self.serviceTreeNodeClicked) {
self.requestnodedata(this.serviceTreeNodeId, self.pagesize, val);
} else {
self.requestdata(self.pagesize, val);
}
},
requestnodedata(id, pageSize, pageNo) {
// 点击节点后,请求 节点相关的服务
const self = this;
axios({
method: "get",
url: "http://devops.zhaohongye.com/api/v1/service_tree/node_link_service",
params: {
id: id,
page: pageNo,
pageSize: pageSize,
},
responseType: "json",
}).then(function(response) {
var res = response.data.data;
console.log(res);
self.tableData = res.list;
self.total = res.total;
self.currentPage = res.page;
self.pagesize = res.pagesize;
// self.$message({
// showClose: true,
// message: "共搜索到" + self.total + "条结果",
// type: "success",
// });
});
},

requestdata(pageSize, pageNo) {
const self = this;
axios({
method: "get",
url: "http://devops.zhaohongye.com/api/v1/business/service/_list",
params: {
page: pageNo,
pageSize: pageSize,
},
responseType: "json",
}).then(function(response) {
var res = response.data.data;
console.log(res);
self.tableData = res.list;
self.total = res.total;
self.currentPage = res.page;
self.pagesize = res.pagesize;
// self.$message({
// showClose: true,
// message: "共搜索到" + self.total + "条结果",
// type: "success",
// });
});
},
},
};
</script>

<!-- <style>
.el-dropdown-link {
cursor: pointer;
color: #409EFF;
}

.el-icon-arrow-down {
font-size: 12px;
}
</style>
-->

详情页detail.vue
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
<template>
<div>
<!-- <el-container> -->
<!-- <el-card> -->
<h3 style="text-align: left;">基础信息</h3>
<div style="margin-left: 50px">
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">应用名称:{{ data.name }}</el-col>
<el-col :span="12" style="text-align: left;">开发语言:{{ data.language }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">业务线:{{ data.businessLine }}</el-col>
<el-col :span="12" style="text-align: left;">数据来源:{{ data.platform }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">JDK版本:{{ data.jdkVersion }}</el-col>
<el-col :span="12" style="text-align: left;">容器版本:{{ data.webVersion }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">开发负责人:{{ data.developer }}</el-col>
<el-col :span="12" style="text-align: left;">测试负责人:{{ data.tester }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">容器目录:{{ data.webDir }}</el-col>
<el-col :span="12" style="text-align: left;">部署目录:{{ data.codeDir }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">服务等级:{{ data.serviceLevel }}</el-col>
<el-col :span="12" style="text-align: left;">是否自研:{{ data.isIndependentRD }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">Git地址:{{ data.gitUrl }}</el-col>
<el-col :span="12" style="text-align: left;">第三方公司:{{ data.thirdPartyCompany }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">功能描述:{{ data.desc }}</el-col>
<el-col :span="12" style="text-align: left;"></el-col>
</el-row>
</div>
<!-- </el-card>
<el-card> -->
<el-collapse v-model="activeNames" @change="handleChange">
<el-collapse-item title="生产环境" name="1">
<div style="margin-left: 50px">
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">域名:{{ data.domainPro }}</el-col>
<el-col :span="12" style="text-align: left;"></el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">编译参数:{{ data.buildCommandPro }}</el-col>
<el-col :span="12" style="text-align: left;"></el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">启动参数:{{ data.startCommandProtform }}</el-col>
<el-col :span="12" style="text-align: left;">停止参数{{ data.stopCommandPro }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">检测URL:{{ data.healthURLPro }}</el-col>
<el-col :span="12" style="text-align: left;">负载均衡:{{ data.slbPro }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">当前版本:{{ data.webDir }}</el-col>
<el-col :span="12" style="text-align: left;">发布时间:{{ data.codeDir }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="24" style="text-align: left;">公共组件:{{ data.componentPro }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="24" style="text-align: left;">数据库集群:{{ data.dbPro }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="24" style="text-align: left;">
<h4>实例信息</h4>
<el-table :data="ecsPro" border style="width: 60%">
<el-table-column prop="privateIp" label="主机" width="180"></el-table-column>
<el-table-column prop="port" label="端口" width="180"></el-table-column>
<el-table-column prop="cpu" label="CPU"></el-table-column>
<el-table-column prop="mem" label="内存"></el-table-column>
<el-table-column prop="capacity" label="存储"></el-table-column>
<el-table-column prop="platform" label="数据来源"></el-table-column>
<el-table-column prop="computeType" label="类型"></el-table-column>
<el-table-column prop="outIp" label="出口地址"></el-table-column>
</el-table>
</el-col>
</el-row>
</div>
</el-collapse-item>
<el-collapse-item title="预览环境" name="2">
<div style="margin-left: 50px">
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">域名:{{ data.domainPro }}</el-col>
<el-col :span="12" style="text-align: left;"></el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">编译参数:{{ data.buildCommandPro }}</el-col>
<el-col :span="12" style="text-align: left;"></el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">启动参数:{{ data.startCommandProtform }}</el-col>
<el-col :span="12" style="text-align: left;">停止参数{{ data.stopCommandPro }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">检测URL:{{ data.healthURLPro }}</el-col>
<el-col :span="12" style="text-align: left;">负载均衡:{{ data.slbPro }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">当前版本:{{ data.webDir }}</el-col>
<el-col :span="12" style="text-align: left;">发布时间:{{ data.codeDir }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="24" style="text-align: left;">公共组件:{{ data.componentPro }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="24" style="text-align: left;">数据库集群:{{ data.dbPro }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="24" style="text-align: left;">
<h4>实例信息</h4>
<el-table :data="ecsPro" border style="width: 60%">
<el-table-column prop="privateIp" label="主机" width="180"></el-table-column>
<el-table-column prop="port" label="端口" width="180"></el-table-column>
<el-table-column prop="cpu" label="CPU"></el-table-column>
<el-table-column prop="mem" label="内存"></el-table-column>
<el-table-column prop="capacity" label="存储"></el-table-column>
<el-table-column prop="platform" label="数据来源"></el-table-column>
<el-table-column prop="computeType" label="类型"></el-table-column>
<el-table-column prop="outIp" label="出口地址"></el-table-column>
</el-table>
</el-col>
</el-row>
</div>
</el-collapse-item>
<el-collapse-item title="测试环境" name="3">
<div style="margin-left: 50px">
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">域名:{{ data.domainPro }}</el-col>
<el-col :span="12" style="text-align: left;"></el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">编译参数:{{ data.buildCommandPro }}</el-col>
<el-col :span="12" style="text-align: left;"></el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">启动参数:{{ data.startCommandProtform }}</el-col>
<el-col :span="12" style="text-align: left;">停止参数{{ data.stopCommandPro }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">检测URL:{{ data.healthURLPro }}</el-col>
<el-col :span="12" style="text-align: left;">负载均衡:{{ data.slbPro }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">当前版本:{{ data.webDir }}</el-col>
<el-col :span="12" style="text-align: left;">发布时间:{{ data.codeDir }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="24" style="text-align: left;">公共组件:{{ data.componentPro }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="24" style="text-align: left;">数据库集群:{{ data.dbPro }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="24" style="text-align: left;">
<h4>实例信息</h4>
<el-table :data="ecsPro" border style="width: 60%">
<el-table-column prop="privateIp" label="主机" width="180"></el-table-column>
<el-table-column prop="port" label="端口" width="180"></el-table-column>
<el-table-column prop="cpu" label="CPU"></el-table-column>
<el-table-column prop="mem" label="内存"></el-table-column>
<el-table-column prop="capacity" label="存储"></el-table-column>
<el-table-column prop="platform" label="数据来源"></el-table-column>
<el-table-column prop="computeType" label="类型"></el-table-column>
<el-table-column prop="outIp" label="出口地址"></el-table-column>
</el-table>
</el-col>
</el-row>
</div>
</el-collapse-item>
<el-collapse-item title="开发环境" name="4">
<div style="margin-left: 50px">
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">域名:{{ data.domainPro }}</el-col>
<el-col :span="12" style="text-align: left;"></el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">编译参数:{{ data.buildCommandPro }}</el-col>
<el-col :span="12" style="text-align: left;"></el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">启动参数:{{ data.startCommandProtform }}</el-col>
<el-col :span="12" style="text-align: left;">停止参数{{ data.stopCommandPro }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">检测URL:{{ data.healthURLPro }}</el-col>
<el-col :span="12" style="text-align: left;">负载均衡:{{ data.slbPro }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="12" style="text-align: left;">当前版本:{{ data.webDir }}</el-col>
<el-col :span="12" style="text-align: left;">发布时间:{{ data.codeDir }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="24" style="text-align: left;">公共组件:{{ data.componentPro }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="24" style="text-align: left;">数据库集群:{{ data.dbPro }}</el-col>
</el-row>
<el-row type="flex" class="row-bg" justify="center">
<el-col :span="24" style="text-align: left;">
<h4>实例信息</h4>
<el-table :data="ecsPro" border style="width: 60%">
<el-table-column prop="privateIp" label="主机" width="180"></el-table-column>
<el-table-column prop="port" label="端口" width="180"></el-table-column>
<el-table-column prop="cpu" label="CPU"></el-table-column>
<el-table-column prop="mem" label="内存"></el-table-column>
<el-table-column prop="capacity" label="存储"></el-table-column>
<el-table-column prop="platform" label="数据来源"></el-table-column>
<el-table-column prop="computeType" label="类型"></el-table-column>
<el-table-column prop="outIp" label="出口地址"></el-table-column>
</el-table>
</el-col>
</el-row>
</div>
</el-collapse-item>
</el-collapse>
<!-- </el-card> -->

<!-- </el-container> -->
</div>
</template>

<script>
const axios = require("axios").default;
export default {
data() {
return {
data: {},
activeNames: ["1"],
ecsPro: [],
};
},
created() {
this.requestdata();
// this.handtree();
},
methods: {
handleChange(val) {
console.log(val);
},
requestdata() {
const self = this;
axios({
method: "get",
url: "http://devops.zhaohongye.com/api/v1/business/service/_detail",
params: {
id: self.$route.query.id,
},
responseType: "json",
}).then(function(response) {
var res = response.data.data;
console.log(res);
self.data = res;
self.ecsPro = res.ecsPro;
});
},
},
};
</script>

<style>
.el-row {
margin-bottom: 20px;
&:last-child {
margin-bottom: 0;
}
}
.el-col {
border-radius: 4px;
}
.bg-purple-dark {
background: #99a9bf;
}
.bg-purple {
background: #d3dce6;
}
.bg-purple-light {
background: #e5e9f2;
}
.grid-content {
border-radius: 4px;
min-height: 36px;
}
.row-bg {
padding: 10px 0;
/* background-color: #f9fafc; */
}
</style>