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
import axios from "axios";
import store from "../store/state";
import router from "../router";
import { Message } from "element-ui";
 
export let baseUrl = process.env.VUE_APP_BASE_URL;
 
axios.defaults.withCredentials = true;
axios.defaults.baseURL = baseUrl;
 
axios.interceptors.request.use(
    function(config) {
        if (
            !config.url.startsWith("/api/user") ||
            config.url === "/api/user/list" ||
            config.url === "/api/user/login_log"
        ) {
            // 在请求拦截中,每次请求,都会加上一个Authorization头
            config.headers.Authorization = store.token;
 
            // 取url地址的第四位作为projectId, 如果不存在,默认设置为0
            let projectId = window.location.pathname.split("/")[3];
            projectId = projectId ? projectId : 0;
            config.headers["Project"] = projectId;
        }
        return config;
    },
    function(error) {
        return Promise.reject(error);
    }
);
 
axios.interceptors.response.use(
    function(response) {
        return response; // 安全地返回 response
    },
    function(error) {
        if (axios.isCancel(error)) {
            // 请求被取消
            if (error.message !== "User cancelled the request") {
                Message.error({
                    message: "请求超时,请稍后再试",
                    duration: 2000
                });
            }
        } else {
            // 其他错误
            try {
                let status = error.response ? error.response.status : 0;
                if (status === 401) {
                    router.replace({
                        name: "Login"
                    });
                }
                if (status === 500) {
                    Message.error({
                        message: "服务器内部异常, 请检查",
                        duration: 2000
                    });
                }
                if (status === 403) {
                    Message.error({
                        message: error.response.data.detail,
                        duration: 2000
                    });
                }
            } catch (e) {
                Message.error({
                    message: "服务器连接超时, 请重试",
                    duration: 2000
                });
            }
        }
        return Promise.reject(error);
    }
);
 
export const login = params => {
    return axios.post("/api/user/login", params).then(res => res.data);
};
 
export const addProject = params => {
    return axios.post("/api/lunarlink/project", params).then(res => res.data);
};
 
export const updateProject = params => {
    return axios.patch("/api/lunarlink/project", params).then(res => res.data);
};
 
export const deleteProject = config => {
    return axios
        .delete("/api/lunarlink/project", config)
        .then(res => res.data);
};
 
export const getProjectList = () => {
    return axios.get("/api/lunarlink/project").then(res => res.data);
};
 
export const getPagination = url => {
    return axios.get(url).then(res => res.data);
};
 
export const getUserList = () => {
    return axios.get("/api/user/list").then(res => res.data);
};
 
export const getDashboard = () => {
    return axios.get("/api/lunarlink/dashboard").then(res => res.data);
};
 
export const getVisit = params => {
    return axios.get("/api/lunarlink/visit", params).then(res => res.data);
};
 
export const getProjectDetail = pk => {
    return axios.get("/api/lunarlink/project/" + pk).then(res => res.data);
};
 
export const updateTree = (treeId, params) => {
    return axios
        .patch("/api/lunarlink/tree/" + treeId, params)
        .then(res => res.data);
};
 
export const getTree = (projectId, params) => {
    return axios
        .get("/api/lunarlink/tree/" + projectId, params)
        .then(res => res.data.data);
};
 
export const getAllConfig = projectId => {
    return axios
        .get("/api/lunarlink/config/" + projectId)
        .then(res => res.data);
};
 
export const getProjectYapiInfo = pk => {
    return axios
        .get("/api/lunarlink/project/yapi/" + pk)
        .then(res => res.data);
};
 
export const getGroupList = () => {
    return axios
        .get("/api/lunarlink/project/groups")
        .then(res => res.data);
};
 
export const addYAPI = projectId => {
    return axios
        .post("/api/lunarlink/yapi/" + projectId)
        .then(res => res.data);
};
 
export const addAPI = params => {
    return axios.post("/api/lunarlink/api", params).then(res => res.data);
};
 
export const updateAPI = (url, params) => {
    return axios
        .patch("/api/lunarlink/api/" + url, params)
        .then(res => res.data);
};
 
export const apiList = params => {
    return axios.get("/api/lunarlink/api", params).then(res => res.data);
};
 
export const delAllAPI = params => {
    return axios.delete("/api/lunarlink/api", params).then(res => res.data);
};
 
export const tagAPI = params => {
    return axios.patch("/api/lunarlink/api/tag", params).then(res => res.data);
};
 
export const delAPI = apiId => {
    return axios.delete("/api/lunarlink/api/" + apiId).then(res => res.data);
};
 
export const copyAPI = (apiId, params) => {
    return axios
        .post("/api/lunarlink/api/" + apiId, params)
        .then(res => res.data);
};
 
export const syncCaseStep = apiId => {
    return axios
        .patch("/api/lunarlink/api/sync/" + apiId)
        .then(res => res.data);
};
 
export const getAPISingle = apiId => {
    return axios.get("/api/lunarlink/api/" + apiId).then(res => res.data);
};
 
export const moveAPI = params => {
    return axios
        .patch("/api/lunarlink/api/move_api", params)
        .then(res => res.data);
};
 
export const getPaginationByPage = params => {
    return axios.get("/api/lunarlink/api", params).then(res => res.data);
};
 
export const runAPIByPk = (apiId, params, cancelToken) => {
    return axios
        .get("/api/lunarlink/run_api_pk/" + apiId, {
            params: params,
            cancelToken: cancelToken
        })
        .then(res => res.data);
};
 
export const runSingleAPI = params => {
    return axios.post("/api/lunarlink/run_api", params).then(res => res.data);
};
 
// TODO: 上传文件接口需要优化,后端当前不存在此接口
export const uploadFile = url => {
    return baseUrl + "/api/lunarlink/file/?token=" + store.token;
};
 
export const addConfig = params => {
    return axios.post("/api/lunarlink/config", params).then(res => res.data);
};
 
export const updateConfig = (configId, params) => {
    return axios
        .patch("/api/lunarlink/config/" + configId, params)
        .then(res => res.data);
};
 
export const configList = params => {
    return axios.get("/api/lunarlink/config", params).then(res => res.data);
};
 
export const delAllConfig = params => {
    return axios.delete("/api/lunarlink/config", params).then(res => res.data);
};
 
export const delConfig = configId => {
    return axios
        .delete("/api/lunarlink/config/" + configId)
        .then(res => res.data);
};
 
export const copyConfig = (configId, params) => {
    return axios
        .post("/api/lunarlink/config/" + configId, params)
        .then(res => res.data);
};
 
export const getConfigPaginationByPage = params => {
    return axios.get("/api/lunarlink/config", params).then(res => res.data);
};
 
export const delAllTest = params => {
    return axios.delete("/api/lunarlink/test", params).then(res => res.data);
};
 
export const testList = params => {
    return axios.get("/api/lunarlink/test", params).then(res => res.data);
};
 
export const runSuiteTree = params => {
    return axios
        .post("/api/lunarlink/run_suite_tree", params)
        .then(res => res.data);
};
 
export const moveCase = params => {
    return axios
        .patch("/api/lunarlink/test/move_case", params)
        .then(res => res.data);
};
 
export const tagCase = params => {
    return axios
        .patch("/api/lunarlink/test/tag", params)
        .then(res => res.data);
};
 
export const runTestByPk = (testId, params) => {
    return axios
        .get("/api/lunarlink/run_testsuite_pk/" + testId, params)
        .then(res => res.data);
};
 
export const runTestByPkWithCancel = (testId, params, cancelToken) => {
    return axios
        .get("/api/lunarlink/run_testsuite_pk/" + testId, {
            params: params,
            cancelToken: cancelToken
        })
        .then(res => res.data);
};
 
export const getTestPaginationByPage = params => {
    return axios.get("/api/lunarlink/test", params).then(res => res.data);
};
 
export const editTest = testId => {
    return axios
        .get("/api/lunarlink/teststep/" + testId)
        .then(res => res.data);
};
 
export const copyTest = (testId, params) => {
    return axios
        .post("/api/lunarlink/test/" + testId, params)
        .then(res => res.data);
};
 
export const delTest = pk => {
    return axios.delete("/api/lunarlink/test/" + pk).then(res => res.data);
};
 
export const syncTest = testId => {
    return axios.put("/api/lunarlink/test/" + testId).then(res => res.data);
};
 
export const addTestCase = params => {
    return axios.post("/api/lunarlink/test", params).then(res => res.data);
};
 
export const updateTestCase = (testId, params) => {
    return axios
        .patch("/api/lunarlink/test/" + testId, params)
        .then(res => res.data);
};
 
export const runSingleTestSuite = params => {
    return axios
        .post("/api/lunarlink/run_testsuite", params)
        .then(res => res.data);
};
 
export const runSingleTest = params => {
    return axios.post("/api/lunarlink/run_test", params).then(res => res.data);
};
 
export const getAPIPaginationByPage = params => {
    return axios.get("/api/lunarlink/api", params).then(res => res.data);
};
 
export const deleteVariables = variableId => {
    return axios
        .delete("/api/lunarlink/variables/" + variableId)
        .then(res => res.data);
};
 
export const variablesList = params => {
    return axios.get("/api/lunarlink/variables", params).then(res => res.data);
};
 
export const getVariablesPaginationByPage = params => {
    return axios.get("/api/lunarlink/variables", params).then(res => res.data);
};
 
export const delAllVariables = params => {
    return axios
        .delete("/api/lunarlink/variables", params)
        .then(res => res.data);
};
 
export const addVariables = params => {
    return axios
        .post("/api/lunarlink/variables", params)
        .then(res => res.data);
};
 
export const updateVariables = (variablesId, params) => {
    return axios
        .patch("/api/lunarlink/variables/" + variablesId, params)
        .then(res => res.data);
};
 
export const loginLogList = params => {
    return axios.get("/api/user/login_log", params).then(res => res.data);
};
 
export const loginLogPaginationByPage = params => {
    return axios.get("/api/user/login_log", params).then(res => res.data);
};
 
export const runDebugtalk = params => {
    return axios
        .post("/api/lunarlink/debugtalk", params)
        .then(res => res.data);
};
 
export const updateDebugtalk = params => {
    return axios
        .patch("/api/lunarlink/debugtalk", params)
        .then(res => res.data);
};
 
export const getDebugtalk = debugtalkId => {
    return axios
        .get("/api/lunarlink/debugtalk/" + debugtalkId)
        .then(res => res.data);
};
 
export const delTasks = taskId => {
    return axios
        .delete("/api/lunarlink/schedule/" + taskId)
        .then(res => res.data);
};
 
export const taskList = params => {
    return axios.get("/api/lunarlink/schedule", params).then(res => res.data);
};
 
export const patchTask = (taskId, params) => {
    return axios
        .patch("/api/lunarlink/schedule/" + taskId, params)
        .then(res => res.data);
};
 
export const copyTask = (taskId, params) => {
    return axios
        .post("/api/lunarlink/schedule/" + taskId, params)
        .then(res => res.data);
};
 
export const runTask = taskId => {
    return axios
        .get("/api/lunarlink/schedule/" + taskId)
        .then(res => res.data);
};
 
export const getTaskPaginationByPage = params => {
    return axios.get("/api/lunarlink/schedule", params).then(res => res.data);
};
 
export const addTask = params => {
    return axios.post("/api/lunarlink/schedule", params).then(res => res.data);
};
 
export const updateTask = (taskId, data) => {
    return axios({
        method: "put",
        url: "/api/lunarlink/schedule/" + taskId,
        data: data
    }).then(res => res.data);
};
 
export const reportList = params => {
    return axios.get("/api/lunarlink/reports", params).then(res => res.data);
};
 
export const getReportPaginationByPage = params => {
    return axios.get("/api/lunarlink/reports", params).then(res => res.data);
};
 
export const runMultiTest = params => {
    return axios
        .post("/api/lunarlink/run_multi_tests", params)
        .then(res => res.data);
};
 
export const delReports = reportId => {
    return axios
        .delete("/api/lunarlink/reports/" + reportId)
        .then(res => res.data);
};
 
export const delAllReports = params => {
    return axios
        .delete("/api/lunarlink/reports", params)
        .then(res => res.data);
};
 
export const recordStart = params => {
    return axios
        .get("/api/lunarlink/record/start", params)
        .then(res => res.data);
};
 
export const recordStop = params => {
    return axios
        .get("/api/lunarlink/record/stop", params)
        .then(res => res.data);
};
 
export const getRecordStatus = params => {
    return axios
        .get("/api/lunarlink/record/status", params)
        .then(res => res.data);
};
 
export const recordRemove = params => {
    return axios
        .get("/api/lunarlink/record/remove", params)
        .then(res => res.data);
};
 
export const generateTestCase = params => {
    return axios
        .post("/api/lunarlink/record_case", params)
        .then(res => res.data);
};
 
export const getTasksCount = projectId => {
    return axios.get("/api/lunarlink/schedule", {
        params: {
            project: projectId,
            page: 1,
            size: 1000000
        }
    }).then(res => res.data);
};
export const getReportsForProject = (projectId) => {
    return axios.get("/api/lunarlink/reports", {
        params: {
            project: projectId,
            search: "",
            reportType: "",
            reportStatus: 0,  // 0表示失败状态
            page: 1,
            size: 100,
            onlyMe: false
        }
    }).then(res => res.data);
};