Skip to content

Instantly share code, notes, and snippets.

@languanghao
Created May 29, 2020 09:04
Show Gist options
  • Save languanghao/d1b9fd7bc0fbbd44fecb359b13fcce8c to your computer and use it in GitHub Desktop.
Save languanghao/d1b9fd7bc0fbbd44fecb359b13fcce8c to your computer and use it in GitHub Desktop.
AddApiEventListener
window.onWindowActive = () => {
};
window.onDocumentSave = () => {
};
window.onDocumentBeforeClose = () => {
};
window.onDocumentAfterClose = () => {
};
window.onDocumentBeforePrint = () => {
};
window.onDocumentOpen = () => {
};
window.onDocumentNew = () => {
alert(333);
};
const EVENT_MAP = {
WindowActivate: window.onWindowActive,
DocumentBeforeSave: window.onDocumentSave,
DocumentBeforeClose: window.onDocumentBeforeClose,
DocumentAfterClose: window.onDocumentAfterClose,
DocumentBeforePrint: window.onDocumentBeforePrint,
DocumentOpen: window.onDocumentOpen,
DocumentNew: window.onDocumentNew,
};
export const registerDocumentEvents = () => {
for (const [key, value] of Object.entries(EVENT_MAP)) {
console.log(`注册事件: ${key}`);
wps.ApiEvent.AddApiEventListener(key, value);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment