|
@@ -1,6 +1,6 @@
|
|
|
import { createVNode, defineComponent, render, App } from 'vue';
|
|
import { createVNode, defineComponent, render, App } from 'vue';
|
|
|
-import VueNotify from './index.vue';
|
|
|
|
|
-const NotifyConstructor = defineComponent(VueNotify);
|
|
|
|
|
|
|
+import Notify from './index.vue';
|
|
|
|
|
+const NotifyConstructor = defineComponent(Notify);
|
|
|
const defaultOptions = {
|
|
const defaultOptions = {
|
|
|
type: 'base',
|
|
type: 'base',
|
|
|
showPopup: false,
|
|
showPopup: false,
|
|
@@ -21,13 +21,13 @@ let optsMap: any[] = [];
|
|
|
const clearNotify = (id?: string) => {
|
|
const clearNotify = (id?: string) => {
|
|
|
if (id) {
|
|
if (id) {
|
|
|
const container = document.getElementById(id);
|
|
const container = document.getElementById(id);
|
|
|
- optsMap = optsMap.filter(item => item.id !== id);
|
|
|
|
|
- idsMap = idsMap.filter(item => item !== id);
|
|
|
|
|
|
|
+ optsMap = optsMap.filter((item) => item.id !== id);
|
|
|
|
|
+ idsMap = idsMap.filter((item) => item !== id);
|
|
|
if (container) {
|
|
if (container) {
|
|
|
document.body.removeChild(container);
|
|
document.body.removeChild(container);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- idsMap.forEach(item => {
|
|
|
|
|
|
|
+ idsMap.forEach((item) => {
|
|
|
const container = document.getElementById(item);
|
|
const container = document.getElementById(item);
|
|
|
if (container) {
|
|
if (container) {
|
|
|
document.body.removeChild(container);
|
|
document.body.removeChild(container);
|
|
@@ -41,13 +41,13 @@ const clearNotify = (id?: string) => {
|
|
|
const updateNotify = (opts: any) => {
|
|
const updateNotify = (opts: any) => {
|
|
|
const container = document.getElementById(opts.id);
|
|
const container = document.getElementById(opts.id);
|
|
|
if (container) {
|
|
if (container) {
|
|
|
- const currentOpt = optsMap.find(item => item.id === opts.id);
|
|
|
|
|
|
|
+ const currentOpt = optsMap.find((item) => item.id === opts.id);
|
|
|
if (currentOpt) {
|
|
if (currentOpt) {
|
|
|
opts = { ...defaultOptions, ...currentOpt, ...opts };
|
|
opts = { ...defaultOptions, ...currentOpt, ...opts };
|
|
|
} else {
|
|
} else {
|
|
|
opts = { ...defaultOptions, ...opts };
|
|
opts = { ...defaultOptions, ...opts };
|
|
|
}
|
|
}
|
|
|
- const instance: any = createVNode(VueNotify, opts);
|
|
|
|
|
|
|
+ const instance: any = createVNode(Notify, opts);
|
|
|
render(instance, container);
|
|
render(instance, container);
|
|
|
return instance.component.ctx;
|
|
return instance.component.ctx;
|
|
|
}
|
|
}
|
|
@@ -58,7 +58,7 @@ const mountNotify = (opts: any) => {
|
|
|
let _id;
|
|
let _id;
|
|
|
if (opts.id) {
|
|
if (opts.id) {
|
|
|
_id = opts.id;
|
|
_id = opts.id;
|
|
|
- if (idsMap.find(item => item === opts.id)) {
|
|
|
|
|
|
|
+ if (idsMap.find((item) => item === opts.id)) {
|
|
|
return updateNotify(opts);
|
|
return updateNotify(opts);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -86,7 +86,7 @@ const errorMsg = (msg: string) => {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-export const Notify = {
|
|
|
|
|
|
|
+export const NotifyFunction = {
|
|
|
text(msg: string, obj = {}) {
|
|
text(msg: string, obj = {}) {
|
|
|
errorMsg(msg);
|
|
errorMsg(msg);
|
|
|
return mountNotify({ ...obj, msg });
|
|
return mountNotify({ ...obj, msg });
|
|
@@ -109,11 +109,11 @@ export const Notify = {
|
|
|
},
|
|
},
|
|
|
hide() {
|
|
hide() {
|
|
|
clearNotify();
|
|
clearNotify();
|
|
|
- }
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
-export default {
|
|
|
|
|
|
|
+ },
|
|
|
install(app: App): void {
|
|
install(app: App): void {
|
|
|
- app.config.globalProperties.$notify = Notify;
|
|
|
|
|
|
|
+ app.config.globalProperties.$notify = NotifyFunction;
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+export default NotifyFunction;
|
|
|
|
|
+export { Notify };
|