2015-11-15 08:23:16 +08:00
|
|
|
import ko from 'ko';
|
2016-10-19 01:52:43 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { i18nToNodes } from 'Common/Translator';
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
class AbstractComponent {
|
2016-09-10 06:38:16 +08:00
|
|
|
disposable = [];
|
2015-11-15 08:23:16 +08:00
|
|
|
|
|
|
|
dispose() {
|
2015-11-19 01:32:29 +08:00
|
|
|
this.disposable.forEach((funcToDispose) => {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (funcToDispose && funcToDispose.dispose) {
|
2015-11-15 08:23:16 +08:00
|
|
|
funcToDispose.dispose();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {*} ClassObject
|
2015-11-19 01:32:29 +08:00
|
|
|
* @param {string} templateID = ''
|
2016-06-30 08:02:45 +08:00
|
|
|
* @returns {Object}
|
2015-11-15 08:23:16 +08:00
|
|
|
*/
|
2016-07-02 06:49:59 +08:00
|
|
|
const componentExportHelper = (ClassObject, templateID = '') => ({
|
2019-07-05 03:19:24 +08:00
|
|
|
template: templateID ? { element: templateID } : '<b></b>',
|
2016-07-02 06:49:59 +08:00
|
|
|
viewModel: {
|
|
|
|
createViewModel: (params, componentInfo) => {
|
|
|
|
params = params || {};
|
|
|
|
params.element = null;
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (componentInfo && componentInfo.element) {
|
2016-07-02 06:49:59 +08:00
|
|
|
params.component = componentInfo;
|
2020-08-30 16:30:50 +08:00
|
|
|
params.element = componentInfo.element;
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2020-08-27 21:45:47 +08:00
|
|
|
i18nToNodes(componentInfo.element);
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2020-07-30 03:49:41 +08:00
|
|
|
if (undefined !== params.inline && ko.unwrap(params.inline)) {
|
2020-08-30 16:30:50 +08:00
|
|
|
params.element.style.display = 'inline-block';
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
|
|
|
}
|
2016-07-02 06:49:59 +08:00
|
|
|
|
|
|
|
return new ClassObject(params);
|
2015-11-15 08:23:16 +08:00
|
|
|
}
|
2016-07-02 06:49:59 +08:00
|
|
|
}
|
|
|
|
});
|
2015-11-15 08:23:16 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
export { AbstractComponent, componentExportHelper };
|