2024-12-04 02:35:06 +08:00
|
|
|
import { HttpClient } from "core/http";
|
|
|
|
import { CapabilityService } from "core/capability";
|
|
|
|
import { Serializable } from "interface/serializableType";
|
2024-12-05 02:13:54 +08:00
|
|
|
import { Layout } from "./layout";
|
2024-11-30 22:24:35 +08:00
|
|
|
|
|
|
|
export class Template {
|
2024-12-05 02:13:54 +08:00
|
|
|
private http: HttpClient;
|
|
|
|
private capability: CapabilityService;
|
|
|
|
|
2024-11-30 22:24:35 +08:00
|
|
|
constructor(
|
|
|
|
public config: {
|
2024-12-05 02:13:54 +08:00
|
|
|
layout?: Layout;
|
2024-11-30 22:24:35 +08:00
|
|
|
styles?: string[];
|
|
|
|
scripts?: string[];
|
2024-12-03 01:37:02 +08:00
|
|
|
description?: string;
|
2024-11-30 22:24:35 +08:00
|
|
|
},
|
2024-12-05 02:13:54 +08:00
|
|
|
public element: (props: {
|
2024-11-30 22:24:35 +08:00
|
|
|
http: HttpClient;
|
2024-12-03 01:37:02 +08:00
|
|
|
args: Serializable;
|
2024-12-04 02:35:06 +08:00
|
|
|
}) => React.ReactNode,
|
2024-12-05 02:13:54 +08:00
|
|
|
services?: {
|
|
|
|
http?: HttpClient;
|
|
|
|
capability?: CapabilityService;
|
|
|
|
}
|
|
|
|
) {
|
|
|
|
this.http = services?.http || HttpClient.getInstance();
|
|
|
|
this.capability = services?.capability || CapabilityService.getInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
render(args: Serializable) {
|
|
|
|
const content = this.element({
|
|
|
|
http: this.http,
|
|
|
|
args,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this.config.layout) {
|
|
|
|
return this.config.layout.render({
|
|
|
|
children: content,
|
|
|
|
args,
|
|
|
|
});
|
|
|
|
}
|
2024-11-30 22:24:35 +08:00
|
|
|
|
2024-12-05 02:13:54 +08:00
|
|
|
return content;
|
2024-11-30 22:24:35 +08:00
|
|
|
}
|
2024-12-04 02:35:06 +08:00
|
|
|
}
|