zhengyiming
1 天以前 1327b99efda99ada27a956981648950f580314b0
packages/core-vue/src/plugin.ts
@@ -1,5 +1,5 @@
import { BlLifeRecharge } from '@life-payment/core';
import { inject, shallowReactive } from 'vue';
import { BlLifeRecharge, BlLifeRechargeOptions } from '@life-payment/core';
import { inject, reactive, provide, ref } from 'vue';
import type { InjectionKey, UnwrapNestedRefs, Ref } from 'vue';
export type LifeRechargeContext = {
@@ -12,10 +12,25 @@
  blLifeRecharge: BlLifeRecharge;
};
function updateState(state: Record<string, unknown>, update: Record<string, any>): void {
  Object.keys(state).forEach((key) => {
    state[key] = update[key];
  });
}
export const VueLifeRechargePlugin = {
  install: (app: any, { blLifeRecharge }: VueLifeRechargePluginOptions) => {
    const _blLifeRecharge = reactive(blLifeRecharge);
    _blLifeRecharge.init();
    // blLifeRecharge.listener.addListener({
    //   update: (state) => {
    //     updateState(_blLifeRecharge, state);
    //   },
    // });
    app.provide(clientKey, {
      blLifeRecharge: shallowReactive(blLifeRecharge),
      blLifeRecharge: _blLifeRecharge,
    });
  },
};