54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { Service } from 'egg';
|
|
import { addBags, addEquips } from '@pubUtils/itemUtils';
|
|
import * as pubUtils from '@pubUtils/util';
|
|
import { BagInter, EquipInter } from '@pubUtils/interface';
|
|
const csprng = require('csprng');
|
|
|
|
/**
|
|
* Utils Service
|
|
*/
|
|
export default class Utils extends Service {
|
|
/**
|
|
* 生成 len 长度的随机字符串
|
|
* @param len 长度
|
|
* @param radix 基数
|
|
*/
|
|
public generateStr(len: number, radix = 36) {
|
|
return `${csprng(len, radix)}`;
|
|
}
|
|
|
|
public genCode(len: number) {
|
|
return pubUtils.genCode(len)
|
|
}
|
|
|
|
public resResult(status: {code: number, simStr: string}, data?, customMsg?: string) {
|
|
return pubUtils.resResult(status, data, customMsg);
|
|
}
|
|
|
|
public addBags(roleId: string, roleName: string, data: BagInter) {
|
|
return addBags(roleId, roleName, data);
|
|
}
|
|
|
|
public addEquips(roleId: string, roleName: string, weapon: EquipInter) {
|
|
return addEquips(roleId, roleName, weapon);
|
|
}
|
|
|
|
public checkActivityData(data: any, type: number) {
|
|
return { data, type }
|
|
}
|
|
|
|
public log(level: 'DEBUG'|'INFO'|'WARN'| 'ERROR', message: string) {
|
|
const log = this.app.loggers.get('linkLogger');
|
|
|
|
if(level == 'DEBUG') {
|
|
log.error(`${message}`);
|
|
} else if (level == 'INFO') {
|
|
log.info(`${message}`);
|
|
} else if (level == 'WARN') {
|
|
log.warn(`${message}`);
|
|
} else if (level == "ERROR") {
|
|
log.error(`${message}`);
|
|
}
|
|
}
|
|
}
|