wupengfei
2025-02-21 64b52fa928e11640e8d6aad49bd39cd27c896543
packages/components/src/utils/lifeRecharge.ts
@@ -1,4 +1,37 @@
export class BlLifeRecharge {
import {
  BlLifeRechargeServices,
  PhoneMesssageCodeLoginInput,
  RequestConfig,
} from './lifeRechargeServices';
import { IRequest, BlLifeRechargeOptions } from './types';
import { LifeRechargeConstants } from './lifeRechargeConstants';
export class BlLifeRecharge<T extends IRequest = IRequest> {
  services: BlLifeRechargeServices<T>;
  userId = '';
  static constants = LifeRechargeConstants;
  constants = LifeRechargeConstants;
  constructor(options: BlLifeRechargeOptions<T>) {
    this.services = new BlLifeRechargeServices(options);
    this.userId = options.userId || '';
  }
  async login(body: PhoneMesssageCodeLoginInput, options?: RequestConfig) {
    let res = await this.services.lifePayPhoneMesssageCodeLogin(body, options);
    this.userId = res;
    return res;
  }
  loginout() {
    this.userId = '';
  }
  isLogin() {
    return !!this.userId;
  }
  getRechargeParValue(amount: number, rate: number) {
    return (amount * rate).toFixed(2);
  }