初始化
This commit is contained in:
40
src/app/client/BaseClient.ts
Normal file
40
src/app/client/BaseClient.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { EventMap, TypedEmitter } from '../../common/TypedEmitter';
|
||||
import { ParamsBase } from '../../types/ParamsBase';
|
||||
import Util from '../Util';
|
||||
|
||||
export class BaseClient<P extends ParamsBase, TE extends EventMap> extends TypedEmitter<TE> {
|
||||
protected title = 'BaseClient';
|
||||
protected params: P;
|
||||
|
||||
protected constructor(params: P) {
|
||||
super();
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
public static parseParameters(query: URLSearchParams): ParamsBase {
|
||||
const action = Util.parseStringEnv(query.get('action'));
|
||||
if (!action) {
|
||||
throw TypeError('Invalid action');
|
||||
}
|
||||
return {
|
||||
action: action,
|
||||
useProxy: Util.parseBooleanEnv(query.get('useProxy')),
|
||||
secure: Util.parseBooleanEnv(query.get('secure')),
|
||||
hostname: Util.parseStringEnv(query.get('hostname')),
|
||||
port: Util.parseIntEnv(query.get('port')),
|
||||
pathname: Util.parseStringEnv(query.get('pathname')),
|
||||
};
|
||||
}
|
||||
|
||||
public setTitle(text = this.title): void {
|
||||
let titleTag: HTMLTitleElement | null = document.querySelector('head > title');
|
||||
if (!titleTag) {
|
||||
titleTag = document.createElement('title');
|
||||
}
|
||||
titleTag.innerText = text;
|
||||
}
|
||||
|
||||
public setBodyClass(text: string): void {
|
||||
document.body.className = text;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user