/* 拉起手机授权 */
export function launchPhone({ commit }) {
  return new Promise((resolve, reject) => {
    const state = {
      show: true,
      triggerFn: resolve,
      triggerReject: reject,
    };
    commit({ phoneModal: state });
  });
}

/* 手机授权成功 */
export function phoneTriggerFn({ state }) {
  if (state.phoneModal.triggerFn) {
    state.phoneModal.triggerFn();
  }
}

/* 手机授权失败 */
export function phoneTriggerFailFn({ state }) {
  if (state.phoneModal.triggerReject) {
    state.phoneModal.triggerReject();
  }
}

/* 关闭授权弹窗 */
export function closePhoneModal({ commit }) {
  const state = {
    show: false,
    triggerFn: null,
    triggerReject: null,
  };
  commit({ phoneModal: state });
}

/* 拉起登录授权 */
export function launchLogin({ commit }) {
  return new Promise((resolve, reject) => {
    const state = {
      show: true,
      triggerFn: resolve,
      triggerReject: reject,
    };
    commit({ loginModal: state });
  });
}

/* 登录授权成功 */
export function loginTriggerFn({ state }) {
  if (state.loginModal.triggerFn) {
    state.loginModal.triggerFn();
  }
}

/* 登录授权失败 */
export function loginTriggerRejectFn({ state }) {
  if (state.loginModal.triggerReject) {
    state.loginModal.triggerReject();
  }
}

/* 关闭授权弹窗 */
export function closeLoginModal({ commit }) {
  const state = {
    show: false,
    triggerFn: null,
    triggerReject: null,
  };
  commit({ loginModal: state });
}

