cool-admin-vue/packages/crud/src/emitter.ts
神仙都没用 1735d6258e 发布7.x
2023-09-28 13:50:15 +08:00

28 lines
498 B
TypeScript

export const crudList: ClCrud.Ref[] = [];
export const emitter: Emitter = {
list: [],
init(events) {
for (const i in events) {
this.on(i, events[i]);
}
},
emit(name, data) {
this.list.forEach((e: EmitterItem) => {
const [_name] = e.name.split("-");
if (name == _name) {
e.callback(data, {
crudList,
refresh(params) {
crudList.forEach((c) => c.refresh(params));
}
});
}
});
},
on(name, callback) {
this.list.push({ name, callback });
}
};