├── .node-version ├── .czrc ├── pnpm-workspace.yaml ├── .npmrc ├── .prettierrc.cjs ├── .commitlintrc.cjs ├── .eslintrc.cjs ├── playground ├── src │ ├── static │ │ └── logo.png │ ├── main.ts │ ├── App.vue │ ├── pages.json │ ├── pages │ │ └── index │ │ │ └── index.vue │ └── manifest.json ├── vite.config.ts ├── tsconfig.json ├── index.html └── package.json ├── .simple-git-hooks.cjs ├── .lintstagedrc.cjs ├── src ├── login │ └── index.ts ├── share │ └── index.ts ├── getRecordManager │ └── index.ts ├── preLogin │ └── index.ts ├── saveFile │ └── index.ts ├── showModal │ └── index.ts ├── showToast │ └── index.ts ├── reLaunch │ └── index.ts ├── vibrate │ └── index.ts ├── authorize │ └── index.ts ├── createCameraContext │ └── index.ts ├── createSelectorQuery │ └── index.ts ├── getSetting │ └── index.ts ├── hideTabBar │ └── index.ts ├── showTabBar │ └── index.ts ├── checkSession │ └── index.ts ├── compressImage │ └── index.ts ├── compressVideo │ └── index.ts ├── getFileInfo │ └── index.ts ├── getImageInfo │ └── index.ts ├── getProvider │ └── index.ts ├── getUserInfo │ └── index.ts ├── getVideoInfo │ └── index.ts ├── loadFontFace │ └── index.ts ├── navigateTo │ └── index.ts ├── pageScrollTo │ └── index.ts ├── previewImage │ └── index.ts ├── redirectTo │ └── index.ts ├── scanCode │ └── index.ts ├── showLoading │ └── index.ts ├── chooseImage │ └── index.ts ├── clearStorage │ └── index.ts ├── getBatteryInfo │ └── index.ts ├── getSystemInfo │ └── index.ts ├── hideShareMenu │ └── index.ts ├── makePhoneCall │ └── index.ts ├── navigateBack │ └── index.ts ├── showShareMenu │ └── index.ts ├── getLocation │ └── index.ts ├── getNetworkType │ └── index.ts ├── getStorage │ └── index.ts ├── getUserProfile │ └── index.ts ├── requestPayment │ └── index.ts ├── showActionSheet │ └── index.ts ├── switchTab │ └── index.ts ├── vibrateLong │ └── index.ts ├── chooseLocation │ └── index.ts ├── chooseVideo │ └── index.ts ├── closeSocket │ └── index.ts ├── getExtConfig │ └── index.ts ├── hideHomeButton │ └── index.ts ├── openLocation │ └── index.ts ├── openVideoEditor │ └── index.ts ├── removeSavedFile │ └── index.ts ├── setTabBarItem │ └── index.ts ├── setTabBarStyle │ └── index.ts ├── shareWithSystem │ └── index.ts ├── vibrateShort │ └── index.ts ├── closePreviewImage │ └── index.ts ├── getBLEDeviceRSSI │ └── index.ts ├── getPushClientId │ └── index.ts ├── getSavedFileInfo │ └── index.ts ├── getSavedFileList │ └── index.ts ├── openSetting │ └── index.ts ├── removeStorage │ └── index.ts ├── setKeepScreenOn │ └── index.ts ├── setTabBarBadge │ └── index.ts ├── addPhoneContact │ └── index.ts ├── chooseFile │ └── index.ts ├── connectSocket │ └── index.ts ├── createInnerAudioContext │ └── index.ts ├── createPushMessage │ └── index.ts ├── getCheckBoxState │ └── index.ts ├── getClipboardData │ └── index.ts ├── getStorageInfo │ └── index.ts ├── setBackgroundColor │ └── index.ts ├── setClipboardData │ └── index.ts ├── closeBLEConnection │ └── index.ts ├── createBLEConnection │ └── index.ts ├── getSelectedTextRange │ └── index.ts ├── hideTabBarRedDot │ └── index.ts ├── removeTabBarBadge │ └── index.ts ├── setStorage │ └── index.ts ├── showTabBarRedDot │ └── index.ts ├── startPullDownRefresh │ └── index.ts ├── getBLEDeviceServices │ └── index.ts ├── getScreenBrightness │ └── index.ts ├── openDocument │ └── index.ts ├── setScreenBrightness │ └── index.ts ├── closeBluetoothAdapter │ └── index.ts ├── getBluetoothDevices │ └── index.ts ├── openAppAuthorizeSetting │ └── index.ts ├── openBluetoothAdapter │ └── index.ts ├── setNavigationBarColor │ └── index.ts ├── saveImageToPhotosAlbum │ └── index.ts ├── saveVideoToPhotosAlbum │ └── index.ts ├── sendSocketMessage │ └── index.ts ├── setBackgroundTextStyle │ └── index.ts ├── setNavigationBarTitle │ └── index.ts ├── getBackgroundAudioManager │ └── index.ts ├── hideNavigationBarLoading │ └── index.ts ├── setEnableDebug │ └── index.ts ├── chooseInvoiceTitle │ └── index.ts ├── getBluetoothAdapterState │ └── index.ts ├── showNavigationBarLoading │ └── index.ts ├── navigateToMiniProgram │ └── index.ts ├── startSoterAuthentication │ └── index.ts ├── getApp │ └── index.ts ├── getBLEDeviceCharacteristics │ └── index.ts ├── readBLECharacteristicValue │ └── index.ts ├── createCanvasContext │ └── index.ts ├── writeBLECharacteristicValue │ └── index.ts ├── createVideoContext │ └── index.ts ├── getConnectedBluetoothDevices │ └── index.ts ├── startBluetoothDevicesDiscovery │ └── index.ts ├── stopBluetoothDevicesDiscovery │ └── index.ts ├── checkIsSoterEnrolledInDevice │ └── index.ts ├── navigateBackMiniProgram │ └── index.ts ├── createLivePusherContext │ └── index.ts ├── chooseAddress │ └── index.ts ├── setBLEMTU │ └── index.ts ├── checkIsSupportSoterAuthentication │ └── index.ts ├── notifyBLECharacteristicValueChange │ └── index.ts ├── chooseMedia │ └── index.ts ├── createMediaContainer │ └── index.ts ├── chooseMessageFile │ └── index.ts ├── chooseInvoice │ └── index.ts ├── createLivePlayerContext │ └── index.ts ├── request │ └── index.ts ├── uploadFile │ └── index.ts ├── downloadFile │ └── index.ts ├── utils.ts ├── types.ts ├── requestSubscribeMessage │ └── index.ts ├── index.ts └── createMapContext │ └── index.ts ├── .markdownlint.json ├── .editorconfig ├── tsconfig.json ├── CHANGELOG.md ├── .github └── workflows │ ├── release.yml │ └── ci.yml ├── LICENSE ├── .gitignore ├── package.json └── README.md /.node-version: -------------------------------------------------------------------------------- 1 | 24 2 | -------------------------------------------------------------------------------- /.czrc: -------------------------------------------------------------------------------- 1 | { 2 | "path": "@commitlint/prompt" 3 | } 4 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - 'playground' 3 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | shamefully-hoist=true 2 | registry=https://registry.npmjs.org/ 3 | -------------------------------------------------------------------------------- /.prettierrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | ...require('@modyqyw/fabric/prettier'), 3 | }; 4 | -------------------------------------------------------------------------------- /.commitlintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['@commitlint/config-conventional'], 3 | }; 4 | -------------------------------------------------------------------------------- /.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [require.resolve('@modyqyw/fabric/eslint')], 3 | }; 4 | -------------------------------------------------------------------------------- /playground/src/static/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uni-helper/uni-promises/HEAD/playground/src/static/logo.png -------------------------------------------------------------------------------- /.simple-git-hooks.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 'pre-commit': 'npx lint-staged --allow-empty', 3 | 'commit-msg': 'npx commitlint --edit ${1}', 4 | }; 5 | -------------------------------------------------------------------------------- /.lintstagedrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | '*.md': 'markdownlint --fix --ignore-path=.gitignore', 3 | './src/*.{js,cjs,mjs,ts,cts,mts}': 'eslint --fix --cache --ignore-path=.gitignore', 4 | }; 5 | -------------------------------------------------------------------------------- /src/login/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 登录 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/plugins/login?id=login 7 | */ 8 | export const login = promisify(uni.login); 9 | -------------------------------------------------------------------------------- /src/share/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 分享 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/plugins/share?id=share 7 | */ 8 | export const share = promisify(uni.share); 9 | -------------------------------------------------------------------------------- /playground/src/main.ts: -------------------------------------------------------------------------------- 1 | import { createSSRApp } from 'vue'; 2 | import App from './App.vue'; 3 | export function createApp() { 4 | const app = createSSRApp(App); 5 | return { 6 | app, 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /src/getRecordManager/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 录音管理 3 | * 4 | * 文档 http://uniapp.dcloud.io/api/media/record-manager?id=getrecordermanager 5 | */ 6 | export const getRecordManager = () => uni.getRecorderManager(); 7 | -------------------------------------------------------------------------------- /playground/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite'; 2 | import uni from '@dcloudio/vite-plugin-uni'; 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [uni()], 7 | }); 8 | -------------------------------------------------------------------------------- /src/preLogin/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 预登录 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/plugins/login?id=prelogin 7 | */ 8 | export const preLogin = promisify(uni.preLogin); 9 | -------------------------------------------------------------------------------- /src/saveFile/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 保存文件到本地 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/file/file?id=savefile 7 | */ 8 | export const saveFile = promisify(uni.saveFile); 9 | -------------------------------------------------------------------------------- /src/showModal/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 显示模态弹窗 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/prompt?id=showmodal 7 | */ 8 | export const showModal = promisify(uni.showModal); 9 | -------------------------------------------------------------------------------- /src/showToast/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 显示消息提示框 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/prompt?id=showtoast 7 | */ 8 | export const showToast = promisify(uni.showToast); 9 | -------------------------------------------------------------------------------- /src/reLaunch/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 关闭所有页面,打开到应用内的某个页面 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/router?id=relaunch 7 | */ 8 | export const reLaunch = promisify(uni.reLaunch); 9 | -------------------------------------------------------------------------------- /src/vibrate/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 使手机发生振动 5 | * 6 | * 文档 https://uniapp.dcloud.net.cn/api/system/vibrate.html#vibrate 7 | */ 8 | export const vibrate = promisify(uni.vibrate); 9 | -------------------------------------------------------------------------------- /src/authorize/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 提前向用户发起授权请求 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/other/authorize?id=authorize 7 | */ 8 | export const authorize = promisify(uni.authorize); 9 | -------------------------------------------------------------------------------- /src/createCameraContext/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 创建并返回 camera 组件的上下文 cameraContext 对象 3 | * 4 | * 文档 http://uniapp.dcloud.io/api/media/camera-context 5 | */ 6 | export const createCameraContext = () => uni.createCameraContext(); 7 | -------------------------------------------------------------------------------- /src/createSelectorQuery/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 返回一个 SelectorQuery 对象实例 3 | * 4 | * 文档 http://uniapp.dcloud.io/api/ui/nodes-info?id=createselectorquery 5 | */ 6 | export const createSelectorQuery = () => uni.createSelectorQuery(); 7 | -------------------------------------------------------------------------------- /src/getSetting/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取用户的当前设置 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/other/setting?id=getsetting 7 | */ 8 | export const getSetting = promisify(uni.getSetting); 9 | -------------------------------------------------------------------------------- /src/hideTabBar/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 隐藏 TabBar 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/tabbar?id=hidetabbar 7 | */ 8 | export const hideTabBar = promisify(uni.hideTabBar); 9 | -------------------------------------------------------------------------------- /src/showTabBar/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 显示 tabBar 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/tabbar?id=showtabbar 7 | */ 8 | export const showTabBar = promisify(uni.showTabBar); 9 | -------------------------------------------------------------------------------- /src/checkSession/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 登录 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/plugins/login?id=unichecksession 7 | */ 8 | export const checkSession = promisify(uni.checkSession); 9 | -------------------------------------------------------------------------------- /src/compressImage/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 压缩图片 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/media/image?id=compressimage 7 | */ 8 | export const compressImage = promisify(uni.compressImage); 9 | -------------------------------------------------------------------------------- /src/compressVideo/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 压缩视频 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/media/video?id=compressvideo 7 | */ 8 | export const compressVideo = promisify(uni.compressVideo); 9 | -------------------------------------------------------------------------------- /src/getFileInfo/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取文件信息 5 | * 6 | * 文档 https://uniapp.dcloud.net.cn/api/file/file.html#getfileinfo 7 | */ 8 | export const getFileInfo = promisify(uni.getFileInfo); 9 | -------------------------------------------------------------------------------- /src/getImageInfo/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 预览图片 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/media/image?id=getimageinfo 7 | */ 8 | export const getImageInfo = promisify(uni.getImageInfo); 9 | -------------------------------------------------------------------------------- /src/getProvider/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取服务供应商 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/plugins/provider?id=getprovider 7 | */ 8 | export const getProvider = promisify(uni.getProvider); 9 | -------------------------------------------------------------------------------- /src/getUserInfo/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取用户信息 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/plugins/login?id=getuserinfo 7 | */ 8 | export const getUserInfo = promisify(uni.getUserInfo); 9 | -------------------------------------------------------------------------------- /src/getVideoInfo/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 压缩视频 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/media/video?id=getvideoinfo 7 | */ 8 | export const getVideoInfo = promisify(uni.getVideoInfo); 9 | -------------------------------------------------------------------------------- /src/loadFontFace/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 动态加载网络字体 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/font?id=loadfontface 7 | */ 8 | export const loadFontFace = promisify(uni.loadFontFace); 9 | -------------------------------------------------------------------------------- /src/navigateTo/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 保留当前页面,跳转到应用内的某个页面 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/router?id=navigateto 7 | */ 8 | export const navigateTo = promisify(uni.navigateTo); 9 | -------------------------------------------------------------------------------- /src/pageScrollTo/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 将页面滚动到目标位置 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/scroll?id=pagescrollto 7 | */ 8 | export const pageScrollTo = promisify(uni.pageScrollTo); 9 | -------------------------------------------------------------------------------- /src/previewImage/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 预览图片 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/media/image?id=previewimage 7 | */ 8 | export const previewImage = promisify(uni.previewImage); 9 | -------------------------------------------------------------------------------- /src/redirectTo/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 关闭当前页面,跳转到应用内的某个页面 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/router?id=redirectto 7 | */ 8 | export const redirectTo = promisify(uni.redirectTo); 9 | -------------------------------------------------------------------------------- /src/scanCode/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 调用扫码界面,扫码成功后返回对应的结果 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/barcode?id=scancode 7 | */ 8 | export const scanCode = promisify(uni.scanCode); 9 | -------------------------------------------------------------------------------- /src/showLoading/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 显示 loading 提示框 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/prompt?id=showloading 7 | */ 8 | export const showLoading = promisify(uni.showLoading); 9 | -------------------------------------------------------------------------------- /.markdownlint.json: -------------------------------------------------------------------------------- 1 | { 2 | "MD001": false, 3 | "MD003": false, 4 | "MD013": false, 5 | "MD022": false, 6 | "MD024": false, 7 | "MD025": false, 8 | "MD033": false, 9 | "MD036": false, 10 | "MD050": false 11 | } 12 | -------------------------------------------------------------------------------- /src/chooseImage/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 从本地相册选择图片或使用相机拍照 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/media/image?id=chooseimage 7 | */ 8 | export const chooseImage = promisify(uni.chooseImage); 9 | -------------------------------------------------------------------------------- /src/clearStorage/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 清理本地数据缓存 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/storage/storage?id=clearstorage 7 | */ 8 | export const clearStorage = promisify(uni.clearStorage); 9 | -------------------------------------------------------------------------------- /src/getBatteryInfo/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取设备电量 5 | * 6 | * 文档 https://uniapp.dcloud.net.cn/api/system/batteryInfo.html 7 | */ 8 | export const getBatteryInfo = promisify(uni.getBatteryInfo); 9 | -------------------------------------------------------------------------------- /src/getSystemInfo/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 异步获取系统信息 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/info?id=getsysteminfo 7 | */ 8 | export const getSystemInfo = promisify(uni.getSystemInfo); 9 | -------------------------------------------------------------------------------- /src/hideShareMenu/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 隐藏分享按钮 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/plugins/share?id=hidesharemenu 7 | */ 8 | export const hideShareMenu = promisify(uni.hideShareMenu); 9 | -------------------------------------------------------------------------------- /src/makePhoneCall/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 拨打电话 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/phone?id=makephonecall 7 | */ 8 | export const makePhoneCall = promisify(uni.makePhoneCall); 9 | -------------------------------------------------------------------------------- /src/navigateBack/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 关闭当前页面,返回上一页面或多级页面 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/router?id=navigateback 7 | */ 8 | export const navigateBack = promisify(uni.navigateBack); 9 | -------------------------------------------------------------------------------- /src/showShareMenu/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 显示分享按钮 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/plugins/share?id=showsharemenu 7 | */ 8 | export const showShareMenu = promisify(uni.showShareMenu); 9 | -------------------------------------------------------------------------------- /src/getLocation/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取当前的地理位置、速度 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/location/location?id=getlocation 7 | */ 8 | export const getLocation = promisify(uni.getLocation); 9 | -------------------------------------------------------------------------------- /src/getNetworkType/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取网络类型 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/network?id=getnetworktype 7 | */ 8 | export const getNetworkType = promisify(uni.getNetworkType); 9 | -------------------------------------------------------------------------------- /src/getStorage/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 从本地缓存中异步获取指定 key 对应的内容 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/storage/storage?id=getstorage 7 | */ 8 | export const getStorage = promisify(uni.getStorage); 9 | -------------------------------------------------------------------------------- /src/getUserProfile/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取用户信息 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/plugins/login?id=getUserProfile 7 | */ 8 | export const getUserProfile = promisify(uni.getUserProfile); 9 | -------------------------------------------------------------------------------- /src/requestPayment/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 支付 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/plugins/payment?id=requestpayment 7 | */ 8 | export const requestPayment = promisify(uni.requestPayment); 9 | -------------------------------------------------------------------------------- /src/showActionSheet/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 显示操作菜单 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/prompt?id=showactionsheet 7 | */ 8 | export const showActionSheet = promisify(uni.showActionSheet); 9 | -------------------------------------------------------------------------------- /src/switchTab/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 跳转到 TabBar 页面,并关闭其它所有非 TabBar 页面 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/router?id=switchtab 7 | */ 8 | export const switchTab = promisify(uni.switchTab); 9 | -------------------------------------------------------------------------------- /src/vibrateLong/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 使手机发生较长时间的振动(400ms) 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/vibrate?id=vibratelong 7 | */ 8 | export const vibrateLong = promisify(uni.vibrateLong); 9 | -------------------------------------------------------------------------------- /src/chooseLocation/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 打开地图选择位置。 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/location/location?id=chooselocation 7 | */ 8 | export const chooseLocation = promisify(uni.chooseLocation); 9 | -------------------------------------------------------------------------------- /src/chooseVideo/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 拍摄视频或从手机相册中选视频,返回视频的临时文件路径。 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/media/video?id=choosevideo 7 | */ 8 | export const chooseVideo = promisify(uni.chooseVideo); 9 | -------------------------------------------------------------------------------- /src/closeSocket/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 关闭 WebSocket 连接 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/request/websocket?id=closesocket 7 | */ 8 | export const closeSocket = () => promisify(uni.closeSocket); 9 | -------------------------------------------------------------------------------- /src/getExtConfig/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取第三方平台自定义的数据字段 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/other/get-extconfig?id=getextconfig 7 | */ 8 | export const getExtConfig = promisify(uni.getExtConfig); 9 | -------------------------------------------------------------------------------- /src/hideHomeButton/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 隐藏返回首页按钮 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/navigationbar?id=hidehomebutton 7 | */ 8 | export const hideHomeButton = promisify(uni.hideHomeButton); 9 | -------------------------------------------------------------------------------- /src/openLocation/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 使用地图查看位置 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/location/open-location?id=openlocation 7 | */ 8 | export const openLocation = promisify(uni.openLocation); 9 | -------------------------------------------------------------------------------- /src/openVideoEditor/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 打开视频编辑器 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/media/video?id=openvideoeditor 7 | */ 8 | export const openVideoEditor = promisify(uni.openVideoEditor); 9 | -------------------------------------------------------------------------------- /src/removeSavedFile/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 删除本地存储的文件 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/file/file?id=removesavedfile 7 | */ 8 | export const removeSavedFile = promisify(uni.removeSavedFile); 9 | -------------------------------------------------------------------------------- /src/setTabBarItem/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 动态设置 TabBar 某一项的内容 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/tabbar?id=settabbaritem 7 | */ 8 | export const setTabBarItem = promisify(uni.setTabBarItem); 9 | -------------------------------------------------------------------------------- /src/setTabBarStyle/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 动态设置 TabBar 的整体样式 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/tabbar?id=settabbarstyle 7 | */ 8 | export const setTabBarStyle = promisify(uni.setTabBarStyle); 9 | -------------------------------------------------------------------------------- /src/shareWithSystem/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 调用系统分享 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/plugins/share?id=sharewithsystem 7 | */ 8 | export const shareWithSystem = promisify(uni.shareWithSystem); 9 | -------------------------------------------------------------------------------- /src/vibrateShort/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 使手机发生较短时间的振动(15ms) 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/vibrate?id=vibrateshort 7 | */ 8 | export const vibrateShort = promisify(uni.vibrateShort); 9 | -------------------------------------------------------------------------------- /src/closePreviewImage/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 预览图片 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/media/image?id=closepreviewimage 7 | */ 8 | export const closePreviewImage = promisify(uni.closePreviewImage); 9 | -------------------------------------------------------------------------------- /src/getBLEDeviceRSSI/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取蓝牙设备的信号强度。 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/ble?id=getBLEDeviceRSSI 7 | */ 8 | export const getBLEDeviceRSSI = promisify(uni.getBLEDeviceRSSI); 9 | -------------------------------------------------------------------------------- /src/getPushClientId/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取客户端唯一的推送标识 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/plugins/push.html#getpushclientid 7 | */ 8 | export const getPushClientId = promisify(uni.getPushClientId); 9 | -------------------------------------------------------------------------------- /src/getSavedFileInfo/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取本地文件的文件信息 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/file/file?id=getsavedfileinfo 7 | */ 8 | export const getSavedFileInfo = promisify(uni.getSavedFileInfo); 9 | -------------------------------------------------------------------------------- /src/getSavedFileList/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取本地已保存的文件列表 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/file/file?id=getsavedfilelist 7 | */ 8 | export const getSavedFileList = promisify(uni.getSavedFileList); 9 | -------------------------------------------------------------------------------- /src/openSetting/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 调起客户端小程序设置界面,返回用户设置的操作结果 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/other/authorize?id=opensetting 7 | */ 8 | export const openSetting = promisify(uni.openSetting); 9 | -------------------------------------------------------------------------------- /src/removeStorage/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 从本地缓存中异步移除指定 key 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/storage/storage?id=removestorage 7 | */ 8 | export const removeStorage = promisify(uni.removeStorage); 9 | -------------------------------------------------------------------------------- /src/setKeepScreenOn/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 设置是否保持常亮状态 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/brightness?id=setkeepscreenon 7 | */ 8 | export const setKeepScreenOn = promisify(uni.setKeepScreenOn); 9 | -------------------------------------------------------------------------------- /src/setTabBarBadge/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 为 TabBar 某一项的右上角添加文本 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/tabbar?id=settabbarbadge 7 | */ 8 | export const setTabBarBadge = promisify(uni.setTabBarBadge); 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 2 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /src/addPhoneContact/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 增加手机通讯录联系人和联系方式 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/contact?id=addphonecontact 7 | */ 8 | export const addPhoneContact = promisify(uni.addPhoneContact); 9 | -------------------------------------------------------------------------------- /src/chooseFile/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 从本地选择文件 5 | * 6 | * 仅支持H5 7 | * 8 | * 文档 http://uniapp.dcloud.io/api/media/file?id=chooseFile 9 | */ 10 | export const chooseFile = promisify(uni.chooseFile); 11 | -------------------------------------------------------------------------------- /src/connectSocket/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 创建一个 WebSocket 连接 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/request/websocket?id=connectsocket 7 | */ 8 | export const connectSocket = () => promisify(uni.connectSocket); 9 | -------------------------------------------------------------------------------- /src/createInnerAudioContext/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 创建并返回 audio 上下文 audioContext 对象 3 | * 4 | * 文档 http://uniapp.dcloud.io/api/media/audio-context?id=createinneraudiocontext 5 | */ 6 | export const createInnerAudioContext = () => uni.createInnerAudioContext(); 7 | -------------------------------------------------------------------------------- /src/createPushMessage/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 创建本地通知栏消息 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/plugins/push.html#createpushmessage 7 | */ 8 | export const createPushMessage = promisify(uni.createPushMessage); 9 | -------------------------------------------------------------------------------- /src/getCheckBoxState/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取一键登录条款勾选框状态 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/plugins/login?id=getCheckBoxState 7 | */ 8 | export const getCheckBoxState = promisify(uni.getCheckBoxState); 9 | -------------------------------------------------------------------------------- /src/getClipboardData/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获得系统剪贴板的内容 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/clipboard?id=getclipboarddata 7 | */ 8 | export const getClipboardData = promisify(uni.getClipboardData); 9 | -------------------------------------------------------------------------------- /src/getStorageInfo/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 异步获取当前 storage 的相关信息 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/storage/storage?id=getstorageinfo 7 | */ 8 | export const getStorageInfo = promisify(uni.getStorageInfo); 9 | -------------------------------------------------------------------------------- /src/setBackgroundColor/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 动态设置窗口的背景色 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/bgcolor?id=setbackgroundcolor 7 | */ 8 | export const setBackgroundColor = promisify(uni.setBackgroundColor); 9 | -------------------------------------------------------------------------------- /src/setClipboardData/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 设置系统剪贴板的内容 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/clipboard?id=setclipboarddata 7 | */ 8 | export const setClipboardData = promisify(uni.setClipboardData); 9 | -------------------------------------------------------------------------------- /src/closeBLEConnection/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 断开与低功耗蓝牙设备的连接 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/ble?id=closebleconnection 7 | */ 8 | export const closeBLEConnection = promisify(uni.closeBLEConnection); 9 | -------------------------------------------------------------------------------- /src/createBLEConnection/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 连接低功耗蓝牙设备 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/ble?id=createbleconnection 7 | */ 8 | export const createBLEConnection = promisify(uni.createBLEConnection); 9 | -------------------------------------------------------------------------------- /src/getSelectedTextRange/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取输入框的光标位置 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/key?id=getselectedtextrange 7 | */ 8 | export const getSelectedTextRange = promisify(uni.getSelectedTextRange); 9 | -------------------------------------------------------------------------------- /src/hideTabBarRedDot/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 隐藏 TabBar 某一项的右上角的红点 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/tabbar?id=hidetabbarreddot 7 | */ 8 | export const hideTabBarRedDot = promisify(uni.hideTabBarRedDot); 9 | -------------------------------------------------------------------------------- /src/removeTabBarBadge/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 移除 TabBar 某一项右上角的文本 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/tabbar?id=removetabbarbadge 7 | */ 8 | export const removeTabBarBadge = promisify(uni.removeTabBarBadge); 9 | -------------------------------------------------------------------------------- /src/setStorage/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 将数据存储在本地缓存中指定的 key 中,会覆盖掉原来该 key 对应的内容 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/storage/storage?id=setstorage 7 | */ 8 | export const setStorage = promisify(uni.setStorage); 9 | -------------------------------------------------------------------------------- /src/showTabBarRedDot/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 显示 TabBar 某一项的右上角的红点 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/tabbar?id=showtabbarreddot 7 | */ 8 | export const showTabBarRedDot = promisify(uni.showTabBarRedDot); 9 | -------------------------------------------------------------------------------- /src/startPullDownRefresh/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 开始下拉刷新 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/pulldown?id=startpulldownrefresh 7 | */ 8 | export const startPullDownRefresh = promisify(uni.startPullDownRefresh); 9 | -------------------------------------------------------------------------------- /src/getBLEDeviceServices/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取蓝牙设备的所有服务 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/ble?id=getbledeviceservices 7 | */ 8 | export const getBLEDeviceServices = promisify(uni.getBLEDeviceServices); 9 | -------------------------------------------------------------------------------- /src/getScreenBrightness/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取屏幕亮度 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/brightness?id=getscreenbrightness 7 | */ 8 | export const getScreenBrightness = promisify(uni.getScreenBrightness); 9 | -------------------------------------------------------------------------------- /src/openDocument/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 新开页面打开文档,支持格式 doc、xls、ppt、pdf、docx、xlsx、pptx 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/file/file?id=opendocument 7 | */ 8 | export const openDocument = promisify(uni.openDocument); 9 | -------------------------------------------------------------------------------- /src/setScreenBrightness/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 设置屏幕亮度 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/brightness?id=setscreenbrightness 7 | */ 8 | export const setScreenBrightness = promisify(uni.setScreenBrightness); 9 | -------------------------------------------------------------------------------- /src/closeBluetoothAdapter/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 关闭蓝牙模块 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/bluetooth?id=closebluetoothadapter 7 | */ 8 | export const closeBluetoothAdapter = promisify(uni.closeBluetoothAdapter); 9 | -------------------------------------------------------------------------------- /src/getBluetoothDevices/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取已搜索到的蓝牙设备 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/bluetooth?id=getbluetoothdevices 7 | */ 8 | export const getBluetoothDevices = promisify(uni.getBluetoothDevices); 9 | -------------------------------------------------------------------------------- /src/openAppAuthorizeSetting/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 跳转系统授权管理页 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/openappauthorizesetting 7 | */ 8 | export const openAppAuthorizeSetting = promisify(uni.openAppAuthorizeSetting); 9 | -------------------------------------------------------------------------------- /src/openBluetoothAdapter/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 初始化蓝牙模块 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/bluetooth?id=openbluetoothadapter 7 | */ 8 | export const openBluetoothAdapter = promisify(uni.openBluetoothAdapter); 9 | -------------------------------------------------------------------------------- /src/setNavigationBarColor/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 设置导航条颜色 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/navigationbar?id=setnavigationbarcolor 7 | */ 8 | export const setNavigationBarColor = promisify(uni.setNavigationBarColor); 9 | -------------------------------------------------------------------------------- /src/saveImageToPhotosAlbum/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 保存图片到系统相册 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/media/image?id=saveimagetophotosalbum 7 | */ 8 | export const saveImageToPhotosAlbum = promisify(uni.saveImageToPhotosAlbum); 9 | -------------------------------------------------------------------------------- /src/saveVideoToPhotosAlbum/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 保存视频到系统相册 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/media/video?id=savevideotophotosalbum 7 | */ 8 | export const saveVideoToPhotosAlbum = promisify(uni.saveVideoToPhotosAlbum); 9 | -------------------------------------------------------------------------------- /src/sendSocketMessage/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 通过 WebSocket 连接发送数据 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/request/websocket?id=sendsocketmessage 7 | */ 8 | export const sendSocketMessage = () => promisify(uni.sendSocketMessage); 9 | -------------------------------------------------------------------------------- /src/setBackgroundTextStyle/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 动态设置窗口的背景色 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/bgcolor?id=setbackgroundtextstyle 7 | */ 8 | export const setBackgroundTextStyle = promisify(uni.setBackgroundTextStyle); 9 | -------------------------------------------------------------------------------- /src/setNavigationBarTitle/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 动态设置当前页面的标题 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/navigationbar?id=setnavigationbartitle 7 | */ 8 | export const setNavigationBarTitle = promisify(uni.setNavigationBarTitle); 9 | -------------------------------------------------------------------------------- /src/getBackgroundAudioManager/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 获取全局唯一的背景音频管理器 backgroundAudioManager 3 | * 4 | * 文档 http://uniapp.dcloud.io/api/media/background-audio-manager?id=getbackgroundaudiomanager 5 | */ 6 | export const getBackgroundAudioManager = () => uni.getBackgroundAudioManager(); 7 | -------------------------------------------------------------------------------- /src/hideNavigationBarLoading/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 隐藏导航条加载动画 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/navigationbar?id=hidenavigationbarloading 7 | */ 8 | export const hideNavigationBarLoading = promisify(uni.hideNavigationBarLoading); 9 | -------------------------------------------------------------------------------- /src/setEnableDebug/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | /** 3 | * 设置是否打开调试开关 4 | * 5 | * 此开关对正式版也能生效 6 | * 7 | * 文档 http://uniapp.dcloud.io/api/other/set-enable-debug?id=setenabledebug 8 | */ 9 | export const setEnableDebug = promisify(uni.setEnableDebug); 10 | -------------------------------------------------------------------------------- /src/chooseInvoiceTitle/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 选择用户的发票抬头,需要用户授权 scope.invoiceTitle 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/other/invoice-title?id=chooseinvoicetitle 7 | */ 8 | export const chooseInvoiceTitle = promisify(uni.chooseInvoiceTitle); 9 | -------------------------------------------------------------------------------- /src/getBluetoothAdapterState/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取本机蓝牙适配器状态 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/bluetooth?id=getbluetoothadapterstate 7 | */ 8 | export const getBluetoothAdapterState = promisify(uni.getBluetoothAdapterState); 9 | -------------------------------------------------------------------------------- /src/showNavigationBarLoading/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 在当前页面显示导航条加载动画 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/ui/navigationbar?id=shownavigationbarloading 7 | */ 8 | export const showNavigationBarLoading = promisify(uni.showNavigationBarLoading); 9 | -------------------------------------------------------------------------------- /src/navigateToMiniProgram/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 调起客户端小程序设置界面,返回用户设置的操作结果 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/other/open-miniprogram?id=navigatetominiprogram 7 | */ 8 | export const navigateToMiniProgram = promisify(uni.navigateToMiniProgram); 9 | -------------------------------------------------------------------------------- /src/startSoterAuthentication/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 开始 SOTER 生物认证 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/authentication?id=startsoterauthentication 7 | */ 8 | export const startSoterAuthentication = promisify(uni.startSoterAuthentication); 9 | -------------------------------------------------------------------------------- /src/getApp/index.ts: -------------------------------------------------------------------------------- 1 | const _getApp = () => 2 | new Promise>((resolve, reject) => { 3 | try { 4 | const app = getApp(); 5 | resolve(app); 6 | } catch (error) { 7 | reject(error); 8 | } 9 | }); 10 | 11 | export { _getApp as getApp }; 12 | -------------------------------------------------------------------------------- /src/getBLEDeviceCharacteristics/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取蓝牙设备指定服务中所有特征值 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/ble?id=getbledevicecharacteristics 7 | */ 8 | export const getBLEDeviceCharacteristics = promisify(uni.getBLEDeviceCharacteristics); 9 | -------------------------------------------------------------------------------- /src/readBLECharacteristicValue/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 读取低功耗蓝牙设备指定特征值的二进制数据值 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/ble?id=readblecharacteristicvalue 7 | */ 8 | export const readBLECharacteristicValue = promisify(uni.readBLECharacteristicValue); 9 | -------------------------------------------------------------------------------- /src/createCanvasContext/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 创建 canvas 绘图上下文 3 | * 4 | * 文档 http://uniapp.dcloud.io/api/canvas/createCanvasContext?id=createcanvascontext 5 | */ 6 | export const createCanvasContext = (canvasId: string, componentInstance?: any) => 7 | uni.createCanvasContext(canvasId, componentInstance); 8 | -------------------------------------------------------------------------------- /src/writeBLECharacteristicValue/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 向低功耗蓝牙设备指定特征值写入二进制数据 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/ble?id=writeblecharacteristicvalue 7 | */ 8 | export const writeBLECharacteristicValue = promisify(uni.writeBLECharacteristicValue); 9 | -------------------------------------------------------------------------------- /src/createVideoContext/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 创建并返回 video 上下文 videoContext 对象 3 | * 4 | * 文档 http://uniapp.dcloud.io/api/media/video-context?id=createvideocontext 5 | */ 6 | export const createVideoContext = (videoId: string, componentInstance?: any) => 7 | uni.createVideoContext(videoId, componentInstance); 8 | -------------------------------------------------------------------------------- /src/getConnectedBluetoothDevices/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 根据 uuid 获取处于已连接的设备 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/bluetooth?id=getconnectedbluetoothdevices 7 | */ 8 | export const getConnectedBluetoothDevices = promisify(uni.getConnectedBluetoothDevices); 9 | -------------------------------------------------------------------------------- /src/startBluetoothDevicesDiscovery/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 开始搜索附近的蓝牙设备 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/bluetooth?id=startbluetoothdevicesdiscovery 7 | */ 8 | export const startBluetoothDevicesDiscovery = promisify(uni.startBluetoothDevicesDiscovery); 9 | -------------------------------------------------------------------------------- /src/stopBluetoothDevicesDiscovery/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 停止搜寻附近的蓝牙外围设备 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/bluetooth?id=stopbluetoothdevicesdiscovery 7 | */ 8 | export const stopBluetoothDevicesDiscovery = promisify(uni.stopBluetoothDevicesDiscovery); 9 | -------------------------------------------------------------------------------- /src/checkIsSoterEnrolledInDevice/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取设备内是否录入指纹等生物信息 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/authentication?id=checkissoterenrolledindevice 7 | */ 8 | export const checkIsSoterEnrolledInDevice = promisify(uni.checkIsSoterEnrolledInDevice); 9 | -------------------------------------------------------------------------------- /src/navigateBackMiniProgram/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 跳转回上一个小程序,只有当另一个小程序跳转到当前小程序时才会能调用成功 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/other/open-miniprogram?id=navigatebackminiprogram 7 | */ 8 | export const navigateBackMiniProgram = promisify(uni.navigateBackMiniProgram); 9 | -------------------------------------------------------------------------------- /playground/src/App.vue: -------------------------------------------------------------------------------- 1 | 14 | -------------------------------------------------------------------------------- /src/createLivePusherContext/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 创建 live-pusher 上下文 livePusherContext 对象 3 | * 4 | * 文档 http://uniapp.dcloud.io/api/media/camera-context 5 | */ 6 | export const createLivePusherContext = (livePusherId: string, componentInstance?: any) => 7 | uni.createLivePusherContext(livePusherId, componentInstance); 8 | -------------------------------------------------------------------------------- /src/chooseAddress/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取用户收货地址 5 | * 6 | * 调起用户编辑收货地址原生界面,并在编辑完成后返回用户选择的地址,需要用户授权 scope.address 7 | * 8 | * 文档 http://uniapp.dcloud.io/api/other/choose-address?id=chooseaddress 9 | */ 10 | export const chooseAddress = promisify(uni.chooseAddress); 11 | -------------------------------------------------------------------------------- /src/setBLEMTU/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 设置蓝牙最大传输单元 5 | * 6 | * 需在 createBLEConnection 调用成功后调用,mtu 设置范围 (22, 512) 7 | * 8 | * 安卓 5.1 以上有效 9 | * 10 | * 文档 http://uniapp.dcloud.io/api/system/ble?id=setBLEMTU 11 | */ 12 | export const setBLEMTU = promisify(uni.setBLEMTU); 13 | -------------------------------------------------------------------------------- /src/checkIsSupportSoterAuthentication/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 获取本机支持的 SOTER 生物认证方式 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/authentication?id=checkissupportsoterauthentication 7 | */ 8 | export const checkIsSupportSoterAuthentication = promisify(uni.checkIsSupportSoterAuthentication); 9 | -------------------------------------------------------------------------------- /src/notifyBLECharacteristicValueChange/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 启用低功耗蓝牙设备特征值变化时的notify功能,订阅特征值 5 | * 6 | * 文档 http://uniapp.dcloud.io/api/system/ble?id=notifyblecharacteristicvaluechange 7 | */ 8 | export const notifyBLECharacteristicValueChange = promisify(uni.notifyBLECharacteristicValueChange); 9 | -------------------------------------------------------------------------------- /src/chooseMedia/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 需要基础库: `2.10.0` 5 | * 6 | * 在插件中使用:需要基础库 `2.11.1` 7 | * 8 | * 拍摄或从手机相册中选择图片或视频。 9 | * 10 | * 文档 https://developers.weixin.qq.com/miniprogram/dev/api/media/video/wx.chooseMedia.html 11 | */ 12 | export const chooseMedia = promisify(uni.chooseMedia); 13 | -------------------------------------------------------------------------------- /src/createMediaContainer/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 需要基础库: `2.9.0` 3 | * 4 | * 在插件中使用:需要基础库 `2.10.0` 5 | * 6 | * 创建音视频处理容器,最终可将容器中的轨道合成一个视频 7 | * 8 | * 文档 9 | * https://developers.weixin.qq.com/miniprogram/dev/api/media/video-processing/wx.createMediaContainer.html 10 | */ 11 | export const createMediaContainer = () => uni.createMediaContainer(); 12 | -------------------------------------------------------------------------------- /playground/src/pages.json: -------------------------------------------------------------------------------- 1 | { 2 | "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages 3 | { 4 | "path": "pages/index/index", 5 | "style": { 6 | "navigationBarTitleText": "uni-app" 7 | } 8 | } 9 | ], 10 | "globalStyle": { 11 | "navigationBarTextStyle": "black", 12 | "navigationBarTitleText": "uni-app", 13 | "navigationBarBackgroundColor": "#F8F8F8", 14 | "backgroundColor": "#F8F8F8" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@tsconfig/node18", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "lib": ["DOM", "ESNext"], 6 | "module": "ESNext", 7 | "moduleResolution": "Bundler", 8 | "target": "ESNext", 9 | "resolveJsonModule": true, 10 | "types": ["@dcloudio/types", "node"] 11 | }, 12 | "include": ["**/*.js", "**/*.cjs", "**/*.mjs", "**/*.ts", "**/*.cts", "**/*.mts"], 13 | "exclude": ["**/node_modules", "**/dist", "playground"] 14 | } 15 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 改动日志 2 | 3 | ## 0.2.1 (2023-10-17) 4 | 5 | - fix: 修复类型推导问题 6 | 7 | ## 0.2.0 (2023-06-21) 8 | 9 | - feat!: 要求 `typescript` 为 `^4.8.0 || ^5.0.0` 10 | - fix: 修复类型错误和赋值错误 11 | 12 | ## 0.1.5 (2023-02-16) 13 | 14 | - build: 切换到 `unbuild` 15 | 16 | ## 0.1.4 (2023-01-04) 17 | 18 | - fix: 修复导入 19 | - build: 切换到 `rollup` 20 | 21 | ## 0.1.3 (2022-12-28) 22 | 23 | - fix: 修复导出 24 | 25 | ## 0.1.2 (2022-12-26) 26 | 27 | - fix: 修复类型 28 | 29 | ## 0.1.1 (2022-12-23) 30 | 31 | - fix: 修复构建 32 | 33 | ## 0.1.0 (2022-12-23) 34 | 35 | - 初次正式发布 36 | -------------------------------------------------------------------------------- /src/chooseMessageFile/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 需要基础库: `2.5.0` 5 | * 6 | * 在插件中使用:不支持 7 | * 8 | * 从客户端会话选择文件。 9 | * 10 | * ```js 11 | * wx.chooseMessageFile({ 12 | * count: 10, 13 | * type: 'image', 14 | * success(res) { 15 | * // tempFilePath可以作为img标签的src属性显示图片 16 | * const tempFilePaths = res.tempFiles; 17 | * }, 18 | * }); 19 | * ``` 20 | * 21 | * 文档 https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.chooseMessageFile.html 22 | */ 23 | export const chooseMessageFile = promisify(uni.chooseMessageFile); 24 | -------------------------------------------------------------------------------- /playground/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "useDefineForClassFields": true, 5 | "module": "esnext", 6 | "moduleResolution": "node", 7 | "strict": true, 8 | "jsx": "preserve", 9 | "sourceMap": true, 10 | "resolveJsonModule": true, 11 | "esModuleInterop": true, 12 | "lib": ["esnext", "dom"], 13 | "types": ["vite/client", "@dcloudio/types"] 14 | }, 15 | "vueCompilerOptions": { 16 | "experimentalRuntimeMode": "runtime-uni-app", 17 | "nativeTags": ["block", "component", "template", "slot"] 18 | }, 19 | "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"] 20 | } 21 | -------------------------------------------------------------------------------- /src/chooseInvoice/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 需要基础库: `2.3.0` 5 | * 6 | * 在插件中使用:需要基础库 `2.16.1` 7 | * 8 | * 选择用户已有的发票。 9 | * 10 | * 通过 cardId 和 encryptCode 获得报销发票的信息。 11 | * 12 | * 请参考 [微信电子发票文档](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=21517918939oae3U) 13 | * 中,「查询报销发票信息」部分。 14 | * 15 | * 其中 `access_token` 的获取请参考 16 | * [auth.getAccessToken](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html) 17 | * 文档 18 | * 19 | * 文档 https://developers.weixin.qq.com/miniprogram/dev/api/open-api/invoice/wx.chooseInvoice.html 20 | */ 21 | export const chooseInvoice = promisify(uni.chooseInvoice); 22 | -------------------------------------------------------------------------------- /src/createLivePlayerContext/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 需要基础库: `1.7.0` 3 | * 4 | * 在插件中使用:需要基础库 `1.9.6` 5 | * 6 | * 创建 [live-player](https://developers.weixin.qq.com/miniprogram/dev/component/live-player.html) 上下文 7 | * [LivePlayerContext](https://developers.weixin.qq.com/miniprogram/dev/api/media/live/LivePlayerContext.html) 8 | * 对象。建议使用 9 | * [uni.createSelectorQuery](https://developers.weixin.qq.com/miniprogram/dev/api/wxml/wx.createSelectorQuery.html) 10 | * 获取 context 对象。 11 | * 12 | * 文档 13 | * https://developers.weixin.qq.com/miniprogram/dev/api/media/live/wx.createLivePlayerContext.html 14 | */ 15 | export const createLivePlayerContext = (livePlayerId: string, componentInstance?: any) => 16 | uni.createLivePlayerContext(livePlayerId, componentInstance); 17 | -------------------------------------------------------------------------------- /playground/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - "v*" 7 | 8 | jobs: 9 | release: 10 | permissions: 11 | id-token: write 12 | contents: write 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v6 17 | with: 18 | fetch-depth: 0 19 | 20 | - name: Install pnpm 21 | uses: pnpm/action-setup@v4 22 | 23 | - name: Setup Node.js 24 | uses: actions/setup-node@v6 25 | with: 26 | node-version-file: .node-version 27 | cache: pnpm 28 | registry-url: https://registry.npmjs.org 29 | 30 | - name: Setup corepack 31 | run: npm install -f -g npm@latest corepack@latest && corepack enable 32 | 33 | - name: GitHub Release 34 | run: pnpx changelogithub 35 | env: 36 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 37 | 38 | - name: Install Dependencies 39 | run: pnpm install 40 | 41 | - name: Publish to NPM 42 | run: pnpm -r publish --access public --no-git-checks 43 | -------------------------------------------------------------------------------- /playground/src/pages/index/index.vue: -------------------------------------------------------------------------------- 1 | 14 | 15 | 23 | 24 | 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-present uni-helper 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/request/index.ts: -------------------------------------------------------------------------------- 1 | import { mountTaskMethodToPromise, noop } from '../utils'; 2 | import { RequestPromise } from '../types'; 3 | 4 | /** 5 | * 发起网络请求 6 | * 7 | * 文档 http://uniapp.dcloud.io/api/request/request?id=request 8 | */ 9 | export function request( 10 | urlOrOptions: string | UniApp.RequestOptions, 11 | options?: UniApp.RequestOptions, 12 | ) { 13 | const _options = 14 | typeof urlOrOptions === 'string' 15 | ? { ...options, url: urlOrOptions, complete: options?.complete ?? noop } 16 | : { 17 | ...urlOrOptions, 18 | ...options, 19 | complete: urlOrOptions?.complete ?? options?.complete ?? noop, 20 | }; 21 | const { success, fail } = _options; 22 | 23 | let task: UniApp.RequestTask | undefined; 24 | const promise: RequestPromise = new Promise((resolve, reject) => { 25 | _options.success = (r) => { 26 | success?.(r); 27 | resolve(r); 28 | }; 29 | _options.fail = (e) => { 30 | fail?.(e); 31 | reject(e); 32 | }; 33 | task = uni.request(_options); 34 | }) as unknown as RequestPromise; 35 | 36 | mountTaskMethodToPromise(task, promise); 37 | 38 | return promise; 39 | } 40 | -------------------------------------------------------------------------------- /src/uploadFile/index.ts: -------------------------------------------------------------------------------- 1 | import { mountTaskMethodToPromise, noop } from '../utils'; 2 | import { UploadFilePromise } from '../types'; 3 | 4 | /** 5 | * 上传文件 6 | * 7 | * 文档 http://uniapp.dcloud.io/api/request/network-file?id=uploadfile 8 | */ 9 | export function uploadFile( 10 | urlOrOptions: string | UniApp.UploadFileOption, 11 | options?: UniApp.UploadFileOption, 12 | ) { 13 | const _options = 14 | typeof urlOrOptions === 'string' 15 | ? { ...options, url: urlOrOptions, complete: options?.complete ?? noop } 16 | : { 17 | ...urlOrOptions, 18 | ...options, 19 | complete: urlOrOptions?.complete ?? options?.complete ?? noop, 20 | }; 21 | const { success, fail } = _options; 22 | 23 | let task: UniApp.UploadTask | undefined; 24 | const promise: UploadFilePromise = new Promise((resolve, reject) => { 25 | _options.success = (r) => { 26 | success?.(r); 27 | resolve(r); 28 | }; 29 | _options.fail = (e) => { 30 | fail?.(e); 31 | reject(e); 32 | }; 33 | task = uni.uploadFile(_options); 34 | }) as unknown as UploadFilePromise; 35 | 36 | mountTaskMethodToPromise(task, promise); 37 | 38 | return promise; 39 | } 40 | -------------------------------------------------------------------------------- /src/downloadFile/index.ts: -------------------------------------------------------------------------------- 1 | import { mountTaskMethodToPromise, noop } from '../utils'; 2 | import { DownloadFilePromise } from '../types'; 3 | 4 | /** 5 | * 下载文件 6 | * 7 | * 文档 http://uniapp.dcloud.io/api/request/network-file?id=downloadfile 8 | */ 9 | export function downloadFile( 10 | urlOrOptions: string | UniApp.DownloadFileOption, 11 | options?: UniApp.DownloadFileOption, 12 | ) { 13 | const _options = 14 | typeof urlOrOptions === 'string' 15 | ? { ...options, url: urlOrOptions, complete: options?.complete ?? noop } 16 | : { 17 | ...urlOrOptions, 18 | ...options, 19 | complete: urlOrOptions?.complete ?? options?.complete ?? noop, 20 | }; 21 | const { success, fail } = _options; 22 | 23 | let task: UniApp.DownloadTask | undefined; 24 | const promise: DownloadFilePromise = new Promise((resolve, reject) => { 25 | _options.success = (r) => { 26 | success?.(r); 27 | resolve(r); 28 | }; 29 | _options.fail = (e) => { 30 | fail?.(e); 31 | reject(e); 32 | }; 33 | task = uni.downloadFile(_options); 34 | }) as unknown as DownloadFilePromise; 35 | 36 | mountTaskMethodToPromise(task, promise); 37 | 38 | return promise; 39 | } 40 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | pull_request: 9 | branches: 10 | - main 11 | 12 | merge_group: {} 13 | 14 | jobs: 15 | test: 16 | runs-on: ${{ matrix.os }} 17 | 18 | strategy: 19 | matrix: 20 | os: [ubuntu-latest, macos-latest, windows-latest] 21 | node_version: [20, 22, 24] 22 | fail-fast: false 23 | 24 | steps: 25 | - name: Set git to use LF 26 | run: | 27 | git config --global core.autocrlf false 28 | git config --global core.eol lf 29 | 30 | - name: Checkout 31 | uses: actions/checkout@v6 32 | 33 | - name: Install pnpm 34 | uses: pnpm/action-setup@v4 35 | 36 | - name: Setup Node.js ${{ matrix.node_version }} 37 | uses: actions/setup-node@v6 38 | with: 39 | node-version: ${{ matrix.node_version }} 40 | cache: pnpm 41 | registry-url: https://registry.npmjs.org 42 | 43 | - name: Setup corepack 44 | run: npm install -f -g npm@latest corepack@latest && corepack enable 45 | 46 | - name: Install Dependencies 47 | run: pnpm install 48 | 49 | - name: Build 50 | run: pnpm build 51 | 52 | - name: Type Check 53 | run: pnpm check:types 54 | -------------------------------------------------------------------------------- /src/utils.ts: -------------------------------------------------------------------------------- 1 | import { DownloadFilePromise, RequestPromise, UploadFilePromise } from './types'; 2 | 3 | export function noop() {} 4 | 5 | export function promisify void>(callback: F) { 6 | return (...args: Parameters) => { 7 | type Options = Parameters[0]; 8 | const options = args[0] as Options; 9 | return new Promise['success']>>[0]>( 10 | (resolve, reject) => { 11 | callback({ 12 | ...options, 13 | success: (result: any) => { 14 | options?.success?.(result); 15 | resolve(result); 16 | }, 17 | fail: (error: any) => { 18 | options?.fail?.(error); 19 | reject(error); 20 | }, 21 | }); 22 | }, 23 | ); 24 | }; 25 | } 26 | 27 | export function mountTaskMethodToPromise( 28 | task?: UniApp.RequestTask | UniApp.UploadTask | UniApp.DownloadTask, 29 | promise?: RequestPromise | DownloadFilePromise | UploadFilePromise, 30 | ) { 31 | if (!task || !promise) return; 32 | for (const fn of [ 33 | 'onHeadersReceived', 34 | 'offHeadersReceived', 35 | 'onChunkReceived', 36 | 'offChunkReceived', 37 | 'onProgressUpdate', 38 | 'offProgressUpdate', 39 | ] as const) { 40 | if (fn in task) { 41 | // @ts-expect-error no types 42 | promise[fn] = task[fn].bind(task); 43 | } 44 | } 45 | promise.abort = () => { 46 | task?.abort(); 47 | return promise; 48 | }; 49 | } 50 | -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | export interface TaskPromise extends Promise { 2 | abort: () => void; 3 | onHeadersReceived: (callback: (result: { header: Record }) => void) => void; 4 | offHeadersReceived: (callback: (result: { header: Record }) => void) => void; 5 | } 6 | 7 | export interface RequestPromise extends TaskPromise { 8 | onChunkReceived: (callback: (result: { data: ArrayBuffer }) => void) => void; 9 | offChunkReceived: (callback?: (result: { data: ArrayBuffer }) => void) => void; 10 | } 11 | 12 | export interface DownloadFilePromise extends TaskPromise { 13 | onProgressUpdate: ( 14 | callback: (result: { 15 | progress: number; 16 | totalBytesWritten: number; 17 | totalBytesExpectedToWrite: number; 18 | }) => void, 19 | ) => void; 20 | offProgressUpdate: ( 21 | callback: (result: { 22 | progress: number; 23 | totalBytesWritten: number; 24 | totalBytesExpectedToWrite: number; 25 | }) => void, 26 | ) => void; 27 | } 28 | 29 | export interface UploadFilePromise 30 | extends TaskPromise { 31 | onProgressUpdate: ( 32 | callback: (result: { 33 | progress: number; 34 | totalBytesSent: number; 35 | totalBytesExpectedToSend: number; 36 | }) => void, 37 | ) => void; 38 | offProgressUpdate: ( 39 | callback: (result: { 40 | progress: number; 41 | totalBytesSent: number; 42 | totalBytesExpectedToSend: number; 43 | }) => void, 44 | ) => void; 45 | } 46 | -------------------------------------------------------------------------------- /playground/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "uni-preset-vue", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "build:app": "uni build -p app", 6 | "build:app-android": "uni build -p app-android", 7 | "build:app-ios": "uni build -p app-ios", 8 | "build:custom": "uni build -p", 9 | "build:h5": "uni build", 10 | "build:h5:ssr": "uni build --ssr", 11 | "build:mp-alipay": "uni build -p mp-alipay", 12 | "build:mp-baidu": "uni build -p mp-baidu", 13 | "build:mp-kuaishou": "uni build -p mp-kuaishou", 14 | "build:mp-lark": "uni build -p mp-lark", 15 | "build:mp-qq": "uni build -p mp-qq", 16 | "build:mp-toutiao": "uni build -p mp-toutiao", 17 | "build:mp-weixin": "uni build -p mp-weixin", 18 | "build:quickapp-webview": "uni build -p quickapp-webview", 19 | "build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei", 20 | "build:quickapp-webview-union": "uni build -p quickapp-webview-union", 21 | "dev:app": "uni -p app", 22 | "dev:app-android": "uni -p app-android", 23 | "dev:app-ios": "uni -p app-ios", 24 | "dev:custom": "uni -p", 25 | "dev:h5": "uni", 26 | "dev:h5:ssr": "uni --ssr", 27 | "dev:mp-alipay": "uni -p mp-alipay", 28 | "dev:mp-baidu": "uni -p mp-baidu", 29 | "dev:mp-kuaishou": "uni -p mp-kuaishou", 30 | "dev:mp-lark": "uni -p mp-lark", 31 | "dev:mp-qq": "uni -p mp-qq", 32 | "dev:mp-toutiao": "uni -p mp-toutiao", 33 | "dev:mp-weixin": "uni -p mp-weixin", 34 | "dev:quickapp-webview": "uni -p quickapp-webview", 35 | "dev:quickapp-webview-huawei": "uni -p quickapp-webview-huawei", 36 | "dev:quickapp-webview-union": "uni -p quickapp-webview-union" 37 | }, 38 | "dependencies": { 39 | "@dcloudio/uni-app": "3.0.0-3081220230817001", 40 | "@dcloudio/uni-app-plus": "3.0.0-3081220230817001", 41 | "@dcloudio/uni-components": "3.0.0-3081220230817001", 42 | "@dcloudio/uni-h5": "3.0.0-3081220230817001", 43 | "@dcloudio/uni-mp-alipay": "3.0.0-3081220230817001", 44 | "@dcloudio/uni-mp-baidu": "3.0.0-3081220230817001", 45 | "@dcloudio/uni-mp-kuaishou": "3.0.0-3081220230817001", 46 | "@dcloudio/uni-mp-lark": "3.0.0-3081220230817001", 47 | "@dcloudio/uni-mp-qq": "3.0.0-3081220230817001", 48 | "@dcloudio/uni-mp-toutiao": "3.0.0-3081220230817001", 49 | "@dcloudio/uni-mp-weixin": "3.0.0-3081220230817001", 50 | "@dcloudio/uni-quickapp-webview": "3.0.0-3081220230817001", 51 | "@uni-helper/uni-promises": "workspace:*", 52 | "vue": "3.2.47", 53 | "vue-i18n": "9.5.0" 54 | }, 55 | "devDependencies": { 56 | "@dcloudio/types": "3.4.0", 57 | "@dcloudio/uni-automator": "3.0.0-3081220230817001", 58 | "@dcloudio/uni-cli-shared": "3.0.0-3081220230817001", 59 | "@dcloudio/uni-stacktracey": "3.0.0-3081220230817001", 60 | "@dcloudio/vite-plugin-uni": "3.0.0-3081220230817001", 61 | "typescript": "5.2.2", 62 | "vite": "4.4.11" 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /playground/src/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "", 3 | "appid" : "", 4 | "description" : "", 5 | "versionName" : "1.0.0", 6 | "versionCode" : "100", 7 | "transformPx" : false, 8 | /* 5+App特有相关 */ 9 | "app-plus" : { 10 | "usingComponents" : true, 11 | "nvueStyleCompiler" : "uni-app", 12 | "compilerVersion" : 3, 13 | "splashscreen" : { 14 | "alwaysShowBeforeRender" : true, 15 | "waiting" : true, 16 | "autoclose" : true, 17 | "delay" : 0 18 | }, 19 | /* 模块配置 */ 20 | "modules" : {}, 21 | /* 应用发布信息 */ 22 | "distribute" : { 23 | /* android打包配置 */ 24 | "android" : { 25 | "permissions" : [ 26 | "", 27 | "", 28 | "", 29 | "", 30 | "", 31 | "", 32 | "", 33 | "", 34 | "", 35 | "", 36 | "", 37 | "", 38 | "", 39 | "", 40 | "" 41 | ] 42 | }, 43 | /* ios打包配置 */ 44 | "ios" : {}, 45 | /* SDK配置 */ 46 | "sdkConfigs" : {} 47 | } 48 | }, 49 | /* 快应用特有相关 */ 50 | "quickapp" : {}, 51 | /* 小程序特有相关 */ 52 | "mp-weixin" : { 53 | "appid" : "", 54 | "setting" : { 55 | "urlCheck" : false 56 | }, 57 | "usingComponents" : true 58 | }, 59 | "mp-alipay" : { 60 | "usingComponents" : true 61 | }, 62 | "mp-baidu" : { 63 | "usingComponents" : true 64 | }, 65 | "mp-toutiao" : { 66 | "usingComponents" : true 67 | }, 68 | "uniStatistics": { 69 | "enable": false 70 | }, 71 | "vueVersion" : "3" 72 | } 73 | -------------------------------------------------------------------------------- /src/requestSubscribeMessage/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | /** 4 | * 需要基础库: `2.4.4` 5 | * 6 | * 在插件中使用:不支持 7 | * 8 | * 调起客户端小程序订阅消息界面,返回用户订阅消息的操作结果。当用户勾选了订阅面板中的“总是保持以上选择,不再询问”时,模板消息会被添加到用户的小程序设置页,通过 9 | * [uni.getSetting](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/setting/wx.getSetting.html) 10 | * 接口可获取用户对相关模板消息的订阅状态。 11 | * 12 | * ## 注意事项 13 | * 14 | * - 一次性模板 id 和永久模板 id 不可同时使用。 15 | * - 低版本基础库2.4.4~2.8.3 已支持订阅消息接口调用,仅支持传入一个一次性 tmplId / 永久 tmplId。 16 | * - [2.8.2](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) 17 | * 版本开始,用户发生点击行为或者发起支付回调后,才可以调起订阅消息界面。 18 | * - [2.10.0](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) 19 | * 版本开始,开发版和体验版小程序将禁止使用模板消息 formId。 20 | * - 一次授权调用里,每个tmplId对应的模板标题不能存在相同的,若出现相同的,只保留一个。 21 | * - [2.10.0](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) 22 | * 版本开始,支持订阅语音消息提醒,[详情](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/subscribe-message.html) 23 | * 24 | * **错误码** 25 | * 26 | * | errCode | errMsg | 说明 | 27 | * | ------- | ------------------------------------------------------ | -------------------------------------------------------------- | 28 | * | 10001 | TmplIds can't be empty | 参数传空了 | 29 | * | 10002 | Request list fail | 网络问题,请求消息列表失败 | 30 | * | 10003 | Request subscribe fail | 网络问题,订阅请求发送失败 | 31 | * | 10004 | Invalid template id | 参数类型错误 | 32 | * | 10005 | Cannot show subscribe message UI | 无法展示 UI,一般是小程序这个时候退后台了导致的 | 33 | * | 20001 | No template data return, verify the template id exist | 没有模板数据,一般是模板 ID 不存在 或者和模板类型不对应 导致的 | 34 | * | 20002 | Templates type must be same | 模板消息类型 既有一次性的又有永久的 | 35 | * | 20003 | Templates count out of max bounds | 模板消息数量超过上限 | 36 | * | 20004 | The main switch is switched off | 用户关闭了主开关,无法进行订阅 | 37 | * | 20005 | This mini program was banned from subscribing messages | 小程序被禁封 | 38 | * | 20013 | Reject DeviceMsg Template | 不允许通过该接口订阅设备消息 | 39 | * 40 | * 文档 41 | * https://developers.weixin.qq.com/miniprogram/dev/api/open-api/subscribe-message/wx.requestSubscribeMessage.html 42 | */ 43 | export const requestSubscribeMessage = promisify(uni.requestSubscribeMessage); 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | pnpm-debug.log* 9 | run 10 | 11 | # Diagnostic reports (https://nodejs.org/api/report.html) 12 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 13 | 14 | # Runtime data 15 | pids 16 | *.pid 17 | *.seed 18 | *.pid.lock 19 | 20 | # Directory for instrumented libs generated by jscoverage/JSCover 21 | lib-cov 22 | 23 | # Coverage directory used by tools like istanbul 24 | coverage 25 | *.lcov 26 | 27 | # nyc test coverage 28 | .nyc_output 29 | 30 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 31 | .grunt 32 | 33 | # Bower dependency directory (https://bower.io/) 34 | bower_components 35 | 36 | # node-waf configuration 37 | .lock-wscript 38 | 39 | # Compiled binary addons (https://nodejs.org/api/addons.html) 40 | build/Release 41 | 42 | # Dependency directories 43 | node_modules 44 | jspm_packages 45 | 46 | # Snowpack dependency directory (https://snowpack.dev/) 47 | web_modules 48 | 49 | # Temp directory 50 | .temp 51 | .tmp 52 | 53 | # TypeScript cache 54 | *.tsbuildinfo 55 | 56 | # Optional npm cache directory 57 | .npm 58 | 59 | # Optional eslint cache 60 | .eslintcache 61 | 62 | # Microbundle cache 63 | .rpt2_cache 64 | .rts2_cache_cjs 65 | .rts2_cache_es 66 | .rts2_cache_umd 67 | 68 | # Optional REPL history 69 | .node_repl_history 70 | 71 | # Output of 'npm pack' 72 | *.tgz 73 | 74 | # Yarn Integrity file 75 | .yarn-integrity 76 | 77 | # dotenv environment variables file 78 | .env 79 | .env.test 80 | .env.*.test 81 | .env.local 82 | .env.*.local 83 | *.local 84 | 85 | # parcel-bundler cache (https://parceljs.org/) 86 | .cache 87 | .parcel-cache 88 | 89 | # Electron 90 | dist-electron 91 | dist_electron 92 | 93 | # Tauri 94 | dist-tauri 95 | dist_tauri 96 | 97 | # Cordova 98 | dist-cordova 99 | dist_cordova 100 | 101 | # Capacitor 102 | dist-capacitor 103 | dist_capacitor 104 | 105 | # Next.js build output 106 | .next 107 | out 108 | 109 | # Umi.js build output 110 | .umi 111 | .umi-production 112 | .umi-test 113 | 114 | # Nuxt.js build / generate output 115 | .nuxt 116 | dist 117 | 118 | # Rax.js build 119 | .rax 120 | 121 | # Vuepress build output 122 | .vuepress/dist 123 | 124 | # SSR 125 | dist-ssr 126 | dist_ssr 127 | 128 | # SSG 129 | dist-ssg 130 | dist_ssg 131 | 132 | # Serverless 133 | .serverless 134 | .dynamodb 135 | .s3 136 | .buckets 137 | .seeds 138 | 139 | # FuseBox cache 140 | .fusebox 141 | 142 | # TernJS port file 143 | .tern-port 144 | 145 | # Cypress 146 | /cypress/videos/ 147 | /cypress/screenshots/ 148 | 149 | # Editor 150 | .vscode-test 151 | .vscode/** 152 | !.vscode/extensions.json 153 | !.vscode/settings.json 154 | *.vsix 155 | .idea 156 | .hbuilder 157 | .hbuilderx 158 | *.suo 159 | *.ntvs* 160 | *.njsproj 161 | *.sln 162 | *.sw? 163 | 164 | # yarn v2 165 | .yarn/cache 166 | .yarn/unplugged 167 | .yarn/build-state.yml 168 | .yarn/install-state.gz 169 | .pnp.* 170 | 171 | # Apple 172 | .DS_Store 173 | *.p12 174 | *.mobileprovision 175 | 176 | # Android 177 | *.keystore 178 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@uni-helper/uni-promises", 3 | "version": "0.2.1", 4 | "description": "uni-app Promise 化的 API", 5 | "keywords": [ 6 | "uni-app", 7 | "uniapp", 8 | "uni", 9 | "promisify", 10 | "promise", 11 | "promisified", 12 | "api" 13 | ], 14 | "homepage": "https://github.com/uni-helper/uni-promises#readme", 15 | "bugs": { 16 | "url": "https://github.com/uni-helper/uni-promises/issues" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/uni-helper/uni-promises.git" 21 | }, 22 | "license": "MIT", 23 | "author": { 24 | "name": "ModyQyW", 25 | "email": "wurui-dev@foxmail.com", 26 | "url": "https://modyqyw.github.io" 27 | }, 28 | "type": "module", 29 | "exports": { 30 | ".": { 31 | "types": { 32 | "import": "./dist/index.d.mts", 33 | "require": "./dist/index.d.cts" 34 | }, 35 | "import": "./dist/index.mjs", 36 | "require": "./dist/index.cjs" 37 | } 38 | }, 39 | "main": "./dist/index.cjs", 40 | "module": "./dist/index.mjs", 41 | "types": "./dist/index.d.ts", 42 | "files": [ 43 | "dist" 44 | ], 45 | "scripts": { 46 | "build": "unbuild", 47 | "check:deps": "taze -f", 48 | "check:types": "tsc --noEmit", 49 | "commit": "git-cz", 50 | "dev": "unbuild --stub", 51 | "lint": "conc \"pnpm:lint:eslint\" \"pnpm:lint:markdownlint\" \"pnpm:lint:publint\"", 52 | "lint:eslint": "eslint ./src --fix --cache --ignore-path=.gitignore", 53 | "lint:markdownlint": "markdownlint . --fix --ignore-path=.gitignore", 54 | "lint:publint": "publint", 55 | "prepublishOnly": "pnpm run build", 56 | "release": "pnpm install && pnpm run lint && bumpp", 57 | "prepare": "is-ci || simple-git-hooks" 58 | }, 59 | "dependencies": { 60 | "@dcloudio/types": "^3.4.0" 61 | }, 62 | "devDependencies": { 63 | "@commitlint/cli": "^17.8.0", 64 | "@commitlint/config-conventional": "^17.8.0", 65 | "@commitlint/prompt": "^17.8.0", 66 | "@modyqyw/fabric": "^9.0.3", 67 | "@tsconfig/node18": "^18.2.2", 68 | "@types/node": "^24.10.4", 69 | "@typescript-eslint/eslint-plugin": "^6.8.0", 70 | "@typescript-eslint/parser": "^6.8.0", 71 | "bumpp": "^9.2.0", 72 | "commitizen": "^4.3.0", 73 | "concurrently": "^8.2.1", 74 | "eslint": "^8.51.0", 75 | "is-ci": "^3.0.1", 76 | "lint-staged": "^15.0.1", 77 | "markdownlint-cli": "^0.37.0", 78 | "prettier": "^3.0.3", 79 | "publint": "^0.2.4", 80 | "simple-git-hooks": "^2.9.0", 81 | "taze": "^0.11.4", 82 | "ts-node": "^10.9.1", 83 | "tsx": "^3.13.0", 84 | "typescript": "^5.2.2", 85 | "unbuild": "^2.0.0", 86 | "vue": "^3.3.4" 87 | }, 88 | "peerDependencies": { 89 | "typescript": "^4.8.0 || ^5.0.0", 90 | "vue": "^3.2.0" 91 | }, 92 | "peerDependenciesMeta": { 93 | "typescript": { 94 | "optional": true 95 | } 96 | }, 97 | "packageManager": "pnpm@8.9.2", 98 | "engines": { 99 | "node": ">=14.18" 100 | }, 101 | "publishConfig": { 102 | "access": "public", 103 | "registry": "https://registry.npmjs.org/" 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './types'; 2 | export * from './utils'; 3 | export * from './addPhoneContact'; 4 | export * from './authorize'; 5 | export * from './checkIsSoterEnrolledInDevice'; 6 | export * from './checkIsSupportSoterAuthentication'; 7 | export * from './checkSession'; 8 | export * from './chooseAddress'; 9 | export * from './chooseFile'; 10 | export * from './chooseImage'; 11 | export * from './chooseInvoice'; 12 | export * from './chooseInvoiceTitle'; 13 | export * from './chooseLocation'; 14 | export * from './chooseMedia'; 15 | export * from './chooseMessageFile'; 16 | export * from './chooseVideo'; 17 | export * from './clearStorage'; 18 | export * from './closeBLEConnection'; 19 | export * from './closeBluetoothAdapter'; 20 | export * from './closePreviewImage'; 21 | export * from './closeSocket'; 22 | export * from './compressImage'; 23 | export * from './compressVideo'; 24 | export * from './connectSocket'; 25 | export * from './createBLEConnection'; 26 | export * from './createCameraContext'; 27 | export * from './createCanvasContext'; 28 | export * from './createInnerAudioContext'; 29 | export * from './createLivePlayerContext'; 30 | export * from './createLivePusherContext'; 31 | export * from './createMapContext'; 32 | export * from './createMediaContainer'; 33 | export * from './createPushMessage'; 34 | export * from './createSelectorQuery'; 35 | export * from './createVideoContext'; 36 | export * from './downloadFile'; 37 | export * from './getApp'; 38 | export * from './getBackgroundAudioManager'; 39 | export * from './getBatteryInfo'; 40 | export * from './getBLEDeviceCharacteristics'; 41 | export * from './getBLEDeviceRSSI'; 42 | export * from './getBLEDeviceServices'; 43 | export * from './getBluetoothAdapterState'; 44 | export * from './getBluetoothDevices'; 45 | export * from './getCheckBoxState'; 46 | export * from './getClipboardData'; 47 | export * from './getConnectedBluetoothDevices'; 48 | export * from './getExtConfig'; 49 | export * from './getFileInfo'; 50 | export * from './getImageInfo'; 51 | export * from './getLocation'; 52 | export * from './getNetworkType'; 53 | export * from './getProvider'; 54 | export * from './getPushClientId'; 55 | export * from './getRecordManager'; 56 | export * from './getSavedFileInfo'; 57 | export * from './getSavedFileList'; 58 | export * from './getScreenBrightness'; 59 | export * from './getSelectedTextRange'; 60 | export * from './getSetting'; 61 | export * from './getStorage'; 62 | export * from './getStorageInfo'; 63 | export * from './getSystemInfo'; 64 | export * from './getUserInfo'; 65 | export * from './getUserProfile'; 66 | export * from './getVideoInfo'; 67 | export * from './hideHomeButton'; 68 | export * from './hideNavigationBarLoading'; 69 | export * from './hideShareMenu'; 70 | export * from './hideTabBar'; 71 | export * from './hideTabBarRedDot'; 72 | export * from './loadFontFace'; 73 | export * from './login'; 74 | export * from './makePhoneCall'; 75 | export * from './navigateBack'; 76 | export * from './navigateBackMiniProgram'; 77 | export * from './navigateTo'; 78 | export * from './navigateToMiniProgram'; 79 | export * from './notifyBLECharacteristicValueChange'; 80 | export * from './openAppAuthorizeSetting'; 81 | export * from './openBluetoothAdapter'; 82 | export * from './openDocument'; 83 | export * from './openLocation'; 84 | export * from './openVideoEditor'; 85 | export * from './pageScrollTo'; 86 | export * from './preLogin'; 87 | export * from './previewImage'; 88 | export * from './readBLECharacteristicValue'; 89 | export * from './redirectTo'; 90 | export * from './reLaunch'; 91 | export * from './removeSavedFile'; 92 | export * from './removeStorage'; 93 | export * from './removeTabBarBadge'; 94 | export * from './request'; 95 | export * from './requestPayment'; 96 | export * from './requestSubscribeMessage'; 97 | export * from './saveFile'; 98 | export * from './saveImageToPhotosAlbum'; 99 | export * from './saveVideoToPhotosAlbum'; 100 | export * from './scanCode'; 101 | export * from './sendSocketMessage'; 102 | export * from './setBackgroundColor'; 103 | export * from './setBackgroundTextStyle'; 104 | export * from './setBLEMTU'; 105 | export * from './setClipboardData'; 106 | export * from './setEnableDebug'; 107 | export * from './setKeepScreenOn'; 108 | export * from './setNavigationBarColor'; 109 | export * from './setNavigationBarTitle'; 110 | export * from './setScreenBrightness'; 111 | export * from './setStorage'; 112 | export * from './setTabBarBadge'; 113 | export * from './setTabBarItem'; 114 | export * from './setTabBarStyle'; 115 | export * from './share'; 116 | export * from './shareWithSystem'; 117 | export * from './showActionSheet'; 118 | export * from './showLoading'; 119 | export * from './showModal'; 120 | export * from './showNavigationBarLoading'; 121 | export * from './showShareMenu'; 122 | export * from './showTabBar'; 123 | export * from './showTabBarRedDot'; 124 | export * from './showToast'; 125 | export * from './startBluetoothDevicesDiscovery'; 126 | export * from './startPullDownRefresh'; 127 | export * from './startSoterAuthentication'; 128 | export * from './stopBluetoothDevicesDiscovery'; 129 | export * from './switchTab'; 130 | export * from './uploadFile'; 131 | export * from './vibrate'; 132 | export * from './vibrateLong'; 133 | export * from './vibrateShort'; 134 | export * from './writeBLECharacteristicValue'; 135 | -------------------------------------------------------------------------------- /src/createMapContext/index.ts: -------------------------------------------------------------------------------- 1 | import { promisify } from '../utils'; 2 | 3 | export interface MapContext extends UniApp.MapContext { 4 | /** 获取当前地图中心的经纬度,返回的是 gcj02 坐标系,可以用于 uni.openLocation */ 5 | getCenterLocation( 6 | options: UniApp.MapContextGetCenterLocationOptions, 7 | ): Promise>[0]>; 8 | /** 将地图中心移动到当前定位点,需要配合 map 组件的 show-location 使用 */ 9 | moveToLocation( 10 | options: UniApp.MapContextMoveToLocationOptions, 11 | ): Promise>[0]>; 12 | /** 平移marker,带动画 */ 13 | translateMarker( 14 | options: UniApp.MapContextTranslateMarkerOptions, 15 | ): Promise>[0]>; 16 | /** 缩放视野展示所有经纬度 */ 17 | includePoints( 18 | options: UniApp.MapContextIncludePointsOptions, 19 | ): Promise>[0]>; 20 | /** 获取当前地图的视野范围 */ 21 | getRegion( 22 | options: UniApp.MapContextGetRegionOptions, 23 | ): Promise>[0]>; 24 | /** 获取当前地图的缩放级别 */ 25 | getScale( 26 | options: UniApp.MapContextGetScaleOptions, 27 | ): Promise>[0]>; 28 | /** 添加个性化图层 */ 29 | addCustomLayer( 30 | options: UniApp.MapContextAddCustomLayerOptions, 31 | ): Promise>[0]>; 32 | /** 创建自定义图片图层,图片会随着地图缩放而缩放 */ 33 | addGroundOverlay( 34 | options: UniApp.MapContextAddGroundOverlayOptions, 35 | ): Promise>[0]>; 36 | /** 添加 marker */ 37 | addMarkers( 38 | options: UniApp.MapContextAddMarkersOptions, 39 | ): Promise>[0]>; 40 | /** 获取屏幕上的点对应的经纬度,坐标原点为地图左上角 */ 41 | fromScreenLocation( 42 | options: UniApp.MapContextFromScreenLocationOptions, 43 | ): Promise>[0]>; 44 | /** 初始化点聚合的配置,未调用时采用默认配置 */ 45 | initMarkerCluster( 46 | options: UniApp.MapContextInitMarkerClusterOptions, 47 | ): Promise>[0]>; 48 | /** 49 | * 沿指定路径移动 marker,用于轨迹回放等场景 50 | * 51 | * 动画完成时触发回调事件,若动画进行中,对同一 marker 再次调用 moveAlong 方法,前一次的动画将被打断 52 | */ 53 | moveAlong( 54 | options: UniApp.MapContextMoveAlongOptions, 55 | ): Promise>[0]>; 56 | /** 拉起地图 APP 选择导航 */ 57 | openMapApp( 58 | options: UniApp.MapContextOpenMapAppOptions, 59 | ): Promise>[0]>; 60 | /** 移除个性化图层 */ 61 | removeCustomLayer( 62 | options: UniApp.MapContextRemoveCustomLayerOptions, 63 | ): Promise>[0]>; 64 | /** 移除自定义图片图层 */ 65 | removeGroundOverlay( 66 | options: UniApp.MapContextRemoveGroundOverlayOptions, 67 | ): Promise>[0]>; 68 | /** 移除 marker */ 69 | removeMarkers( 70 | options: UniApp.MapContextRemoveMarkersOptions, 71 | ): Promise>[0]>; 72 | /** 73 | * 设置地图中心点偏移,向后向下为增长,屏幕比例范围(0.25~0.75) 74 | * 75 | * 默认偏移为[0.5, 0.5] 76 | */ 77 | setCenterOffset( 78 | options: UniApp.MapContextSetCenterOffsetOptions, 79 | ): Promise>[0]>; 80 | /** 获取经纬度对应的屏幕坐标,坐标原点为地图左上角 */ 81 | toScreenLocation( 82 | options: UniApp.MapContextToScreenLocationOptions, 83 | ): Promise>[0]>; 84 | /** 更新自定义图片图层 */ 85 | updateGroundOverlay( 86 | options: UniApp.MapContextUpdateGroundOverlayOptions, 87 | ): Promise>[0]>; 88 | } 89 | 90 | export const createMapContext = (mapId: string, componentInstance?: any) => { 91 | return new Promise((resolve, reject) => { 92 | try { 93 | const context: any = uni.createMapContext(mapId, componentInstance); 94 | context.getCenterLocation = promisify(context.getCenterLocation.bind(context)); 95 | context.moveToLocation = promisify(context.moveToLocation.bind(context)); 96 | context.translateMarker = promisify(context.translateMarker.bind(context)); 97 | context.includePoints = promisify(context.includePoints.bind(context)); 98 | context.getRegion = promisify(context.getRegion.bind(context)); 99 | context.getScale = promisify(context.getScale.bind(context)); 100 | context.addCustomLayer = promisify(context.addCustomLayer.bind(context)); 101 | context.addGroundOverlay = promisify(context.addGroundOverlay.bind(context)); 102 | context.addMarkers = promisify(context.addMarkers.bind(context)); 103 | context.fromScreenLocation = promisify(context.fromScreenLocation.bind(context)); 104 | context.initMarkerCluster = promisify(context.initMarkerCluster.bind(context)); 105 | context.moveAlong = promisify(context.moveAlong.bind(context)); 106 | context.openMapApp = promisify(context.openMapApp.bind(context)); 107 | context.removeCustomLayer = promisify(context.removeCustomLayer.bind(context)); 108 | context.removeGroundOverlay = promisify(context.removeGroundOverlay.bind(context)); 109 | context.removeMarkers = promisify(context.removeMarkers.bind(context)); 110 | context.setCenterOffset = promisify(context.setCenterOffset.bind(context)); 111 | context.toScreenLocation = promisify(context.toScreenLocation.bind(context)); 112 | context.updateGroundOverlay = promisify(context.updateGroundOverlay.bind(context)); 113 | resolve(context); 114 | } catch (error) { 115 | reject(error); 116 | } 117 | }); 118 | }; 119 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # @uni-helper/uni-promises 2 | 3 | [![License](https://img.shields.io/github/license/uni-helper/uni-promises)](https://github.com/uni-helper/uni-promises/blob/main/LICENSE) 4 | 5 | [![npm](https://img.shields.io/npm/v/@uni-helper/uni-promises)](https://www.npmjs.com/package/@uni-helper/uni-promises) 6 | 7 | `uni-app` promise 化的 API。要求 `node >= 14.18`。 8 | 9 | ## 起步 10 | 11 | ### 安装依赖 12 | 13 | 安装依赖。 14 | 15 | ```shell 16 | npm install @uni-helper/uni-promises 17 | ``` 18 | 19 |
20 | yarn v2/v3 21 |

请参考 文档 设置 nodeLinkernode_modules

22 |
23 | 24 |
25 | pnpm 26 |

请参考 文档 设置 shamefully-hoisttrue

27 |
28 | 29 | 不考虑支持 `uni_modules`。 30 | 31 | ## API 32 | 33 | - [addPhoneContact](./src/addPhoneContact/index.ts) 34 | - [authorize](./src/authorize/index.ts) 35 | - [checkIsSoterEnrolledInDevice](./src/checkIsSoterEnrolledInDevice/index.ts) 36 | - [checkIsSupportSoterAuthentication](./src/checkIsSupportSoterAuthentication/index.ts) 37 | - [checkSession](./src/checkSession/index.ts) 38 | - [chooseAddress](./src/chooseAddress/index.ts) 39 | - [chooseFile](./src/chooseFile/index.ts) 40 | - [chooseImage](./src/chooseImage/index.ts) 41 | - [chooseInvoice](./src/chooseInvoice/index.ts) 42 | - [chooseInvoiceTitle](./src/chooseInvoiceTitle/index.ts) 43 | - [chooseLocation](./src/chooseLocation/index.ts) 44 | - [chooseMedia](./src/chooseMedia/index.ts) 45 | - [chooseMessageFile](./src/chooseMessageFile/index.ts) 46 | - [chooseVideo](./src/chooseVideo/index.ts) 47 | - [clearStorage](./src/clearStorage/index.ts) 48 | - [closeBLEConnection](./src/closeBLEConnection/index.ts) 49 | - [closeBluetoothAdapter](./src/closeBluetoothAdapter/index.ts) 50 | - [closePreviewImage](./src/closePreviewImage/index.ts) 51 | - [closeSocket](./src/closeSocket/index.ts) 52 | - [compressImage](./src/compressImage/index.ts) 53 | - [compressVideo](./src/compressVideo/index.ts) 54 | - [connectSocket](./src/connectSocket/index.ts) 55 | - [createBLEConnection](./src/createBLEConnection/index.ts) 56 | - [createCameraContext](./src/createCameraContext/index.ts) 57 | - [createCanvasContext](./src/createCanvasContext/index.ts) 58 | - [createInnerAudioContext](./src/createInnerAudioContext/index.ts) 59 | - [createLivePlayerContext](./src/createLivePlayerContext/index.ts) 60 | - [createLivePusherContext](./src/createLivePusherContext/index.ts) 61 | - [createMapContext](./src/createMapContext/index.ts) 62 | - [createMediaContainer](./src/createMediaContainer/index.ts) 63 | - [createPushMessage](./src/createPushMessage/index.ts) 64 | - [createSelectorQuery](./src/createSelectorQuery/index.ts) 65 | - [createVideoContext](./src/createVideoContext/index.ts) 66 | - [downloadFile](./src/downloadFile/index.ts) 67 | - [getApp](./src/getApp/index.ts) 68 | - [getBLEDeviceCharacteristics](./src/getBLEDeviceCharacteristics/index.ts) 69 | - [getBLEDeviceRSSI](./src/getBLEDeviceRSSI/index.ts) 70 | - [getBLEDeviceServices](./src/getBLEDeviceServices/index.ts) 71 | - [getBackgroundAudioManager](./src/getBackgroundAudioManager/index.ts) 72 | - [getBatteryInfo](./src/getBatteryInfo/index.ts) 73 | - [getBluetoothAdapterState](./src/getBluetoothAdapterState/index.ts) 74 | - [getBluetoothDevices](./src/getBluetoothDevices/index.ts) 75 | - [getCheckBoxState](./src/getCheckBoxState/index.ts) 76 | - [getClipboardData](./src/getClipboardData/index.ts) 77 | - [getConnectedBluetoothDevices](./src/getConnectedBluetoothDevices/index.ts) 78 | - [getExtConfig](./src/getExtConfig/index.ts) 79 | - [getFileInfo](./src/getFileInfo/index.ts) 80 | - [getImageInfo](./src/getImageInfo/index.ts) 81 | - [getLocation](./src/getLocation/index.ts) 82 | - [getNetworkType](./src/getNetworkType/index.ts) 83 | - [getProvider](./src/getProvider/index.ts) 84 | - [getPushClientId](./src/getPushClientId/index.ts) 85 | - [getRecordManager](./src/getRecordManager/index.ts) 86 | - [getSavedFileInfo](./src/getSavedFileInfo/index.ts) 87 | - [getSavedFileList](./src/getSavedFileList/index.ts) 88 | - [getScreenBrightness](./src/getScreenBrightness/index.ts) 89 | - [getSelectedTextRange](./src/getSelectedTextRange/index.ts) 90 | - [getSetting](./src/getSetting/index.ts) 91 | - [getStorage](./src/getStorage/index.ts) 92 | - [getStorageInfo](./src/getStorageInfo/index.ts) 93 | - [getSystemInfo](./src/getSystemInfo/index.ts) 94 | - [getUserInfo](./src/getUserInfo/index.ts) 95 | - [getUserProfile](./src/getUserProfile/index.ts) 96 | - [getVideoInfo](./src/getVideoInfo/index.ts) 97 | - [hideHomeButton](./src/hideHomeButton/index.ts) 98 | - [hideNavigationBarLoading](./src/hideNavigationBarLoading/index.ts) 99 | - [hideShareMenu](./src/hideShareMenu/index.ts) 100 | - [hideTabBar](./src/hideTabBar/index.ts) 101 | - [hideTabBarRedDot](./src/hideTabBarRedDot/index.ts) 102 | - [loadFontFace](./src/loadFontFace/index.ts) 103 | - [login](./src/login/index.ts) 104 | - [makePhoneCall](./src/makePhoneCall/index.ts) 105 | - [navigateBack](./src/navigateBack/index.ts) 106 | - [navigateBackMiniProgram](./src/navigateBackMiniProgram/index.ts) 107 | - [navigateTo](./src/navigateTo/index.ts) 108 | - [navigateToMiniProgram](./src/navigateToMiniProgram/index.ts) 109 | - [notifyBLECharacteristicValueChange](./src/notifyBLECharacteristicValueChange/index.ts) 110 | - [openAppAuthorizeSetting](./src/openAppAuthorizeSetting/index.ts) 111 | - [openBluetoothAdapter](./src/openBluetoothAdapter/index.ts) 112 | - [openDocument](./src/openDocument/index.ts) 113 | - [openLocation](./src/openLocation/index.ts) 114 | - [openSetting](./src/openSetting/index.ts) 115 | - [openVideoEditor](./src/openVideoEditor/index.ts) 116 | - [pageScrollTo](./src/pageScrollTo/index.ts) 117 | - [preLogin](./src/preLogin/index.ts) 118 | - [previewImage](./src/previewImage/index.ts) 119 | - [reLaunch](./src/reLaunch/index.ts) 120 | - [readBLECharacteristicValue](./src/readBLECharacteristicValue/index.ts) 121 | - [redirectTo](./src/redirectTo/index.ts) 122 | - [removeSavedFile](./src/removeSavedFile/index.ts) 123 | - [removeStorage](./src/removeStorage/index.ts) 124 | - [removeTabBarBadge](./src/removeTabBarBadge/index.ts) 125 | - [request](./src/request/index.ts) 126 | - [requestPayment](./src/requestPayment/index.ts) 127 | - [requestSubscribeMessage](./src/requestSubscribeMessage/index.ts) 128 | - [saveFile](./src/saveFile/index.ts) 129 | - [saveImageToPhotosAlbum](./src/saveImageToPhotosAlbum/index.ts) 130 | - [saveVideoToPhotosAlbum](./src/saveVideoToPhotosAlbum/index.ts) 131 | - [scanCode](./src/scanCode/index.ts) 132 | - [sendSocketMessage](./src/sendSocketMessage/index.ts) 133 | - [setBLEMTU](./src/setBLEMTU/index.ts) 134 | - [setBackgroundColor](./src/setBackgroundColor/index.ts) 135 | - [setBackgroundTextStyle](./src/setBackgroundTextStyle/index.ts) 136 | - [setClipboardData](./src/setClipboardData/index.ts) 137 | - [setEnableDebug](./src/setEnableDebug/index.ts) 138 | - [setKeepScreenOn](./src/setKeepScreenOn/index.ts) 139 | - [setNavigationBarColor](./src/setNavigationBarColor/index.ts) 140 | - [setNavigationBarTitle](./src/setNavigationBarTitle/index.ts) 141 | - [setScreenBrightness](./src/setScreenBrightness/index.ts) 142 | - [setStorage](./src/setStorage/index.ts) 143 | - [setTabBarBadge](./src/setTabBarBadge/index.ts) 144 | - [setTabBarItem](./src/setTabBarItem/index.ts) 145 | - [setTabBarStyle](./src/setTabBarStyle/index.ts) 146 | - [share](./src/share/index.ts) 147 | - [shareWithSystem](./src/shareWithSystem/index.ts) 148 | - [showActionSheet](./src/showActionSheet/index.ts) 149 | - [showLoading](./src/showLoading/index.ts) 150 | - [showModal](./src/showModal/index.ts) 151 | - [showNavigationBarLoading](./src/showNavigationBarLoading/index.ts) 152 | - [showShareMenu](./src/showShareMenu/index.ts) 153 | - [showTabBar](./src/showTabBar/index.ts) 154 | - [showTabBarRedDot](./src/showTabBarRedDot/index.ts) 155 | - [showToast](./src/showToast/index.ts) 156 | - [startBluetoothDevicesDiscovery](./src/startBluetoothDevicesDiscovery/index.ts) 157 | - [startPullDownRefresh](./src/startPullDownRefresh/index.ts) 158 | - [startSoterAuthentication](./src/startSoterAuthentication/index.ts) 159 | - [stopBluetoothDevicesDiscovery](./src/stopBluetoothDevicesDiscovery/index.ts) 160 | - [switchTab](./src/switchTab/index.ts) 161 | - [uploadFile](./src/uploadFile/index.ts) 162 | - [vibrate](./src/vibrate/index.ts) 163 | - [vibrateLong](./src/vibrateLong/index.ts) 164 | - [vibrateShort](./src/vibrateShort/index.ts) 165 | - [writeBLECharacteristicValue](./src/writeBLECharacteristicValue/index.ts) 166 | 167 | ## 构建 168 | 169 | 目前 `@uni-helper/uni-promises` 会使用 `unbuild` 将 `uni` API 之外的部分转译到 `ES2017`(即 `ES8`)。`uni` API 需要在项目构建时由 `uni-app` 官方提供的插件处理。 170 | 171 | 对于 `vue-cli + vue2` 项目,请修改项目根目录 `vue.config.js` 如下所示。这会让 `vue-cli` 处理 `@uni-helper/uni-promises`,保证生成代码符合 `browserslist` 里的配置。我们建议设置 `browserslist` 为 `chrome>=53,ios>=8` 172 | 173 | ```javascript 174 | module.exports = { 175 | transpileDependencies: ['@uni-helper/uni-promises'], 176 | }; 177 | ``` 178 | 179 | 对于 `vite + vue3` 项目,请先设置 `build.target` 为 `ES6`。 180 | 181 | ```typescript 182 | import { defineConfig } from 'vite'; 183 | import uni from '@dcloudio/vite-plugin-uni'; 184 | 185 | // https://vitejs.dev/config/ 186 | export default defineConfig({ 187 | build: { 188 | target: 'es6', 189 | cssTarget: 'chrome61', // https://cn.vitejs.dev/config/build-options.html#build-csstarget 190 | }, 191 | plugins: [ 192 | ..., 193 | uni(), 194 | ..., 195 | ], 196 | }); 197 | ``` 198 | 199 | 然后在 `src/main.ts` 或 `src/main.js` 处自行添加 polyfill。以下是使用 [core-js](https://github.com/zloirock/core-js) 的示例(需要自行安装 `core-js`),你也可以使用 [es-shims](https://github.com/es-shims)。 200 | 201 | ```typescript 202 | import 'core-js/actual/array/iterator'; 203 | import 'core-js/actual/promise'; 204 | import 'core-js/actual/object/assign'; 205 | import 'core-js/actual/promise/finally'; 206 | // 你可以根据需要自行添加额外的 polyfills 207 | // import 'core-js/actual/object/values' 208 | import { createSSRApp } from 'vue'; 209 | import App from './App.vue'; 210 | 211 | export function createApp() { 212 | const app = createSSRApp(App); 213 | return { 214 | app, 215 | }; 216 | } 217 | ``` 218 | 219 | 微信小程序的 JavaScript 支持度见 [wechat-miniprogram/miniprogram-compat](https://github.com/wechat-miniprogram/miniprogram-compat)。微信小程序要支持 `vue3`,需设置基础库最低版本为 2.11.2 或以上,2.11.2 对应 `chrome>=53,ios>=10`。 220 | 221 | ## 延伸 222 | 223 | 如果你觉得这个库有用,你可以到 [这个 ISSUE](https://github.com/dcloudio/uni-app/issues/4084) 投票,鼓励官方引入支持。 224 | 225 | 尽管 `@dcloudio/types@3.3.0` 开始提供基于 Promise 的类型定义,但它不能正确地同时支持 Vue 2 和 Vue 3,需要手动适配。而这个库基于回调方法封装 Promise,能正确地同时支持 Vue 2 和 Vue 3。 226 | 227 | 在官方提供的类型定义不能覆盖这个库之前,这个库依旧保持维护。 228 | 229 | ## 致谢 230 | 231 | - [taro](https://github.com/nervjs/taro) 232 | --------------------------------------------------------------------------------