weapp-api-promise

2.0.2 • Public • Published

weapp-api-promise

npm license PRs Welcome

微信小程序 API 基于 TypeScript 的 Promise 化

安装

yarn add weapp-api-promise
# or 
npm i weapp-api-promise

使用

全量加载

import wxp from "weapp-api-promise";
 
wxp
  .request({
    url: "https://foo.bar/api.json"
  })
  .then(res => {
    console.log(res);
  });

按需加载

import { request } from "weapp-api-promise";
 
request({
  url: "https://foo.bar/api.json"
}).then(res => {
  console.log(res);
});

完整 Promise 化 API 列表

import {
  $router,
  addCard,
  addPhoneContact,
  authorize,
  canvasGetImageData,
  canvasToTempFilePath,
  checkIsSoterEnrolledInDevice,
  checkIsSupportSoterAuthentication,
  checkSession,
  chooseAddress,
  chooseImage,
  chooseInvoice,
  chooseInvoiceTitle,
  chooseLocation,
  chooseMessageFile,
  chooseVideo,
  clearStorage,
  closeBLEConnection,
  compressImage,
  connectSocket,
  connectWifi,
  createBLEConnection,
  downloadFile,
  getAvailableAudioSources,
  getBackgroundAudioPlayerState,
  getBackgroundFetchData,
  getBackgroundFetchToken,
  getBatteryInfo,
  getBLEDeviceCharacteristics,
  getBLEDeviceServices,
  getClipboardData,
  getConnectedWifi,
  getExtConfig,
  getFileInfo,
  getHCEState,
  getImageInfo,
  getLocation,
  getNetworkType,
  getSavedFileList,
  getScreenBrightness,
  getSelectedTextRange,
  getSetting,
  getShareInfo,
  getStorage,
  getStorageInfo,
  getSystemInfo,
  getUserInfo,
  getWeRunData,
  getWifiList,
  hideHomeButton,
  hideKeyboard,
  hideLoading,
  hideNavigationBarLoading,
  hideShareMenu,
  hideTabBar,
  hideTabBarRedDot,
  hideToast,
  loadFontFace,
  login,
  makePhoneCall,
  navigateBack,
  navigateBackMiniProgram,
  navigateTo,
  navigateToMiniProgram,
  notifyBLECharacteristicValueChange,
  onBackgroundFetchData,
  openBusinessView,
  openCard,
  openDocument,
  openLocation,
  openSetting,
  pageScrollTo,
  pauseBackgroundAudio,
  pauseVoice,
  playBackgroundAudio,
  playVoice,
  previewImage,
  readBLECharacteristicValue,
  redirectTo,
  reLaunch,
  removeSavedFile,
  removeStorage,
  removeTabBarBadge,
  request,
  requestPayment,
  requestSubscribeMessage,
  saveFile,
  saveImageToPhotosAlbum,
  saveVideoToPhotosAlbum,
  scanCode,
  seekBackgroundAudio,
  sendHCEMessage,
  sendSocketMessage,
  setBackgroundColor,
  setBackgroundFetchToken,
  setBackgroundTextStyle,
  setClipboardData,
  setEnableDebug,
  setInnerAudioOption,
  setKeepScreenOn,
  setNavigationBarColor,
  setNavigationBarTitle,
  setScreenBrightness,
  setStorage,
  setTabBarBadge,
  setTabBarItem,
  setTabBarStyle,
  setTopBarText,
  setWifiList,
  showActionSheet,
  showLoading,
  showModal,
  showNavigationBarLoading,
  showShareMenu,
  showTabBar,
  showTabBarRedDot,
  showToast,
  startAccelerometer,
  startBeaconDiscovery,
  startCompass,
  startDeviceMotionListening,
  startGyroscope,
  startHCE,
  startLocalServiceDiscovery,
  startLocationUpdate,
  startLocationUpdateBackground,
  startPullDownRefresh,
  startRecord,
  startSoterAuthentication,
  stopAccelerometer,
  stopBackgroundAudio,
  stopBeaconDiscovery,
  stopCompass,
  stopDeviceMotionListening,
  stopGyroscope,
  stopHCE,
  stopLocalServiceDiscovery,
  stopLocationUpdate,
  stopPullDownRefresh,
  stopRecord,
  stopVoice,
  stopWifi,
  switchTab,
  updateShareMenu,
  uploadFile,
  vibrateLong,
  vibrateShort,
  writeBLECharacteristicValue
} from "weapp-api-promise";

$router 方法

包含 navigateredirectswitchTabback 四个方法,分别对应原生的 wx.navigateTowx.redirectTowx.switchTabwx.navigateBack 方法

同时当页面栈超过 10 层或其他异常时,尝试改用 redirectTo 重试

import wxp from "weapp-api-promise";
 
wxp.$router.navigate("path", {
  foo: "bar"
}); // => wx.navigateTo({ url: 'path?foo=bar', fail: () => wx.redirectTo({ url: 'path?foo=bar' }) })

License

MIT @ baranwang

Readme

Keywords

none

Package Sidebar

Install

npm i weapp-api-promise

Weekly Downloads

27

Version

2.0.2

License

MIT

Unpacked Size

70.3 kB

Total Files

310

Last publish

Collaborators

  • baranwang