Skip to content

Commit

Permalink
feat: 新增tab相关全局事件
Browse files Browse the repository at this point in the history
  • Loading branch information
shuxiaokai3 committed Aug 30, 2022
1 parent 6f0b8ee commit 5aced9d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/renderer/helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const emitter = mitt<{
"apidoc/tabs/addOrDeleteTab": void,
"apidoc/getBaseInfo": ApidocProjectBaseInfoState,
"searchItem/change": string,
"tabs/saveTabSuccess": void,
"tabs/saveTabError": void,
"tabs/cancelSaveTab": void,
}>()

export const event = emitter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { TreeNodeOptions } from "element-plus/es/components/tree/src/tree.type";
import { router } from "@/router";
import { axios } from "@/api/api"
import { store } from "@/store";
import { event } from "@/helper";
type FormInfo = {
name: string, //接口名称
Expand Down Expand Up @@ -106,6 +107,7 @@ onMounted(() => {
})
const handleClose = () => {
emit("update:modelValue", false)
event.emit("tabs/cancelSaveTab")
}
const handleSaveDoc = () => {
const docInfo = JSON.parse(JSON.stringify(store.state["apidoc/apidoc"].apidoc))
Expand All @@ -123,12 +125,12 @@ const handleSaveDoc = () => {
store.commit("apidoc/apidoc/changeApidocId", res.data);
store.commit("apidoc/apidoc/changeApidocName", formInfo.value.name);
store.commit("apidoc/tabs/changeTabInfoById", {
id: docInfo._id,
id: store.state["apidoc/apidoc"].savedDocId,
field: "label",
value: formInfo.value.name,
})
store.commit("apidoc/tabs/changeTabInfoById", {
id: docInfo._id,
id: store.state["apidoc/apidoc"].savedDocId,
field: "_id",
value: res.data,
})
Expand All @@ -138,10 +140,12 @@ const handleSaveDoc = () => {
field: "saved",
value: true,
})
event.emit("tabs/saveTabSuccess")
})
emit("update:modelValue", false)
}).catch((err) => {
console.error(err);
event.emit("tabs/saveTabError")
}).finally(() => {
loading.value = false;
});
Expand Down

0 comments on commit 5aced9d

Please sign in to comment.