Browse Source
* commit '80b5eda991e1d318e424683e39b740e164983323': fix: 根据最新交互修改,调整数据库模式交互逻辑。 fix: 根据最新交互修改,调整数据库模式交互逻辑。qufenxi
alan
5 years ago
6 changed files with 147 additions and 178 deletions
@ -0,0 +1,84 @@ |
|||||||
|
import { Connection, ConnectionJDBC } from '../../../crud/crud.typings'; |
||||||
|
import { connectionType, errorCode } from '@constants/env'; |
||||||
|
import { DATA_BASE_DRIVER_LINK } from '@constants/constant'; |
||||||
|
import { TestStatusXtype, EVENT_RELOAD, EVENT_CLOSE } from '../../../components/test_status/test_status'; |
||||||
|
import { ApiFactory } from '../../../crud/apiFactory'; |
||||||
|
const api = new ApiFactory().create(); |
||||||
|
export function testConnection(value: Connection): Promise<string[]> { |
||||||
|
return new Promise(resolve => { |
||||||
|
let testStatus = null; |
||||||
|
if (!value.connectionName) { |
||||||
|
BI.Msg.toast(BI.i18nText('Dec-Dcm_Connection_ConnectionName_Cannt_Null'), { |
||||||
|
level: 'error', |
||||||
|
}); |
||||||
|
|
||||||
|
return false; |
||||||
|
} |
||||||
|
const id = BI.UUID(); |
||||||
|
const testConnection = () => { |
||||||
|
const formValue = value; |
||||||
|
api.testConnection(formValue).then(re => { |
||||||
|
if (re && re.errorCode) { |
||||||
|
// 判断是否是缺少驱动,如果缺少驱动则显示下载驱动的连接
|
||||||
|
if (api.isDriverError(re.errorCode)) { |
||||||
|
if (formValue.connectionType === connectionType.JDBC) { |
||||||
|
const driver = (formValue.connectionData as ConnectionJDBC).driver; |
||||||
|
const databaseType = (formValue.connectionData as ConnectionJDBC).database; |
||||||
|
const databaseLink = BI.get(DATA_BASE_DRIVER_LINK.find(item => item.databaseType === databaseType), 'link'); |
||||||
|
testStatus.setFail(re.errorMsg, driver, Dec.system[DecCst.Hyperlink.DECISION_HYPERLINK_CONFIG][databaseLink]); |
||||||
|
} else { |
||||||
|
testStatus.setFail(re.errorMsg); |
||||||
|
} |
||||||
|
} else if (re.errorCode === errorCode.DUPLICATE_NAMES) { |
||||||
|
testStatus.setFail(BI.i18nText(re.errorMsg)); |
||||||
|
} else { |
||||||
|
testStatus.setFail(re.errorMsg); |
||||||
|
} |
||||||
|
} else if (re.data) { |
||||||
|
testStatus.setSuccess(); |
||||||
|
resolve(re.data); |
||||||
|
setTimeout(() => { |
||||||
|
BI.Maskers.remove(id); |
||||||
|
}, 1000 * 2); |
||||||
|
} else { |
||||||
|
BI.Msg.toast(BI.i18nText('Dec-Dcm_Connection_Error'), { |
||||||
|
level: 'error', |
||||||
|
}); |
||||||
|
BI.Maskers.remove(id); |
||||||
|
} |
||||||
|
}); |
||||||
|
}; |
||||||
|
BI.Maskers.create(id, null, { |
||||||
|
render: { |
||||||
|
type: TestStatusXtype, |
||||||
|
loadingText: BI.i18nText('Dec-Dcm_Connection_Testing'), |
||||||
|
loadingCls: 'upload-loading-icon', |
||||||
|
successText: BI.i18nText('Dec-Dcm_Connection_Test_Success'), |
||||||
|
successCls: 'upload-success-icon', |
||||||
|
failText: BI.i18nText('Dec-Dcm_Connection_Test_Fail', name), |
||||||
|
failCls: 'upload-fail-icon', |
||||||
|
retryText: BI.i18nText('Dec-Dcm_Connection_ReConnect'), |
||||||
|
ref: (_ref: any) => { |
||||||
|
testStatus = _ref; |
||||||
|
}, |
||||||
|
listeners: [ |
||||||
|
{ |
||||||
|
eventName: EVENT_RELOAD, |
||||||
|
action: () => { |
||||||
|
testStatus.setLoading(); |
||||||
|
testConnection(); |
||||||
|
}, |
||||||
|
}, |
||||||
|
{ |
||||||
|
eventName: EVENT_CLOSE, |
||||||
|
action: () => { |
||||||
|
BI.Maskers.remove(id); |
||||||
|
}, |
||||||
|
}, |
||||||
|
], |
||||||
|
}, |
||||||
|
}); |
||||||
|
BI.Maskers.show(id); |
||||||
|
testConnection(); |
||||||
|
}); |
||||||
|
} |
Loading…
Reference in new issue