Skip to content

Commit

Permalink
feat: 更新保存接口弹窗功能
Browse files Browse the repository at this point in the history
  • Loading branch information
shuxiaokai3 committed Aug 30, 2022
1 parent 5aced9d commit 98590b9
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/@types/store.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ type ApidocState = {
loading: boolean,
saveLoading: boolean,
saveDocDialogVisible: boolean,
savedDocId: string,
}

type ApidocResponseState = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ export default defineComponent({
if (!this.currentSelectTab) {
return
}
if (this.currentSelectTab._id?.startsWith("local_")) {
this.$store.commit("apidoc/apidoc/changeApidoc", this.$helper.apidocGenerateApidoc(this.currentSelectTab._id));
this.$store.commit("apidoc/apidoc/changeOriginApidoc")
return
}
if (this.currentSelectTab.saved) { //取最新值
if (this.currentSelectTab._id?.startsWith("local_")) {
this.$store.commit("apidoc/apidoc/changeApidoc", this.$helper.apidocGenerateApidoc(this.currentSelectTab._id));
this.$store.commit("apidoc/apidoc/changeOriginApidoc")
return
}
this.$store.dispatch("apidoc/apidoc/getApidocDetail", {
id: this.currentSelectTab?._id,
projectId: this.$route.query.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ const saveDocDialogVisible = computed({
},
set(val) {
store.commit("apidoc/apidoc/changeSaveDocDialogVisible", val)
store.commit("apidoc/apidoc/changeSavedDocId", currentSelectTab.value?._id);
}
});
const operationPart = getOperationPart();
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/pages/modules/apidoc/doc-edit/doc-edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const saveDocDialogVisible = computed({
return store.state["apidoc/apidoc"].saveDocDialogVisible;
},
set(val) {
store.commit("apidoc/apidoc/changeSaveDocDialogVisible", val)
store.commit("apidoc/apidoc/changeSaveDocDialogVisible", val);
store.commit("apidoc/apidoc/changeSavedDocId", currentSelectTab.value?._id);
}
});
//=====================================绑定快捷键====================================//
Expand Down
35 changes: 30 additions & 5 deletions src/renderer/store/apidoc/apidoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { ApidocDetail, Response, ApidocProperty, ApidocBodyMode, ApidocHttp
import { axios as axiosInstance } from "@/api/api"
import { router } from "@/router/index"
import { store } from "@/store/index"
import { apidocGenerateProperty, apidocGenerateApidoc, apidocGenerateMockInfo, cloneDeep, forEachForest, uuid, apidocConvertParamsToJsonStr } from "@/helper/index"
import { apidocGenerateProperty, apidocGenerateApidoc, apidocGenerateMockInfo, cloneDeep, forEachForest, uuid, apidocConvertParamsToJsonStr, event } from "@/helper/index"
import shareRouter from "@/pages/modules/apidoc/doc-view/router/index"
import { apidocCache } from "@/cache/apidoc"
import config from "@/../config/config"
Expand Down Expand Up @@ -122,6 +122,10 @@ const apidoc = {
* 保存接口弹窗是否展示
*/
saveDocDialogVisible: false,
/**
* 需要保存接口的id
*/
savedDocId: ""
},
mutations: {
/*
Expand Down Expand Up @@ -364,10 +368,6 @@ const apidoc = {
changeApidocSaveLoading(state: ApidocState, loading: boolean): void {
state.saveLoading = loading;
},
//改变保存apidoc弹窗状态
changeSaveDocDialogVisible(state: ApidocState, visible: boolean): void {
state.saveDocDialogVisible = visible;
},
//添加一个请求参数数据
addProperty(state: ApidocState, payload: { data: ApidocProperty[], params: ApidocProperty }): void {
payload.data.push(payload.params);
Expand All @@ -385,6 +385,14 @@ const apidoc = {
changeRequestJsonBody(state: ApidocState, payload: ApidocProperty[]): void {
state.apidoc.item.requestBody.json = payload;
},
//保存接口弹窗是否展示
changeSaveDocDialogVisible(state: ApidocState, visible: boolean): void {
state.saveDocDialogVisible = visible;
},
//改变当前需要保存的节点id
changeSavedDocId(state: ApidocState, id: string): void {
state.savedDocId = id;
},
/*
|--------------------------------------------------------------------------
| 预请求脚本
Expand Down Expand Up @@ -601,6 +609,23 @@ const apidoc = {
console.error(err);
});
},
//改变保存apidoc弹窗状态
openSaveDocDialog(context: ActionContext<ApidocState, RootState>, id: string): Promise<"save" | "cancel"> {
context.commit("changeSaveDocDialogVisible", true)
context.commit("changeSavedDocId", id)
return new Promise((resolve, reject) => {
try {
event.on("tabs/saveTabSuccess", () => {
resolve("save");
})
event.on("tabs/cancelSaveTab", () => {
resolve("cancel");
})
} catch (error) {
reject(error)
}
})
},
},
}

Expand Down
50 changes: 29 additions & 21 deletions src/renderer/store/apidoc/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,29 +179,37 @@ const storeTabs = {
continue;
}
if (apidoc._id.includes("local_")) {
store.commit("apidoc/apidoc/changeSaveDocDialogVisible", true)
console.log(12367)
return
}
const params = {
_id: apidoc._id,
projectId,
info: apidoc.info,
item: apidoc.item,
preRequest: apidoc.preRequest,
afterRequest: apidoc.afterRequest,
mockInfo: apidoc.mockInfo,
};
axios.post("/api/project/fill_doc", params).then(() => {
const deleteIndex = context.state.tabs[projectId].findIndex((tab) => tab._id === apidoc._id);
context.commit("deleteTabByIndex", {
// eslint-disable-next-line no-await-in-loop
const result = await store.dispatch("apidoc/apidoc/openSaveDocDialog", apidoc._id);
if (result === "save") {
context.commit("deleteTabByIndex", {
projectId,
deleteIndex,
});
checkSeletedTab();
}
} else {
const params = {
_id: apidoc._id,
projectId,
deleteIndex,
});
checkSeletedTab();
}).catch((err) => {
console.error(err);
})
info: apidoc.info,
item: apidoc.item,
preRequest: apidoc.preRequest,
afterRequest: apidoc.afterRequest,
mockInfo: apidoc.mockInfo,
};
axios.post("/api/project/fill_doc", params).then(() => {
const deleteIndex = context.state.tabs[projectId].findIndex((tab) => tab._id === apidoc._id);
context.commit("deleteTabByIndex", {
projectId,
deleteIndex,
});
checkSeletedTab();
}).catch((err) => {
console.error(err);
})
}
} catch (error) {
if (error === "close") {
return;
Expand Down

0 comments on commit 98590b9

Please sign in to comment.