提交 | 用户 | 时间
|
850106
|
1 |
<template> |
H |
2 |
<el-dialog |
|
3 |
:title="!dataForm.id ? '新增' : '修改'" |
|
4 |
:close-on-click-modal="false" |
|
5 |
:visible.sync="visible"> |
|
6 |
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="100px"> |
|
7 |
<el-form-item label="API名称" prop="apiName"> |
|
8 |
<el-input v-model="dataForm.apiName" placeholder="API名称"></el-input> |
|
9 |
</el-form-item> |
|
10 |
<el-form-item label="分组名称" prop="apiGroupId"> |
|
11 |
<el-select v-model="dataForm.apiGroupId" placeholder="分组名称" maxlength="36" clearable> |
|
12 |
<el-option |
|
13 |
v-for="item in groupList" |
|
14 |
:key="item.id" |
|
15 |
:label="item.groupName" |
|
16 |
:value="item.id"> |
|
17 |
</el-option> |
|
18 |
</el-select> |
|
19 |
</el-form-item> |
|
20 |
<el-form-item label="服务提供方" prop="apiServerId"> |
|
21 |
<el-select v-model="dataForm.apiServerId" placeholder="分组名称" maxlength="36" clearable> |
|
22 |
<el-option |
|
23 |
v-for="item in serverList" |
|
24 |
:key="item.id" |
|
25 |
:label="item.serverName" |
|
26 |
:value="item.id"> |
|
27 |
</el-option> |
|
28 |
</el-select> |
|
29 |
</el-form-item> |
|
30 |
<el-form-item label="URL" prop="apiAddress"> |
|
31 |
<el-input v-model="dataForm.apiAddress" placeholder="URL"></el-input> |
|
32 |
</el-form-item> |
|
33 |
<el-form-item label="描述" prop="apiDesc"> |
|
34 |
<el-input v-model="dataForm.apiDesc" placeholder="描述"></el-input> |
|
35 |
</el-form-item> |
|
36 |
</el-form> |
|
37 |
<span slot="footer" class="dialog-footer"> |
|
38 |
<el-button @click="visible = false">取消</el-button> |
|
39 |
<el-button :loading="loading" type="primary" @click="dataFormSubmit()">确定</el-button> |
|
40 |
</span> |
|
41 |
</el-dialog> |
|
42 |
</template> |
|
43 |
|
|
44 |
<script> |
|
45 |
export default { |
|
46 |
data () { |
|
47 |
return { |
|
48 |
visible: false, |
|
49 |
loading: false, |
|
50 |
groupList: [], |
|
51 |
serverList: [], |
|
52 |
dataForm: { |
|
53 |
id: '', |
|
54 |
apiName: '', |
|
55 |
apiGroupId: '', |
|
56 |
apiServerId: '', |
|
57 |
apiAddress: '', |
|
58 |
apiDesc: '' |
|
59 |
}, |
|
60 |
dataRule: { |
|
61 |
apiName: [ |
|
62 |
{ required: true, message: 'API名称不能为空', trigger: 'blur' } |
|
63 |
], |
|
64 |
apiGroupId: [ |
|
65 |
{ required: true, message: '分组名称不能为空', trigger: 'blur' } |
|
66 |
], |
|
67 |
apiServerId: [ |
|
68 |
{ required: true, message: '服务提供方不能为空', trigger: 'blur' } |
|
69 |
], |
|
70 |
URL: [ |
|
71 |
{ required: true, message: '服务提供方不能为空', trigger: 'blur' } |
|
72 |
] |
|
73 |
} |
|
74 |
} |
|
75 |
}, |
|
76 |
methods: { |
|
77 |
init (id) { |
|
78 |
this.getGroupList() |
|
79 |
this.getServerList() |
|
80 |
this.dataForm.id = id || 0 |
|
81 |
this.visible = true |
|
82 |
this.$nextTick(() => { |
|
83 |
this.$refs['dataForm'].resetFields() |
|
84 |
if (this.dataForm.id) { |
|
85 |
this.getInfo() |
|
86 |
} |
|
87 |
}) |
|
88 |
}, |
|
89 |
|
|
90 |
// 获取信息 |
|
91 |
getInfo() { |
|
92 |
this.$http.get(`/data/api-gateway/info/info/${this.dataForm.id}`).then(({data: res}) => { |
|
93 |
if (res.code !== 0) { |
|
94 |
return this.$message.error(res.msg) |
|
95 |
} |
|
96 |
this.dataForm = { |
|
97 |
...this.dataForm, |
|
98 |
...res.data |
|
99 |
} |
|
100 |
}).catch(() => { |
|
101 |
}) |
|
102 |
}, |
|
103 |
|
|
104 |
getGroupList () { |
|
105 |
this.$http({ |
|
106 |
url: '/data/api-gateway/group/list', |
|
107 |
method: 'get', |
|
108 |
params: this.$http.adornParams({ |
|
109 |
'page': 1, |
|
110 |
'limit': 100 |
|
111 |
}) |
|
112 |
}).then(({data}) => { |
|
113 |
if (data && data.code === 0) { |
|
114 |
this.groupList = data.page.list |
|
115 |
} else { |
|
116 |
this.groupList = [] |
|
117 |
} |
|
118 |
}) |
|
119 |
}, |
|
120 |
|
|
121 |
getServerList () { |
|
122 |
this.$http({ |
|
123 |
url: '/data/api-gateway/server/list', |
|
124 |
method: 'get', |
|
125 |
params: this.$http.adornParams({ |
|
126 |
'page': 1, |
|
127 |
'limit': 100 |
|
128 |
}) |
|
129 |
}).then(({data}) => { |
|
130 |
if (data && data.code === 0) { |
|
131 |
this.serverList = data.page.list |
|
132 |
} else { |
|
133 |
this.serverList = [] |
|
134 |
} |
|
135 |
}) |
|
136 |
}, |
|
137 |
|
|
138 |
// 表单提交 |
|
139 |
dataFormSubmit () { |
|
140 |
this.$refs['dataForm'].validate((valid) => { |
|
141 |
if (!valid) { |
|
142 |
return false |
|
143 |
} |
|
144 |
this.loading = true |
|
145 |
this.$http['post'](`/data/api-gateway/info/${!this.dataForm.id ? 'add' : 'update'}`, this.dataForm).then(({data: res}) => { |
|
146 |
this.loading = false |
|
147 |
if (res.code !== 0) { |
|
148 |
return this.$message.error(res.msg) |
|
149 |
} |
|
150 |
this.$message({ |
|
151 |
message: this.$t('prompt.success'), |
|
152 |
type: 'success', |
|
153 |
duration: 500, |
|
154 |
onClose: () => { |
|
155 |
this.visible = false |
|
156 |
this.$emit('refreshDataList') |
|
157 |
} |
|
158 |
}) |
|
159 |
}).catch(() => { |
|
160 |
}) |
|
161 |
}) |
|
162 |
} |
|
163 |
} |
|
164 |
} |
|
165 |
</script> |
|
166 |
<style> |
|
167 |
.el-select { |
|
168 |
width:100% |
|
169 |
} |
|
170 |
.el-input-group__append { |
|
171 |
padding: 0 5px 0 5px |
|
172 |
} |
|
173 |
.el-input-group__prepend { |
|
174 |
padding: 0 5px 0 5px |
|
175 |
} |
|
176 |
</style> |