Skip to content

Commit 4e1b42d

Browse files
committed
feat: add close
1 parent 9374d7a commit 4e1b42d

File tree

2 files changed

+68
-17
lines changed

2 files changed

+68
-17
lines changed

src/components/common/Message/instance.ts

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type {
66
Options,
77
InstanceComponent,
88
InstanceOptions,
9-
InstanceHandle,
109
} from "./type";
1110

1211
const isServer = typeof window === "undefined";
@@ -61,7 +60,7 @@ const Message: MessageInstance = (opts: InstanceOptions) => {
6160
close: () => {
6261
(vm.component?.proxy as InstanceComponent).visible = false;
6362
},
64-
} as InstanceHandle;
63+
} as any;
6564
};
6665

6766
Message.closeAll = () => {
@@ -71,20 +70,71 @@ Message.closeAll = () => {
7170
}
7271
};
7372

74-
(["success", "warn", "info", "error"] as const).forEach(type => {
75-
Message[type] = (options: InstanceOptions) => {
76-
if (typeof options === "string") {
77-
options = {
78-
content: options,
79-
type,
80-
};
81-
} else {
82-
options.type = type;
83-
}
84-
return Message(options);
85-
};
86-
});
73+
// (["success", "warn", "info", "error"] as const).forEach(type => {
74+
// Message[type] = (options: InstanceOptions) => {
75+
// if (typeof options === "string") {
76+
// options = {
77+
// content: options,
78+
// type,
79+
// };
80+
// } else {
81+
// options.type = type;
82+
// }
83+
// return Message(options);
84+
// };
85+
// });
86+
87+
Message.warn = (options: InstanceOptions) => {
88+
const t = "warn";
89+
if (typeof options === "string") {
90+
options = {
91+
content: options,
92+
type: t,
93+
};
94+
} else {
95+
options.type = t;
96+
}
97+
return Message(options);
98+
};
99+
100+
Message.info = (options: InstanceOptions) => {
101+
const t = "info";
102+
if (typeof options === "string") {
103+
options = {
104+
content: options,
105+
type: t,
106+
};
107+
} else {
108+
options.type = t;
109+
}
110+
return Message(options);
111+
};
87112

113+
Message.error = (options: InstanceOptions) => {
114+
const t = "error";
115+
if (typeof options === "string") {
116+
options = {
117+
content: options,
118+
type: t,
119+
};
120+
} else {
121+
options.type = t;
122+
}
123+
return Message(options);
124+
};
125+
126+
Message.success = (options: InstanceOptions) => {
127+
const t = "success";
128+
if (typeof options === "string") {
129+
options = {
130+
content: options,
131+
type: t,
132+
};
133+
} else {
134+
options.type = t;
135+
}
136+
return Message(options);
137+
};
88138
const remove = (id: string, userOnclose?: () => void) => {
89139
const index = Queqe.findIndex(vm => {
90140
const tid = vm.component?.props.id;
@@ -114,5 +164,6 @@ const remove = (id: string, userOnclose?: () => void) => {
114164
export default Message;
115165

116166
export const useMessage = () => {
167+
if (isServer) return;
117168
return Message;
118169
};

src/components/common/Message/type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import type { VNode, ComponentPublicInstance } from "vue";
33
export type MessageType = "warn" | "error" | "success" | "info";
44

55
export type MessageInstance = {
6-
(opt?: InstanceOptions): InstanceHandle;
6+
(opt: InstanceOptions): InstanceHandle;
77
warn: (opt: InstanceOptions) => InstanceHandle;
88
error: (opt: InstanceOptions) => InstanceHandle;
99
success: (opt: InstanceOptions) => InstanceHandle;
1010
info: (opt: InstanceOptions) => InstanceHandle;
11-
closeAll: () => void;
11+
closeAll(): void;
1212
};
1313

1414
export type Options = {

0 commit comments

Comments
 (0)