houzhongjian
2024-07-23 8501060c4f921d1e744c477e4dc08eb47b52693c
提交 | 用户 | 时间
850106 1 <template>
H 2   <el-card shadow="never" class="aui-card--fill">
3     <div class="mod-http-api">
4       <el-form
5           :inline="true"
6           :model="dataForm"
7           @keyup.enter.native="getDataList()"
8       >
9         <el-form-item>
10           <el-input
11               v-model="dataForm.name"
12               placeholder="应用接口名称"
13               clearable
14           ></el-input>
15         </el-form-item>
16         <el-form-item>
17           <el-button @click="getDataList()">{{ $t("query") }}</el-button>
18         </el-form-item>
19         <el-form-item>
20           <el-button
21               type="primary"
22               @click="addOrUpdateHandle()"
23           >新增
24           </el-button>
25         </el-form-item>
26       </el-form>
27       <el-table
28           v-loading="dataListLoading"
29           :data="dataList"
30           border
31           style="width: 100%"
32       >
33         <el-table-column
34             prop="name"
35             label="接口名称"
36             header-align="center"
37             align="left"
38             min-width="100"
39         >
40         </el-table-column>
41         <el-table-column
42             prop="code"
43             label="接口代码"
44             header-align="center"
45             align="left"
46             min-width="100"
47         ></el-table-column>
48         <el-table-column
49             prop="url"
50             label="接口地址"
51             header-align="center"
52             align="left"
53             min-width="240"
54         ></el-table-column>
55         <el-table-column
56             prop="method"
57             label="方法类型"
58             header-align="center"
59             align="center"
60             min-width="60"
61         ></el-table-column>
62         <el-table-column
63             prop="collectType"
64             label="采集器类型"
65             header-align="center"
66             align="center"
67             min-width="60"
68         ></el-table-column>
69         <el-table-column
70             prop="param"
71             label="参数"
72             header-align="center"
73             align="center"
74         ></el-table-column>
75         <el-table-column
76             prop="descp"
77             label="描述"
78             header-align="center"
79             align="left"
80             min-width="100"
81         ></el-table-column>
82         <el-table-column
83             :label="$t('handle')"
84             fixed="right"
85             header-align="center"
86             align="center"
87             width="160"
88         >
89           <template slot-scope="scope">
90             <el-button
91                 type="text"
92                 size="small"
93                 @click="addOrUpdateHandle(scope.row.id)"
94             >{{ $t("update") }}
95             </el-button>
96             <el-button
97                 type="text"
98                 size="small"
99                 @click="deleteHandle(scope.row.id)"
100             >{{ $t("delete") }}
101             </el-button>
102             <el-button
103                 type="text"
104                 size="small"
105                 @click="tokenViewHandle(scope.row.id)"
106             >token
107             </el-button>
108             <el-button
109                 type="text"
110                 size="small"
111                 @click="tagItemHandle(scope.row.name, scope.row.code)"
112             >Tag
113             </el-button>
114           </template>
115         </el-table-column>
116       </el-table>
117       <el-pagination
118           @size-change="sizeChangeHandle"
119           @current-change="currentChangeHandle"
120           :current-page="pageIndex"
121           :page-sizes="[10, 20, 50, 100]"
122           :page-size="pageSize"
123           :total="totalPage"
124           layout="total, sizes, prev, pager, next, jumper"
125       >
126       </el-pagination>
127       <!-- 弹窗, 新增 / 修改 -->
128       <add-or-update
129           v-if="addOrUpdateVisible"
130           ref="addOrUpdate"
131           @refreshDataList="getDataList"
132       ></add-or-update>
133       <!-- 弹窗, tag -->
134       <tag-item
135           v-if="tagItemVisible"
136           ref="tagItem"
137           @refreshDataList="getDataList"
138       ></tag-item>
139     </div>
140   </el-card>
141 </template>
142 <script>
143   import AddOrUpdate from "./api-add-or-update";
144   import TokenView from "./token-view";
145   import TagItem from "./tags/tag.vue";
146
147   export default {
148     data() {
149       return {
150         dataForm: {
151           id: "",
152           name: "",
153           address: "",
154           port: "",
155           connectInactivityTimeout: "",
156           reconnectInterval: "",
157           attemptsBeforeTimeout: "",
158           waitToRetryMilliseconds: "",
159           readTimeout: "",
160           writeTimeout: "",
161           useOptimizedBlockRead: "",
162           projectReference: "",
163         },
164         tagItemVisibleXst: false,
165         tagItemVisibleEleLow: false,
166         tagItemVisibleFxjy: false,
167         tagItemVisibleYearPei: false,
168         tagItemVisibleCurrentPerformance: false,
169         tagItemVisibleCurrentSale: false,
170         tagItemVisible: false,
171         dataList: [],
172         pageIndex: 1,
173         pageSize: 10,
174         totalPage: 0,
175         dataListLoading: false,
176         dataListSelections: [],
177         addOrUpdateVisible: false,
178         tokenViewVisible: false,
179       };
180     },
181
182     components: {
183       AddOrUpdate,
184       TokenView,
185       TagItem
186     },
187     mounted() {
188       this.getDataList();
189     },
190     methods: {
191       // 获取数据列表
192       getDataList() {
193         this.dataListLoading = true;
194         this.$http({
195           url: "/data/http/api/page",
196           method: "get",
197           params: this.$http.adornParams({
198             page: this.pageIndex,
199             limit: this.pageSize,
200             name: this.dataForm.name,
201           }),
202         }).then(({code, data}) => {
203           if (data && code === 0) {
204             this.dataList = data.list;
205             this.totalPage = data.total;
206           } else {
207             this.dataList = [];
208             this.totalPage = 0;
209           }
210           this.dataListLoading = false;
211         });
212       },
213       // 每页数
214       sizeChangeHandle(val) {
215         this.pageSize = val;
216         this.pageIndex = 1;
217         this.getDataList();
218       },
219       // 当前页
220       currentChangeHandle(val) {
221         this.pageIndex = val;
222         this.getDataList();
223       },
224       // 新增 / 修改
225       addOrUpdateHandle(id) {
226         this.addOrUpdateVisible = true;
227         this.$nextTick(() => {
228           this.$refs.addOrUpdate.init(id);
229         });
230       },
231
232       // 查看token
233       tokenViewHandle(id) {
234         this.tokenViewVisible = true;
235         this.$nextTick(() => {
236           this.$refs.tokenView.init(id);
237         });
238       },
239
240       //  tag方法
241       tagItemHandle(name, code) {
242           this.tagItemVisible = true;
243           this.$nextTick(() => {
244             this.$refs.tagItem.init(name, code);
245           });
246       },
247
248       // 删除
249       deleteHandle(id) {
250         this.$confirm(`确定对选中项进行删除操作?`, "提示", {
251           confirmButtonText: "确定",
252           cancelButtonText: "取消",
253           type: "warning",
254         })
255           .then(() => {
256             this.$http({
257               headers: {
258                 "Content-Type": "application/json",
259               },
260               url: `/data/http/api/delete`,
261               method: "post",
262               data: this.$http.adornData({
263                 id: id,
264               }),
265             }).then(({code, data, msg}) => {
266               if (data && code === 0) {
267                 this.$message({
268                   message: "操作成功",
269                   type: "success",
270                   duration: 1500,
271                   onClose: () => {
272                     this.getDataList();
273                   },
274                 });
275               } else {
276                 this.$message.error(msg);
277               }
278             });
279           })
280           .catch(() => {
281           });
282       }
283     },
284   };
285 </script>