fix: 接口自动化从vuex获取projectId

This commit is contained in:
chenjianxing 2021-03-23 17:26:00 +08:00
parent 0073ed1307
commit 0bd0098b95
8 changed files with 54 additions and 39 deletions

View File

@ -70,7 +70,6 @@
import {getUUID, downloadFile, checkoutTestManagerOrTestUser} from "@/common/js/utils"; import {getUUID, downloadFile, checkoutTestManagerOrTestUser} from "@/common/js/utils";
import MsApiScenarioModule from "@/business/components/api/automation/scenario/ApiScenarioModule"; import MsApiScenarioModule from "@/business/components/api/automation/scenario/ApiScenarioModule";
import MsEditApiScenario from "./scenario/EditApiScenario"; import MsEditApiScenario from "./scenario/EditApiScenario";
import {getCurrentProjectID} from "../../../../common/js/utils";
export default { export default {
name: "ApiAutomation", name: "ApiAutomation",
@ -96,7 +95,10 @@
}, },
isReadOnly() { isReadOnly() {
return !checkoutTestManagerOrTestUser(); return !checkoutTestManagerOrTestUser();
} },
projectId() {
return this.$store.state.projectId
},
}, },
data() { data() {
return { return {
@ -145,7 +147,7 @@
let selectParamArr = redirectParam.split("edit:"); let selectParamArr = redirectParam.split("edit:");
if (selectParamArr.length == 2) { if (selectParamArr.length == 2) {
let scenarioId = selectParamArr[1]; let scenarioId = selectParamArr[1];
let projectId = getCurrentProjectID(); let projectId = this.projectId;
// //
let url = "/api/automation/list/" + 1 + "/" + 1; let url = "/api/automation/list/" + 1 + "/" + 1;
this.$post(url, {id: scenarioId, projectId: projectId}, response => { this.$post(url, {id: scenarioId, projectId: projectId}, response => {
@ -176,7 +178,7 @@
} }
}, },
addTab(tab) { addTab(tab) {
if (!getCurrentProjectID()) { if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip')); this.$warning(this.$t('commons.check_project_tip'));
return; return;
} }

View File

@ -45,7 +45,7 @@
import MsApiReportExport from "./ApiReportExport"; import MsApiReportExport from "./ApiReportExport";
import MsApiReportViewHeader from "./ApiReportViewHeader"; import MsApiReportViewHeader from "./ApiReportViewHeader";
import {RequestFactory} from "../../definition/model/ApiTestModel"; import {RequestFactory} from "../../definition/model/ApiTestModel";
import {windowPrint, getCurrentProjectID} from "@/common/js/utils"; import {windowPrint} from "@/common/js/utils";
export default { export default {
name: "MsApiReport", name: "MsApiReport",
@ -211,7 +211,7 @@
return; return;
} }
this.loading = true; this.loading = true;
this.report.projectId = getCurrentProjectID(); this.report.projectId = this.projectId;
let url = "/api/scenario/report/update"; let url = "/api/scenario/report/update";
this.result = this.$post(url, this.report, response => { this.result = this.$post(url, this.report, response => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
@ -236,7 +236,10 @@
}, },
isNotRunning() { isNotRunning() {
return "Running" !== this.report.status; return "Running" !== this.report.status;
} },
projectId() {
return this.$store.state.projectId
},
} }
} }
</script> </script>

View File

@ -58,7 +58,7 @@
<script> <script>
import {WORKSPACE_ID} from '@/common/js/constants'; import {WORKSPACE_ID} from '@/common/js/constants';
import {getCurrentUser, getUUID, getCurrentProjectID} from "@/common/js/utils"; import {getCurrentUser, getUUID} from "@/common/js/utils";
import MsDialogFooter from "@/business/components/common/components/MsDialogFooter"; import MsDialogFooter from "@/business/components/common/components/MsDialogFooter";
export default { export default {
@ -84,6 +84,11 @@
}, },
} }
}, },
computed: {
projectId() {
return this.$store.state.projectId
},
},
methods: { methods: {
saveScenario(saveAs) { saveScenario(saveAs) {
this.$refs['scenarioForm'].validate((valid) => { this.$refs['scenarioForm'].validate((valid) => {
@ -105,7 +110,7 @@
}) })
}, },
setParameter() { setParameter() {
this.scenarioForm.projectId = getCurrentProjectID(); this.scenarioForm.projectId = this.projectId;
this.scenarioForm.id = getUUID().substring(0, 8); this.scenarioForm.id = getUUID().substring(0, 8);
this.scenarioForm.protocol = this.currentProtocol; this.scenarioForm.protocol = this.currentProtocol;

View File

@ -164,7 +164,7 @@
import MsTablePagination from "@/business/components/common/pagination/TablePagination"; import MsTablePagination from "@/business/components/common/pagination/TablePagination";
import ShowMoreBtn from "@/business/components/track/case/components/ShowMoreBtn"; import ShowMoreBtn from "@/business/components/track/case/components/ShowMoreBtn";
import MsTag from "../../../common/components/MsTag"; import MsTag from "../../../common/components/MsTag";
import {downloadFile, getCurrentProjectID, getCurrentUser, getUUID, strMapToObj} from "@/common/js/utils"; import {downloadFile, getUUID, strMapToObj} from "@/common/js/utils";
import MsApiReportDetail from "../report/ApiReportDetail"; import MsApiReportDetail from "../report/ApiReportDetail";
import MsTableMoreBtn from "./TableMoreBtn"; import MsTableMoreBtn from "./TableMoreBtn";
import MsScenarioExtendButtons from "@/business/components/api/automation/scenario/ScenarioExtendBtns"; import MsScenarioExtendButtons from "@/business/components/api/automation/scenario/ScenarioExtendBtns";
@ -264,7 +264,6 @@
infoDb: false, infoDb: false,
runVisible: false, runVisible: false,
planVisible: false, planVisible: false,
projectId: "",
runData: [], runData: [],
report: {}, report: {},
selectDataSize: 0, selectDataSize: 0,
@ -338,7 +337,6 @@
}, },
created() { created() {
this.condition.filters = {status: ["Prepare", "Underway", "Completed"]}; this.condition.filters = {status: ["Prepare", "Underway", "Completed"]};
this.projectId = getCurrentProjectID();
this.search(); this.search();
this.getPrincipalOptions([]); this.getPrincipalOptions([]);
}, },
@ -363,7 +361,10 @@
computed: { computed: {
isNotRunning() { isNotRunning() {
return "Running" !== this.report.status; return "Running" !== this.report.status;
} },
projectId() {
return this.$store.state.projectId
},
}, },
methods: { methods: {
customHeader() { customHeader() {
@ -559,7 +560,7 @@
}, },
buildBatchParam(param) { buildBatchParam(param) {
param.ids = Array.from(this.selectRows).map(row => row.id); param.ids = Array.from(this.selectRows).map(row => row.id);
param.projectId = getCurrentProjectID(); param.projectId = this.projectId;
param.condition = this.condition; param.condition = this.condition;
}, },
handleBatchExecute() { handleBatchExecute() {
@ -640,7 +641,7 @@
let scenarioIds = []; let scenarioIds = [];
scenarioIds.push(row.id); scenarioIds.push(row.id);
run.id = getUUID(); run.id = getUUID();
run.projectId = getCurrentProjectID(); run.projectId = this.projectId;
run.ids = scenarioIds; run.ids = scenarioIds;
this.$post(url, run, response => { this.$post(url, run, response => {
let data = response.data; let data = response.data;

View File

@ -59,7 +59,6 @@
<script> <script>
import SelectMenu from "../../../track/common/SelectMenu"; import SelectMenu from "../../../track/common/SelectMenu";
import MsAddBasisScenario from "@/business/components/api/automation/scenario/AddBasisScenario"; import MsAddBasisScenario from "@/business/components/api/automation/scenario/AddBasisScenario";
import {getCurrentProjectID} from "@/common/js/utils";
import MsNodeTree from "../../../track/common/NodeTree"; import MsNodeTree from "../../../track/common/NodeTree";
import {buildNodePath} from "../../definition/model/NodeTree"; import {buildNodePath} from "../../definition/model/NodeTree";
import ModuleTrashButton from "../../definition/components/module/ModuleTrashButton"; import ModuleTrashButton from "../../definition/components/module/ModuleTrashButton";
@ -90,7 +89,10 @@
}, },
isRelevanceModel() { isRelevanceModel() {
return this.relevanceProjectId ? true : false; return this.relevanceProjectId ? true : false;
} },
projectId() {
return this.$store.state.projectId
},
}, },
data() { data() {
return { return {
@ -99,14 +101,12 @@
filterText: "", filterText: "",
trashEnable: false trashEnable: false
}, },
projectId: "",
data: [], data: [],
currentModule: undefined, currentModule: undefined,
moduleOptions: [], moduleOptions: [],
} }
}, },
mounted() { mounted() {
this.projectId = getCurrentProjectID();
this.list(); this.list();
}, },
watch: { watch: {
@ -130,7 +130,7 @@
this.addScenario(); this.addScenario();
break; break;
case "import": case "import":
this.result = this.$get("/api/automation/module/list/" + getCurrentProjectID(), response => { this.result = this.$get("/api/automation/module/list/" + this.projectId, response => {
if (response.data != undefined && response.data != null) { if (response.data != undefined && response.data != null) {
this.data = response.data; this.data = response.data;
let moduleOptions = []; let moduleOptions = [];
@ -238,7 +238,7 @@
this.$emit("refreshTable"); this.$emit("refreshTable");
}, },
addScenario() { addScenario() {
if (!getCurrentProjectID()) { if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip')); this.$warning(this.$t('commons.check_project_tip'));
return; return;
} }

View File

@ -222,7 +222,7 @@
import {parseEnvironment} from "../../definition/model/EnvironmentModel"; import {parseEnvironment} from "../../definition/model/EnvironmentModel";
import {ELEMENT_TYPE, ELEMENTS} from "./Setting"; import {ELEMENT_TYPE, ELEMENTS} from "./Setting";
import MsApiCustomize from "./ApiCustomize"; import MsApiCustomize from "./ApiCustomize";
import {getCurrentProjectID, getUUID, objToStrMap, strMapToObj, handleCtrlSEvent} from "@/common/js/utils"; import {getUUID, objToStrMap, strMapToObj, handleCtrlSEvent} from "@/common/js/utils";
import ApiEnvironmentConfig from "../../definition/components/environment/ApiEnvironmentConfig"; import ApiEnvironmentConfig from "../../definition/components/environment/ApiEnvironmentConfig";
import MsInputTag from "./MsInputTag"; import MsInputTag from "./MsInputTag";
import MsRun from "./DebugRun"; import MsRun from "./DebugRun";
@ -300,7 +300,6 @@
path: "/api/automation/create", path: "/api/automation/create",
debugData: {}, debugData: {},
reportId: "", reportId: "",
projectId: "",
enableCookieShare: false, enableCookieShare: false,
globalOptions: { globalOptions: {
spacing: 30 spacing: 30
@ -317,7 +316,6 @@
if (!this.currentScenario.apiScenarioModuleId) { if (!this.currentScenario.apiScenarioModuleId) {
this.currentScenario.apiScenarioModuleId = ""; this.currentScenario.apiScenarioModuleId = "";
} }
this.projectId = getCurrentProjectID();
this.operatingElements = ELEMENTS.get("ALL"); this.operatingElements = ELEMENTS.get("ALL");
this.getWsProjects(); this.getWsProjects();
this.getMaintainerOptions(); this.getMaintainerOptions();
@ -438,7 +436,10 @@
} }
]; ];
return buttons.filter(btn => btn.show); return buttons.filter(btn => btn.show);
} },
projectId() {
return this.$store.state.projectId
},
}, },
methods: { methods: {
// //
@ -574,7 +575,7 @@
arr[i].countController.proceed = true; arr[i].countController.proceed = true;
} }
if (!arr[i].projectId) { if (!arr[i].projectId) {
arr[i].projectId = getCurrentProjectID(); arr[i].projectId = this.projectId;
} }
if (arr[i].hashTree != undefined && arr[i].hashTree.length > 0) { if (arr[i].hashTree != undefined && arr[i].hashTree.length > 0) {
this.recursiveSorting(arr[i].hashTree); this.recursiveSorting(arr[i].hashTree);
@ -596,7 +597,7 @@
} }
// ID // ID
if (!this.scenarioDefinition[i].projectId) { if (!this.scenarioDefinition[i].projectId) {
this.scenarioDefinition[i].projectId = getCurrentProjectID(); this.scenarioDefinition[i].projectId = this.projectId;
} }
if (this.scenarioDefinition[i].hashTree != undefined && this.scenarioDefinition[i].hashTree.length > 0) { if (this.scenarioDefinition[i].hashTree != undefined && this.scenarioDefinition[i].hashTree.length > 0) {
this.recursiveSorting(this.scenarioDefinition[i].hashTree); this.recursiveSorting(this.scenarioDefinition[i].hashTree);
@ -957,7 +958,7 @@
this.projectEnvMap = objToStrMap(obj.environmentMap); this.projectEnvMap = objToStrMap(obj.environmentMap);
} else { } else {
// //
this.projectEnvMap.set(getCurrentProjectID(), obj.environmentId); this.projectEnvMap.set(this.projectId, obj.environmentId);
} }
this.currentScenario.variables = []; this.currentScenario.variables = [];
let index = 1; let index = 1;
@ -994,7 +995,7 @@
}, },
setParameter() { setParameter() {
this.currentScenario.stepTotal = this.scenarioDefinition.length; this.currentScenario.stepTotal = this.scenarioDefinition.length;
this.currentScenario.projectId = getCurrentProjectID(); this.currentScenario.projectId = this.projectId;
this.currentScenario.modulePath = this.getPath(this.currentScenario.apiScenarioModuleId); this.currentScenario.modulePath = this.getPath(this.currentScenario.apiScenarioModuleId);
// 便 // 便
let scenario = { let scenario = {

View File

@ -69,8 +69,7 @@
<script> <script>
import MsDialogFooter from "../../../../common/components/MsDialogFooter"; import MsDialogFooter from "../../../../common/components/MsDialogFooter";
import {listenGoBack, removeGoBackListener, getCurrentProjectID} from "@/common/js/utils"; import {listenGoBack, removeGoBackListener} from "@/common/js/utils";
import {buildNodePath} from "@/business/components/api/definition/model/NodeTree";
export default { export default {
name: "ScenarioImport", name: "ScenarioImport",
@ -161,6 +160,9 @@
isHar() { isHar() {
return this.selectedPlatformValue === 'Har'; return this.selectedPlatformValue === 'Har';
}, },
projectId() {
return this.$store.state.projectId
},
}, },
methods: { methods: {
scheduleEdit() { scheduleEdit() {
@ -241,7 +243,7 @@
}) })
param.modeId = this.formData.modeId param.modeId = this.formData.modeId
} }
param.projectId = getCurrentProjectID(); param.projectId = this.projectId;
if (!this.swaggerUrlEable) { if (!this.swaggerUrlEable) {
param.swaggerUrl = undefined; param.swaggerUrl = undefined;
} }

View File

@ -135,7 +135,7 @@
import {parseEnvironment} from "../../../definition/model/EnvironmentModel"; import {parseEnvironment} from "../../../definition/model/EnvironmentModel";
import {ELEMENT_TYPE, ELEMENTS} from "../Setting"; import {ELEMENT_TYPE, ELEMENTS} from "../Setting";
import MsApiCustomize from "../ApiCustomize"; import MsApiCustomize from "../ApiCustomize";
import {getCurrentProjectID, getUUID, objToStrMap, strMapToObj} from "@/common/js/utils"; import {getUUID, strMapToObj} from "@/common/js/utils";
import ApiEnvironmentConfig from "../../../definition/components/environment/ApiEnvironmentConfig"; import ApiEnvironmentConfig from "../../../definition/components/environment/ApiEnvironmentConfig";
import MsInputTag from "../MsInputTag"; import MsInputTag from "../MsInputTag";
import MsRun from "../DebugRun"; import MsRun from "../DebugRun";
@ -215,7 +215,6 @@
path: "/api/automation/create", path: "/api/automation/create",
debugData: {}, debugData: {},
reportId: "", reportId: "",
projectId: "",
enableCookieShare: false, enableCookieShare: false,
globalOptions: { globalOptions: {
spacing: 30 spacing: 30
@ -231,7 +230,6 @@
if (!this.currentScenario.apiScenarioModuleId) { if (!this.currentScenario.apiScenarioModuleId) {
this.currentScenario.apiScenarioModuleId = ""; this.currentScenario.apiScenarioModuleId = "";
} }
this.projectId = getCurrentProjectID();
this.operatingElements = ELEMENTS.get("ALL"); this.operatingElements = ELEMENTS.get("ALL");
this.projectEnvMap = this.envMap; this.projectEnvMap = this.envMap;
}, },
@ -354,7 +352,10 @@
} }
]; ];
return buttons.filter(btn => btn.show); return buttons.filter(btn => btn.show);
} },
projectId() {
return this.$store.state.projectId
},
}, },
methods: { methods: {
// //
@ -496,7 +497,7 @@
arr[i].countController.proceed = true; arr[i].countController.proceed = true;
} }
if (!arr[i].projectId) { if (!arr[i].projectId) {
arr[i].projectId = getCurrentProjectID(); arr[i].projectId = this.projectId;
} }
if (arr[i].hashTree != undefined && arr[i].hashTree.length > 0) { if (arr[i].hashTree != undefined && arr[i].hashTree.length > 0) {
this.recursiveSorting(arr[i].hashTree); this.recursiveSorting(arr[i].hashTree);
@ -518,7 +519,7 @@
} }
// ID // ID
if (!this.scenarioDefinition[i].projectId) { if (!this.scenarioDefinition[i].projectId) {
this.scenarioDefinition[i].projectId = getCurrentProjectID(); this.scenarioDefinition[i].projectId = this.projectId;
} }
if (this.scenarioDefinition[i].hashTree != undefined && this.scenarioDefinition[i].hashTree.length > 0) { if (this.scenarioDefinition[i].hashTree != undefined && this.scenarioDefinition[i].hashTree.length > 0) {
this.recursiveSorting(this.scenarioDefinition[i].hashTree); this.recursiveSorting(this.scenarioDefinition[i].hashTree);
@ -858,7 +859,7 @@
setParameter() { setParameter() {
this.currentScenario.stepTotal = this.scenarioDefinition.length; this.currentScenario.stepTotal = this.scenarioDefinition.length;
this.currentScenario.projectId = getCurrentProjectID(); this.currentScenario.projectId = this.projectId;
this.currentScenario.modulePath = this.getPath(this.currentScenario.apiScenarioModuleId); this.currentScenario.modulePath = this.getPath(this.currentScenario.apiScenarioModuleId);
// 便 // 便
let scenario = { let scenario = {