Browse Source

Pull request #8944: REPORT-116621 fix: 【服务拆分】emit回调无法触发问题

Merge in DEC/decision-webui-dcm from ~AUSTIN.DUAN/decision-webui-dcm:research/11.0 to research/11.0

* commit '4847988a9289a70ba747bccb0294cb09249a832d':
  REPORT-116621  fix: 【服务拆分】emit回调无法触发问题
research/11.0
Austin.Duan-段嗣跃 8 months ago
parent
commit
babc7aafa1
  1. 12
      src/modules/constants/env.ts
  2. 30
      src/modules/crud/decision.api.ts
  3. 3
      types/globals.d.ts

12
src/modules/constants/env.ts

@ -9,12 +9,12 @@ export const connectionType: {
JNDI: string; JNDI: string;
} = DecCst.Connect.ConnectionType; } = DecCst.Connect.ConnectionType;
export const editStatusEvent: { export const editStatusEvent = {
OPEN: string; OPEN: 'getConnectionStatus',
SHUTDOWN: string; SHUTDOWN: 'shutdownConnectionStatus',
CONNECTION_EDITED: string, CONNECTION_EDITED: 'connectionEdited',
CONNECTION_RELEASED: string, CONNECTION_RELEASED: 'connectionReleased',
} = DecCst.Connect.EditStatusEvent; };
export const errorCode: { export const errorCode: {
CONNECTION_DELETED: string; CONNECTION_DELETED: string;

30
src/modules/crud/decision.api.ts

@ -61,11 +61,14 @@ export class DecisionApi implements Api {
} }
getConnectionStatus(name: string): Promise<SocketResult> { getConnectionStatus(name: string): Promise<SocketResult> {
return this.sendEditStatusEvent(name, editStatusEvent.OPEN) // TODO: 当前emit同步回调已无法执行
.then(re => { this.sendEditStatusEvent(name, editStatusEvent.OPEN);
if (re.errorCode) {
return new Promise((resolve, rejected) => {
this.addEventListener(editStatusEvent.OPEN, res => {
if (res.errorCode) {
let errorMessage = ''; let errorMessage = '';
switch (re.errorCode) { switch (res.errorCode) {
case errorCode.CONNECTION_DELETED: case errorCode.CONNECTION_DELETED:
errorMessage = 'Dec-Dcm_Connection_Deleted'; errorMessage = 'Dec-Dcm_Connection_Deleted';
break; break;
@ -73,17 +76,18 @@ export class DecisionApi implements Api {
errorMessage = 'Dec-Dcm_Connection_Is_Using'; errorMessage = 'Dec-Dcm_Connection_Is_Using';
break; break;
default: default:
errorMessage = re.errorMsg; errorMessage = res.errorMsg;
break; break;
} }
BI.Msg.toast(BI.i18nText(errorMessage, re.errorMsg), { BI.Msg.toast(BI.i18nText(errorMessage, res.errorMsg), {
level: 'error', level: 'error',
}); });
throw re; rejected(res);
} else { } else {
return re; resolve(res);
} }
}); });
});
} }
setEditedConnectionStatus(name: string): Promise<SocketResult> { setEditedConnectionStatus(name: string): Promise<SocketResult> {
@ -131,4 +135,14 @@ export class DecisionApi implements Api {
} }
}); });
} }
private addEventListener(name: string, callback: Function) {
if (!Dec.socket) return;
if (Dec.socket.hasListeners(name)) {
Dec.socket.removeListener(name);
}
Dec.socket.originOn(name, callback);
}
} }

3
types/globals.d.ts vendored

@ -10,6 +10,9 @@ declare const Dec: {
socket: { socket: {
connected: boolean; connected: boolean;
emit: Function; emit: Function;
originOn: Function;
hasListeners: Function;
removeListener: Function;
}; };
system: { system: {

Loading…
Cancel
Save