zhengyiming
2025-02-21 bc9db06646fc925635dd5995d521bcf9fd05aa93
packages/components/src/utils/lifeRecharge.ts
@@ -1,20 +1,37 @@
import { BlLifeRechargeServices, PhoneMesssageCodeLoginInput } from './lifeRechargeServices';
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>;
  isLogin = false;
  userId = '';
  static constants = LifeRechargeConstants;
  constants = LifeRechargeConstants;
  constructor(options: BlLifeRechargeOptions<T>) {
    this.services = new BlLifeRechargeServices(options);
    this.userId = options.userId || '';
  }
  login(body: PhoneMesssageCodeLoginInput) {
    let res = this.services.lifePayPhoneMesssageCodeLogin(body);
    this.isLogin = true;
  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);
  }