From 8463492072e7f43b16e28431d46055e98b5e9537 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Wed, 31 Mar 2021 21:20:41 +0800 Subject: [PATCH] feat: createApi => defineApi --- packages/uni-api/src/helpers/api/index.ts | 18 +++--- packages/uni-api/src/index.ts | 8 +-- .../src/protocols/media/getImageInfo.ts | 3 +- packages/uni-api/src/service/base/base64.ts | 6 +- .../uni-api/src/service/base/interceptor.ts | 6 +- packages/uni-api/src/service/base/upx2px.ts | 4 +- .../service/ui/createIntersectionObserver.ts | 4 +- packages/uni-h5/dist/uni-h5.esm.js | 60 +++++++++---------- .../uni-h5/src/service/api/base/canIUse.ts | 4 +- .../src/service/api/device/getSystemInfo.ts | 4 +- .../service/api/device/getSystemInfoSync.ts | 4 +- .../src/service/api/device/makePhoneCall.ts | 4 +- .../src/service/api/file/openDocument.ts | 4 +- packages/uni-h5/src/service/api/index.ts | 2 - .../src/service/api/media/getImageInfo.ts | 4 +- .../src/service/api/route/navigateBack.ts | 4 +- .../src/service/api/route/navigateTo.ts | 4 +- .../uni-h5/src/service/api/route/reLaunch.ts | 4 +- .../src/service/api/route/redirectTo.ts | 4 +- .../uni-h5/src/service/api/route/switchTab.ts | 4 +- .../src/service/api/util/getRealPath.ts | 5 -- packages/uni-mp-alipay/dist/uni.api.esm.js | 12 ++-- packages/uni-mp-alipay/src/platform/index.ts | 2 + packages/uni-mp-baidu/dist/uni.api.esm.js | 12 ++-- packages/uni-mp-baidu/src/platform/index.ts | 1 + packages/uni-mp-qq/dist/uni.api.esm.js | 12 ++-- packages/uni-mp-qq/src/platform/index.ts | 1 + packages/uni-mp-toutiao/dist/uni.api.esm.js | 12 ++-- packages/uni-mp-toutiao/src/platform/index.ts | 1 + packages/uni-mp-weixin/dist/uni.api.esm.js | 12 ++-- packages/uni-mp-weixin/src/platform/index.ts | 1 + .../uni-quickapp-webview/dist/uni.api.esm.js | 12 ++-- .../src/platform/index.ts | 1 + 33 files changed, 118 insertions(+), 121 deletions(-) delete mode 100644 packages/uni-h5/src/service/api/util/getRealPath.ts diff --git a/packages/uni-api/src/helpers/api/index.ts b/packages/uni-api/src/helpers/api/index.ts index 1c2826045..b43edda72 100644 --- a/packages/uni-api/src/helpers/api/index.ts +++ b/packages/uni-api/src/helpers/api/index.ts @@ -63,12 +63,12 @@ function wrapperApi( } as unknown) as T } -export function createOnApi( +export function defineOnApi( name: string, fn: T, options?: ApiOptions ) { - return createApi( + return defineApi( API_TYPE_ON, name, fn, @@ -77,13 +77,13 @@ export function createOnApi( ) } -export function createTaskApi( +export function defineTaskApi( name: string, fn: T, protocol?: ApiProtocols, options?: ApiOptions ) { - return createApi( + return defineApi( API_TYPE_TASK, name, fn, @@ -92,13 +92,13 @@ export function createTaskApi( ) } -export function createSyncApi( +export function defineSyncApi( name: string, fn: T, protocol?: ApiProtocols, options?: ApiOptions ) { - return createApi( + return defineApi( API_TYPE_SYNC, name, fn, @@ -107,18 +107,18 @@ export function createSyncApi( ) } -export function createAsyncApi( +export function defineAsyncApi( name: string, fn: T, protocol?: ApiProtocols, options?: ApiOptions ) { return promisify( - createApi(API_TYPE_ASYNC, name, fn, __DEV__ ? protocol : undefined, options) + defineApi(API_TYPE_ASYNC, name, fn, __DEV__ ? protocol : undefined, options) ) } -function createApi( +function defineApi( type: API_TYPES, name: string, fn: T, diff --git a/packages/uni-api/src/index.ts b/packages/uni-api/src/index.ts index 76dcb5924..43f5ea4df 100644 --- a/packages/uni-api/src/index.ts +++ b/packages/uni-api/src/index.ts @@ -23,10 +23,10 @@ export * from './protocols/media/getImageInfo' // helpers export { - createOnApi, - createTaskApi, - createSyncApi, - createAsyncApi, + defineOnApi, + defineTaskApi, + defineSyncApi, + defineAsyncApi, } from './helpers/api' export { handlePromise } from './helpers/api/promise' diff --git a/packages/uni-api/src/protocols/media/getImageInfo.ts b/packages/uni-api/src/protocols/media/getImageInfo.ts index e7150f128..fcac89027 100644 --- a/packages/uni-api/src/protocols/media/getImageInfo.ts +++ b/packages/uni-api/src/protocols/media/getImageInfo.ts @@ -1,9 +1,10 @@ +import { getRealPath } from '@dcloudio/uni-platform' import { ApiOptions, ApiProtocol } from '../type' export const GetImageInfoOptions: ApiOptions = { formatArgs: { src(src, params) { - params.src = (uni as any).getRealPath(src) + params.src = getRealPath(src) }, }, } diff --git a/packages/uni-api/src/service/base/base64.ts b/packages/uni-api/src/service/base/base64.ts index ce46fbc37..6b3b26f58 100644 --- a/packages/uni-api/src/service/base/base64.ts +++ b/packages/uni-api/src/service/base/base64.ts @@ -1,14 +1,14 @@ // @ts-ignore import { encode, decode } from '../../helpers/base64-arraybuffer' -import { createSyncApi } from '../../helpers/api' +import { defineSyncApi } from '../../helpers/api' import { Base64ToArrayBufferProtocol, ArrayBufferToBase64Protocol, } from '../../protocols/base/base64' -export const base64ToArrayBuffer = createSyncApi< +export const base64ToArrayBuffer = defineSyncApi< typeof uni.base64ToArrayBuffer >( 'base64ToArrayBuffer', @@ -18,7 +18,7 @@ export const base64ToArrayBuffer = createSyncApi< Base64ToArrayBufferProtocol ) -export const arrayBufferToBase64 = createSyncApi< +export const arrayBufferToBase64 = defineSyncApi< typeof uni.arrayBufferToBase64 >( 'arrayBufferToBase64', diff --git a/packages/uni-api/src/service/base/interceptor.ts b/packages/uni-api/src/service/base/interceptor.ts index 59dda03c1..72d0cace6 100644 --- a/packages/uni-api/src/service/base/interceptor.ts +++ b/packages/uni-api/src/service/base/interceptor.ts @@ -8,7 +8,7 @@ import { HOOKS, } from '../../helpers/interceptor' -import { createSyncApi } from '../../helpers/api' +import { defineSyncApi } from '../../helpers/api' import { AddInterceptorProtocol, @@ -80,7 +80,7 @@ function removeHook(hooks: Function[] | undefined, hook: Function) { } } -export const addInterceptor = createSyncApi( +export const addInterceptor = defineSyncApi( 'addInterceptor', (method: string | Interceptor, interceptor: Interceptor | undefined) => { if (typeof method === 'string' && isPlainObject(interceptor)) { @@ -95,7 +95,7 @@ export const addInterceptor = createSyncApi( AddInterceptorProtocol ) -export const removeInterceptor = createSyncApi( +export const removeInterceptor = defineSyncApi( 'removeInterceptor', (method: string | Interceptor, interceptor: Interceptor | undefined) => { if (typeof method === 'string') { diff --git a/packages/uni-api/src/service/base/upx2px.ts b/packages/uni-api/src/service/base/upx2px.ts index d0574613a..76eda56e4 100644 --- a/packages/uni-api/src/service/base/upx2px.ts +++ b/packages/uni-api/src/service/base/upx2px.ts @@ -1,5 +1,5 @@ import { getBaseSystemInfo } from '@dcloudio/uni-platform' -import { createSyncApi } from '../../helpers/api' +import { defineSyncApi } from '../../helpers/api' import { Upx2pxProtocol } from '../../protocols/base/upx2px' const EPS = 1e-4 @@ -15,7 +15,7 @@ function checkDeviceWidth() { isIOS = platform === 'ios' } -export const upx2px = createSyncApi( +export const upx2px = defineSyncApi( 'upx2px', (number, newDeviceWidth?: number) => { if (deviceWidth === 0) { diff --git a/packages/uni-api/src/service/ui/createIntersectionObserver.ts b/packages/uni-api/src/service/ui/createIntersectionObserver.ts index ed1c6e3f0..28f05ddae 100644 --- a/packages/uni-api/src/service/ui/createIntersectionObserver.ts +++ b/packages/uni-api/src/service/ui/createIntersectionObserver.ts @@ -2,7 +2,7 @@ import { extend } from '@vue/shared' import { ServiceJSBridge } from '@dcloudio/uni-core' -import { createSyncApi } from '../../helpers/api' +import { defineSyncApi } from '../../helpers/api' import { getCurrentPageVm } from '../utils' const defaultOptions = { @@ -120,7 +120,7 @@ class ServiceIntersectionObserver { } } -export const createIntersectionObserver = createSyncApi< +export const createIntersectionObserver = defineSyncApi< typeof uni.createIntersectionObserver >('createIntersectionObserver', (context?, options?) => { if (!context) { diff --git a/packages/uni-h5/dist/uni-h5.esm.js b/packages/uni-h5/dist/uni-h5.esm.js index 1579f9929..9978bc654 100644 --- a/packages/uni-h5/dist/uni-h5.esm.js +++ b/packages/uni-h5/dist/uni-h5.esm.js @@ -3319,7 +3319,7 @@ function addBase(filePath) { } return base + filePath; } -function getRealPath$1(filePath) { +function getRealPath(filePath) { if (__uniConfig.router.base === "./") { filePath = filePath.replace(/^\.\/static\//, "/static/"); } @@ -3395,7 +3395,7 @@ const _sfc_main$j = { return this.originalWidth && this.originalHeight ? this.originalWidth / this.originalHeight : 0; }, realImagePath() { - return getRealPath$1(this.src); + return getRealPath(this.src); }, modeStyle() { let size = "auto"; @@ -7716,13 +7716,13 @@ function wrapperApi(fn, name, protocol, options) { return fn.apply(null, formatApiArgs(args)); }; } -function createSyncApi(name, fn, protocol, options) { - return createApi(API_TYPE_SYNC, name, fn, process.env.NODE_ENV !== "production" ? protocol : void 0, options); +function defineSyncApi(name, fn, protocol, options) { + return defineApi(API_TYPE_SYNC, name, fn, process.env.NODE_ENV !== "production" ? protocol : void 0, options); } -function createAsyncApi(name, fn, protocol, options) { - return promisify(createApi(API_TYPE_ASYNC, name, fn, process.env.NODE_ENV !== "production" ? protocol : void 0, options)); +function defineAsyncApi(name, fn, protocol, options) { + return promisify(defineApi(API_TYPE_ASYNC, name, fn, process.env.NODE_ENV !== "production" ? protocol : void 0, options)); } -function createApi(type, name, fn, protocol, options) { +function defineApi(type, name, fn, protocol, options) { switch (type) { case API_TYPE_ON: return wrapperApi(wrapperOnApi(name, fn), name, protocol); @@ -7748,10 +7748,10 @@ const ArrayBufferToBase64Protocol = [ required: true } ]; -const base64ToArrayBuffer = /* @__PURE__ */ createSyncApi("base64ToArrayBuffer", (base64) => { +const base64ToArrayBuffer = defineSyncApi("base64ToArrayBuffer", (base64) => { return decode(base64); }, Base64ToArrayBufferProtocol); -const arrayBufferToBase64 = /* @__PURE__ */ createSyncApi("arrayBufferToBase64", (arrayBuffer) => { +const arrayBufferToBase64 = defineSyncApi("arrayBufferToBase64", (arrayBuffer) => { return encode(arrayBuffer); }, ArrayBufferToBase64Protocol); const Upx2pxProtocol = [ @@ -7772,7 +7772,7 @@ function checkDeviceWidth() { deviceDPR = pixelRatio2; isIOS = platform === "ios"; } -const upx2px = /* @__PURE__ */ createSyncApi("upx2px", (number, newDeviceWidth) => { +const upx2px = defineSyncApi("upx2px", (number, newDeviceWidth) => { if (deviceWidth === 0) { checkDeviceWidth(); } @@ -7851,14 +7851,14 @@ function removeHook(hooks, hook) { hooks.splice(index2, 1); } } -const addInterceptor = /* @__PURE__ */ createSyncApi("addInterceptor", (method, interceptor) => { +const addInterceptor = defineSyncApi("addInterceptor", (method, interceptor) => { if (typeof method === "string" && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); } else if (isPlainObject(method)) { mergeInterceptorHook(globalInterceptors, method); } }, AddInterceptorProtocol); -const removeInterceptor = /* @__PURE__ */ createSyncApi("removeInterceptor", (method, interceptor) => { +const removeInterceptor = defineSyncApi("removeInterceptor", (method, interceptor) => { if (typeof method === "string") { if (isPlainObject(interceptor)) { removeInterceptorHook(scopedInterceptors[method], interceptor); @@ -7946,7 +7946,7 @@ class ServiceIntersectionObserver { }, this._pageId); } } -const createIntersectionObserver = /* @__PURE__ */ createSyncApi("createIntersectionObserver", (context, options) => { +const createIntersectionObserver = defineSyncApi("createIntersectionObserver", (context, options) => { if (!context) { context = getCurrentPageVm(); } @@ -7984,7 +7984,7 @@ const OpenDocumentProtocol = { const GetImageInfoOptions = { formatArgs: { src(src, params) { - params.src = uni.getRealPath(src); + params.src = getRealPath(src); } } }; @@ -8002,16 +8002,16 @@ const SCHEMA_CSS = { "css.env": cssSupports("top:env(a)"), "css.constant": cssSupports("top:constant(a)") }; -const canIUse = /* @__PURE__ */ createSyncApi("canIUse", (schema) => { +const canIUse = defineSyncApi("canIUse", (schema) => { if (hasOwn$1(SCHEMA_CSS, schema)) { return SCHEMA_CSS[schema]; } return true; }, CanIUseProtocol); -const makePhoneCall = /* @__PURE__ */ createAsyncApi("makePhoneCall", (option) => { +const makePhoneCall = defineAsyncApi("makePhoneCall", (option) => { window.location.href = `tel:${option.phoneNumber}`; }, MakePhoneCallProtocol); -const getSystemInfoSync = /* @__PURE__ */ createSyncApi("getSystemInfoSync", () => { +const getSystemInfoSync = defineSyncApi("getSystemInfoSync", () => { const pixelRatio2 = window.devicePixelRatio; const screenFix = getScreenFix(); const landscape = isLandscape(screenFix); @@ -8111,16 +8111,16 @@ const getSystemInfoSync = /* @__PURE__ */ createSyncApi("getSystemInfoSync", () } }; }); -const getSystemInfo = /* @__PURE__ */ createAsyncApi("getSystemInfo", () => { +const getSystemInfo = defineAsyncApi("getSystemInfo", () => { return getSystemInfoSync(); }); -const openDocument = /* @__PURE__ */ createAsyncApi("openDocument", (option) => { +const openDocument = defineAsyncApi("openDocument", (option) => { window.open(option.filePath); }, OpenDocumentProtocol); function _getServiceAddress() { return window.location.protocol + "//" + window.location.host; } -const getImageInfo = /* @__PURE__ */ createAsyncApi("getImageInfo", ({src}, callback) => { +const getImageInfo = defineAsyncApi("getImageInfo", ({src}, callback) => { const img = new Image(); img.onload = function() { callback({ @@ -8137,9 +8137,9 @@ const getImageInfo = /* @__PURE__ */ createAsyncApi("getImageInfo", ({src}, call }; img.src = src; }, GetImageInfoProtocol, GetImageInfoOptions); -const navigateBack = /* @__PURE__ */ createAsyncApi("navigateBack", () => { +const navigateBack = defineAsyncApi("navigateBack", () => { }); -const navigateTo = /* @__PURE__ */ createAsyncApi("navigateTo", (options) => { +const navigateTo = defineAsyncApi("navigateTo", (options) => { const router = getApp().$router; router.push({ path: options.url, @@ -8147,14 +8147,11 @@ const navigateTo = /* @__PURE__ */ createAsyncApi("navigateTo", (options) => { state: createPageState("navigateTo") }); }); -const redirectTo = /* @__PURE__ */ createAsyncApi("redirectTo", () => { +const redirectTo = defineAsyncApi("redirectTo", () => { }); -const reLaunch = /* @__PURE__ */ createAsyncApi("reLaunch", () => { +const reLaunch = defineAsyncApi("reLaunch", () => { }); -const switchTab = /* @__PURE__ */ createAsyncApi("switchTab", () => { -}); -const getRealPath = /* @__PURE__ */ createSyncApi("getRealPath", (path) => { - return path; +const switchTab = defineAsyncApi("switchTab", () => { }); var api = /* @__PURE__ */ Object.freeze({ __proto__: null, @@ -8177,8 +8174,7 @@ var api = /* @__PURE__ */ Object.freeze({ navigateTo, redirectTo, reLaunch, - switchTab, - getRealPath + switchTab }); const uni$1 = api; const UniServiceJSBridge$1 = extend(ServiceJSBridge, { @@ -8464,7 +8460,7 @@ function usePageHeadButtons(navigationBar) { const fonts = Object.create(null); buttons.forEach((btn) => { if (btn.fontSrc && !btn.fontFamily) { - const fontSrc = getRealPath$1(btn.fontSrc); + const fontSrc = getRealPath(btn.fontSrc); let fontFamily = fonts[fontSrc]; if (!fontFamily) { fontFamily = `font${Date.now()}`; @@ -9268,4 +9264,4 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { ]); } _sfc_main.render = _sfc_render; -export {_sfc_main$1 as AsyncErrorComponent, _sfc_main as AsyncLoadingComponent, _sfc_main$p as Audio, _sfc_main$o as Canvas, _sfc_main$n as Checkbox, _sfc_main$m as CheckboxGroup, _sfc_main$l as Editor, _sfc_main$k as Form, index$1 as Icon, _sfc_main$j as Image, _sfc_main$i as Input, _sfc_main$h as Label, _sfc_main$g as MovableView, _sfc_main$f as Navigator, index as PageComponent, _sfc_main$e as Progress, _sfc_main$d as Radio, _sfc_main$c as RadioGroup, _sfc_main$b as ResizeSensor, _sfc_main$a as RichText, _sfc_main$9 as ScrollView, _sfc_main$8 as Slider, _sfc_main$7 as SwiperItem, _sfc_main$6 as Switch, _sfc_main$5 as Text, _sfc_main$4 as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, _sfc_main$3 as View, addInterceptor, arrayBufferToBase64, base64ToArrayBuffer, canIUse, createIntersectionObserver, createSelectorQuery, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getImageInfo, getRealPath, getSystemInfo, getSystemInfoSync, makePhoneCall, navigateBack, navigateTo, openDocument, index$2 as plugin, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, switchTab, uni$1 as uni, upx2px}; +export {_sfc_main$1 as AsyncErrorComponent, _sfc_main as AsyncLoadingComponent, _sfc_main$p as Audio, _sfc_main$o as Canvas, _sfc_main$n as Checkbox, _sfc_main$m as CheckboxGroup, _sfc_main$l as Editor, _sfc_main$k as Form, index$1 as Icon, _sfc_main$j as Image, _sfc_main$i as Input, _sfc_main$h as Label, _sfc_main$g as MovableView, _sfc_main$f as Navigator, index as PageComponent, _sfc_main$e as Progress, _sfc_main$d as Radio, _sfc_main$c as RadioGroup, _sfc_main$b as ResizeSensor, _sfc_main$a as RichText, _sfc_main$9 as ScrollView, _sfc_main$8 as Slider, _sfc_main$7 as SwiperItem, _sfc_main$6 as Switch, _sfc_main$5 as Text, _sfc_main$4 as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, _sfc_main$3 as View, addInterceptor, arrayBufferToBase64, base64ToArrayBuffer, canIUse, createIntersectionObserver, createSelectorQuery, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getImageInfo, getSystemInfo, getSystemInfoSync, makePhoneCall, navigateBack, navigateTo, openDocument, index$2 as plugin, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, switchTab, uni$1 as uni, upx2px}; diff --git a/packages/uni-h5/src/service/api/base/canIUse.ts b/packages/uni-h5/src/service/api/base/canIUse.ts index ea12323bb..6c06e7507 100644 --- a/packages/uni-h5/src/service/api/base/canIUse.ts +++ b/packages/uni-h5/src/service/api/base/canIUse.ts @@ -1,6 +1,6 @@ import { hasOwn } from '@vue/shared' -import { CanIUseProtocol, createSyncApi } from '@dcloudio/uni-api' +import { CanIUseProtocol, defineSyncApi } from '@dcloudio/uni-api' function cssSupports(css: string) { return window.CSS && window.CSS.supports && window.CSS.supports(css) @@ -12,7 +12,7 @@ const SCHEMA_CSS = { 'css.constant': cssSupports('top:constant(a)'), } -export const canIUse = createSyncApi( +export const canIUse = defineSyncApi( 'canIUse', (schema: string) => { if (hasOwn(SCHEMA_CSS, schema)) { diff --git a/packages/uni-h5/src/service/api/device/getSystemInfo.ts b/packages/uni-h5/src/service/api/device/getSystemInfo.ts index 6beb18c82..8df61d8f8 100644 --- a/packages/uni-h5/src/service/api/device/getSystemInfo.ts +++ b/packages/uni-h5/src/service/api/device/getSystemInfo.ts @@ -1,8 +1,8 @@ -import { createAsyncApi } from '@dcloudio/uni-api' +import { defineAsyncApi } from '@dcloudio/uni-api' import { getSystemInfoSync } from './getSystemInfoSync' -export const getSystemInfo = createAsyncApi( +export const getSystemInfo = defineAsyncApi( 'getSystemInfo', () => { return getSystemInfoSync() diff --git a/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts b/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts index 0c3c0899d..5b0bd79f5 100644 --- a/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts +++ b/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts @@ -1,6 +1,6 @@ import safeAreaInsets from 'safe-area-insets' -import { createSyncApi } from '@dcloudio/uni-api' +import { defineSyncApi } from '@dcloudio/uni-api' import { getWindowOffset } from '@dcloudio/uni-core' @@ -18,7 +18,7 @@ import { /** * 获取系统信息-同步 */ -export const getSystemInfoSync = createSyncApi( +export const getSystemInfoSync = defineSyncApi( 'getSystemInfoSync', () => { const pixelRatio = window.devicePixelRatio diff --git a/packages/uni-h5/src/service/api/device/makePhoneCall.ts b/packages/uni-h5/src/service/api/device/makePhoneCall.ts index a0df5d4a8..ddc73aedf 100644 --- a/packages/uni-h5/src/service/api/device/makePhoneCall.ts +++ b/packages/uni-h5/src/service/api/device/makePhoneCall.ts @@ -1,6 +1,6 @@ -import { createAsyncApi, MakePhoneCallProtocol } from '@dcloudio/uni-api' +import { defineAsyncApi, MakePhoneCallProtocol } from '@dcloudio/uni-api' -export const makePhoneCall = createAsyncApi( +export const makePhoneCall = defineAsyncApi( 'makePhoneCall', (option) => { window.location.href = `tel:${option.phoneNumber}` diff --git a/packages/uni-h5/src/service/api/file/openDocument.ts b/packages/uni-h5/src/service/api/file/openDocument.ts index 4bbcf4b77..c6ea15cec 100644 --- a/packages/uni-h5/src/service/api/file/openDocument.ts +++ b/packages/uni-h5/src/service/api/file/openDocument.ts @@ -1,6 +1,6 @@ -import { createAsyncApi, OpenDocumentProtocol } from '@dcloudio/uni-api' +import { defineAsyncApi, OpenDocumentProtocol } from '@dcloudio/uni-api' -export const openDocument = createAsyncApi( +export const openDocument = defineAsyncApi( 'openDocument', (option) => { window.open(option.filePath) diff --git a/packages/uni-h5/src/service/api/index.ts b/packages/uni-h5/src/service/api/index.ts index d2f68e125..ecd4e619f 100644 --- a/packages/uni-h5/src/service/api/index.ts +++ b/packages/uni-h5/src/service/api/index.ts @@ -14,8 +14,6 @@ export * from './route/redirectTo' export * from './route/reLaunch' export * from './route/switchTab' -export * from './util/getRealPath' - export { upx2px, addInterceptor, diff --git a/packages/uni-h5/src/service/api/media/getImageInfo.ts b/packages/uni-h5/src/service/api/media/getImageInfo.ts index 24a1bbaf0..2fe590112 100644 --- a/packages/uni-h5/src/service/api/media/getImageInfo.ts +++ b/packages/uni-h5/src/service/api/media/getImageInfo.ts @@ -1,5 +1,5 @@ import { - createAsyncApi, + defineAsyncApi, GetImageInfoOptions, GetImageInfoProtocol, } from '@dcloudio/uni-api' @@ -8,7 +8,7 @@ function _getServiceAddress() { return window.location.protocol + '//' + window.location.host } -export const getImageInfo = createAsyncApi( +export const getImageInfo = defineAsyncApi( 'getImageInfo', ({ src }, callback?: Function) => { const img = new Image() diff --git a/packages/uni-h5/src/service/api/route/navigateBack.ts b/packages/uni-h5/src/service/api/route/navigateBack.ts index 2c787e49e..c1f5ca3f6 100644 --- a/packages/uni-h5/src/service/api/route/navigateBack.ts +++ b/packages/uni-h5/src/service/api/route/navigateBack.ts @@ -1,6 +1,6 @@ -import { createAsyncApi } from '@dcloudio/uni-api' +import { defineAsyncApi } from '@dcloudio/uni-api' -export const navigateBack = createAsyncApi( +export const navigateBack = defineAsyncApi( 'navigateBack', () => {} ) diff --git a/packages/uni-h5/src/service/api/route/navigateTo.ts b/packages/uni-h5/src/service/api/route/navigateTo.ts index f53ce27bb..6cb4a69ee 100644 --- a/packages/uni-h5/src/service/api/route/navigateTo.ts +++ b/packages/uni-h5/src/service/api/route/navigateTo.ts @@ -1,8 +1,8 @@ import { Router } from 'vue-router' -import { createAsyncApi } from '@dcloudio/uni-api' +import { defineAsyncApi } from '@dcloudio/uni-api' import { createPageState } from '../../../framework/plugin/page' -export const navigateTo = createAsyncApi( +export const navigateTo = defineAsyncApi( 'navigateTo', (options) => { const router = getApp().$router as Router diff --git a/packages/uni-h5/src/service/api/route/reLaunch.ts b/packages/uni-h5/src/service/api/route/reLaunch.ts index 3b7bc20e6..e1dfb0664 100644 --- a/packages/uni-h5/src/service/api/route/reLaunch.ts +++ b/packages/uni-h5/src/service/api/route/reLaunch.ts @@ -1,3 +1,3 @@ -import { createAsyncApi } from '@dcloudio/uni-api' +import { defineAsyncApi } from '@dcloudio/uni-api' -export const reLaunch = createAsyncApi('reLaunch', () => {}) +export const reLaunch = defineAsyncApi('reLaunch', () => {}) diff --git a/packages/uni-h5/src/service/api/route/redirectTo.ts b/packages/uni-h5/src/service/api/route/redirectTo.ts index 86da2a4f8..6f1ddfd10 100644 --- a/packages/uni-h5/src/service/api/route/redirectTo.ts +++ b/packages/uni-h5/src/service/api/route/redirectTo.ts @@ -1,3 +1,3 @@ -import { createAsyncApi } from '@dcloudio/uni-api' +import { defineAsyncApi } from '@dcloudio/uni-api' -export const redirectTo = createAsyncApi('redirectTo', () => {}) +export const redirectTo = defineAsyncApi('redirectTo', () => {}) diff --git a/packages/uni-h5/src/service/api/route/switchTab.ts b/packages/uni-h5/src/service/api/route/switchTab.ts index a56a78e4b..6430d3a1b 100644 --- a/packages/uni-h5/src/service/api/route/switchTab.ts +++ b/packages/uni-h5/src/service/api/route/switchTab.ts @@ -1,3 +1,3 @@ -import { createAsyncApi } from '@dcloudio/uni-api' +import { defineAsyncApi } from '@dcloudio/uni-api' -export const switchTab = createAsyncApi('switchTab', () => {}) +export const switchTab = defineAsyncApi('switchTab', () => {}) diff --git a/packages/uni-h5/src/service/api/util/getRealPath.ts b/packages/uni-h5/src/service/api/util/getRealPath.ts deleted file mode 100644 index fb63b9cb1..000000000 --- a/packages/uni-h5/src/service/api/util/getRealPath.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { createSyncApi } from '@dcloudio/uni-api' - -export const getRealPath = createSyncApi('getRealPath', (path: string) => { - return path -}) diff --git a/packages/uni-mp-alipay/dist/uni.api.esm.js b/packages/uni-mp-alipay/dist/uni.api.esm.js index ab74fc079..742069884 100644 --- a/packages/uni-mp-alipay/dist/uni.api.esm.js +++ b/packages/uni-mp-alipay/dist/uni.api.esm.js @@ -285,10 +285,10 @@ function wrapperApi(fn, name, protocol, options) { return fn.apply(null, formatApiArgs(args)); }; } -function createSyncApi(name, fn, protocol, options) { - return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options); +function defineSyncApi(name, fn, protocol, options) { + return defineApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options); } -function createApi(type, name, fn, protocol, options) { +function defineApi(type, name, fn, protocol, options) { switch (type) { case API_TYPE_ON: return wrapperApi(wrapperOnApi(name, fn), name, protocol); @@ -324,7 +324,7 @@ function checkDeviceWidth() { deviceDPR = pixelRatio; isIOS = platform === 'ios'; } -const upx2px = createSyncApi('upx2px', (number, newDeviceWidth) => { +const upx2px = defineSyncApi('upx2px', (number, newDeviceWidth) => { if (deviceWidth === 0) { checkDeviceWidth(); } @@ -506,7 +506,7 @@ function removeHook(hooks, hook) { hooks.splice(index, 1); } } -const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => { +const addInterceptor = defineSyncApi('addInterceptor', (method, interceptor) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); } @@ -514,7 +514,7 @@ const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => mergeInterceptorHook(globalInterceptors, method); } }, AddInterceptorProtocol); -const removeInterceptor = createSyncApi('removeInterceptor', (method, interceptor) => { +const removeInterceptor = defineSyncApi('removeInterceptor', (method, interceptor) => { if (typeof method === 'string') { if (isPlainObject(interceptor)) { removeInterceptorHook(scopedInterceptors[method], interceptor); diff --git a/packages/uni-mp-alipay/src/platform/index.ts b/packages/uni-mp-alipay/src/platform/index.ts index 90ad685ef..17d74c3d2 100644 --- a/packages/uni-mp-alipay/src/platform/index.ts +++ b/packages/uni-mp-alipay/src/platform/index.ts @@ -1,3 +1,5 @@ export function getBaseSystemInfo() { return my.getSystemInfoSync() } + +export function getRealPath() {} diff --git a/packages/uni-mp-baidu/dist/uni.api.esm.js b/packages/uni-mp-baidu/dist/uni.api.esm.js index 669ceff70..5c61058f2 100644 --- a/packages/uni-mp-baidu/dist/uni.api.esm.js +++ b/packages/uni-mp-baidu/dist/uni.api.esm.js @@ -285,10 +285,10 @@ function wrapperApi(fn, name, protocol, options) { return fn.apply(null, formatApiArgs(args)); }; } -function createSyncApi(name, fn, protocol, options) { - return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options); +function defineSyncApi(name, fn, protocol, options) { + return defineApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options); } -function createApi(type, name, fn, protocol, options) { +function defineApi(type, name, fn, protocol, options) { switch (type) { case API_TYPE_ON: return wrapperApi(wrapperOnApi(name, fn), name, protocol); @@ -324,7 +324,7 @@ function checkDeviceWidth() { deviceDPR = pixelRatio; isIOS = platform === 'ios'; } -const upx2px = createSyncApi('upx2px', (number, newDeviceWidth) => { +const upx2px = defineSyncApi('upx2px', (number, newDeviceWidth) => { if (deviceWidth === 0) { checkDeviceWidth(); } @@ -506,7 +506,7 @@ function removeHook(hooks, hook) { hooks.splice(index, 1); } } -const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => { +const addInterceptor = defineSyncApi('addInterceptor', (method, interceptor) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); } @@ -514,7 +514,7 @@ const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => mergeInterceptorHook(globalInterceptors, method); } }, AddInterceptorProtocol); -const removeInterceptor = createSyncApi('removeInterceptor', (method, interceptor) => { +const removeInterceptor = defineSyncApi('removeInterceptor', (method, interceptor) => { if (typeof method === 'string') { if (isPlainObject(interceptor)) { removeInterceptorHook(scopedInterceptors[method], interceptor); diff --git a/packages/uni-mp-baidu/src/platform/index.ts b/packages/uni-mp-baidu/src/platform/index.ts index 2cc117b75..83d36d266 100644 --- a/packages/uni-mp-baidu/src/platform/index.ts +++ b/packages/uni-mp-baidu/src/platform/index.ts @@ -1,3 +1,4 @@ export function getBaseSystemInfo() { return swan.getSystemInfoSync() } +export function getRealPath() {} diff --git a/packages/uni-mp-qq/dist/uni.api.esm.js b/packages/uni-mp-qq/dist/uni.api.esm.js index 1051f5eaf..ee900f0a0 100644 --- a/packages/uni-mp-qq/dist/uni.api.esm.js +++ b/packages/uni-mp-qq/dist/uni.api.esm.js @@ -285,10 +285,10 @@ function wrapperApi(fn, name, protocol, options) { return fn.apply(null, formatApiArgs(args)); }; } -function createSyncApi(name, fn, protocol, options) { - return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options); +function defineSyncApi(name, fn, protocol, options) { + return defineApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options); } -function createApi(type, name, fn, protocol, options) { +function defineApi(type, name, fn, protocol, options) { switch (type) { case API_TYPE_ON: return wrapperApi(wrapperOnApi(name, fn), name, protocol); @@ -324,7 +324,7 @@ function checkDeviceWidth() { deviceDPR = pixelRatio; isIOS = platform === 'ios'; } -const upx2px = createSyncApi('upx2px', (number, newDeviceWidth) => { +const upx2px = defineSyncApi('upx2px', (number, newDeviceWidth) => { if (deviceWidth === 0) { checkDeviceWidth(); } @@ -506,7 +506,7 @@ function removeHook(hooks, hook) { hooks.splice(index, 1); } } -const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => { +const addInterceptor = defineSyncApi('addInterceptor', (method, interceptor) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); } @@ -514,7 +514,7 @@ const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => mergeInterceptorHook(globalInterceptors, method); } }, AddInterceptorProtocol); -const removeInterceptor = createSyncApi('removeInterceptor', (method, interceptor) => { +const removeInterceptor = defineSyncApi('removeInterceptor', (method, interceptor) => { if (typeof method === 'string') { if (isPlainObject(interceptor)) { removeInterceptorHook(scopedInterceptors[method], interceptor); diff --git a/packages/uni-mp-qq/src/platform/index.ts b/packages/uni-mp-qq/src/platform/index.ts index 17dbcd7d2..3a7c0f2bd 100644 --- a/packages/uni-mp-qq/src/platform/index.ts +++ b/packages/uni-mp-qq/src/platform/index.ts @@ -1,3 +1,4 @@ export function getBaseSystemInfo() { return qq.getSystemInfoSync() } +export function getRealPath() {} diff --git a/packages/uni-mp-toutiao/dist/uni.api.esm.js b/packages/uni-mp-toutiao/dist/uni.api.esm.js index d6f7b9ec6..e0aedf590 100644 --- a/packages/uni-mp-toutiao/dist/uni.api.esm.js +++ b/packages/uni-mp-toutiao/dist/uni.api.esm.js @@ -285,10 +285,10 @@ function wrapperApi(fn, name, protocol, options) { return fn.apply(null, formatApiArgs(args)); }; } -function createSyncApi(name, fn, protocol, options) { - return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options); +function defineSyncApi(name, fn, protocol, options) { + return defineApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options); } -function createApi(type, name, fn, protocol, options) { +function defineApi(type, name, fn, protocol, options) { switch (type) { case API_TYPE_ON: return wrapperApi(wrapperOnApi(name, fn), name, protocol); @@ -324,7 +324,7 @@ function checkDeviceWidth() { deviceDPR = pixelRatio; isIOS = platform === 'ios'; } -const upx2px = createSyncApi('upx2px', (number, newDeviceWidth) => { +const upx2px = defineSyncApi('upx2px', (number, newDeviceWidth) => { if (deviceWidth === 0) { checkDeviceWidth(); } @@ -506,7 +506,7 @@ function removeHook(hooks, hook) { hooks.splice(index, 1); } } -const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => { +const addInterceptor = defineSyncApi('addInterceptor', (method, interceptor) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); } @@ -514,7 +514,7 @@ const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => mergeInterceptorHook(globalInterceptors, method); } }, AddInterceptorProtocol); -const removeInterceptor = createSyncApi('removeInterceptor', (method, interceptor) => { +const removeInterceptor = defineSyncApi('removeInterceptor', (method, interceptor) => { if (typeof method === 'string') { if (isPlainObject(interceptor)) { removeInterceptorHook(scopedInterceptors[method], interceptor); diff --git a/packages/uni-mp-toutiao/src/platform/index.ts b/packages/uni-mp-toutiao/src/platform/index.ts index 53a55c0ac..c0e5d97dc 100644 --- a/packages/uni-mp-toutiao/src/platform/index.ts +++ b/packages/uni-mp-toutiao/src/platform/index.ts @@ -1,3 +1,4 @@ export function getBaseSystemInfo() { return tt.getSystemInfoSync() } +export function getRealPath() {} diff --git a/packages/uni-mp-weixin/dist/uni.api.esm.js b/packages/uni-mp-weixin/dist/uni.api.esm.js index 61188fe2a..c83959e42 100644 --- a/packages/uni-mp-weixin/dist/uni.api.esm.js +++ b/packages/uni-mp-weixin/dist/uni.api.esm.js @@ -285,10 +285,10 @@ function wrapperApi(fn, name, protocol, options) { return fn.apply(null, formatApiArgs(args)); }; } -function createSyncApi(name, fn, protocol, options) { - return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options); +function defineSyncApi(name, fn, protocol, options) { + return defineApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options); } -function createApi(type, name, fn, protocol, options) { +function defineApi(type, name, fn, protocol, options) { switch (type) { case API_TYPE_ON: return wrapperApi(wrapperOnApi(name, fn), name, protocol); @@ -324,7 +324,7 @@ function checkDeviceWidth() { deviceDPR = pixelRatio; isIOS = platform === 'ios'; } -const upx2px = createSyncApi('upx2px', (number, newDeviceWidth) => { +const upx2px = defineSyncApi('upx2px', (number, newDeviceWidth) => { if (deviceWidth === 0) { checkDeviceWidth(); } @@ -506,7 +506,7 @@ function removeHook(hooks, hook) { hooks.splice(index, 1); } } -const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => { +const addInterceptor = defineSyncApi('addInterceptor', (method, interceptor) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); } @@ -514,7 +514,7 @@ const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => mergeInterceptorHook(globalInterceptors, method); } }, AddInterceptorProtocol); -const removeInterceptor = createSyncApi('removeInterceptor', (method, interceptor) => { +const removeInterceptor = defineSyncApi('removeInterceptor', (method, interceptor) => { if (typeof method === 'string') { if (isPlainObject(interceptor)) { removeInterceptorHook(scopedInterceptors[method], interceptor); diff --git a/packages/uni-mp-weixin/src/platform/index.ts b/packages/uni-mp-weixin/src/platform/index.ts index 80a7678ea..62fc2536f 100644 --- a/packages/uni-mp-weixin/src/platform/index.ts +++ b/packages/uni-mp-weixin/src/platform/index.ts @@ -1,3 +1,4 @@ export function getBaseSystemInfo() { return wx.getSystemInfoSync() } +export function getRealPath() {} diff --git a/packages/uni-quickapp-webview/dist/uni.api.esm.js b/packages/uni-quickapp-webview/dist/uni.api.esm.js index d4339b392..4d2deebc0 100644 --- a/packages/uni-quickapp-webview/dist/uni.api.esm.js +++ b/packages/uni-quickapp-webview/dist/uni.api.esm.js @@ -285,10 +285,10 @@ function wrapperApi(fn, name, protocol, options) { return fn.apply(null, formatApiArgs(args)); }; } -function createSyncApi(name, fn, protocol, options) { - return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options); +function defineSyncApi(name, fn, protocol, options) { + return defineApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options); } -function createApi(type, name, fn, protocol, options) { +function defineApi(type, name, fn, protocol, options) { switch (type) { case API_TYPE_ON: return wrapperApi(wrapperOnApi(name, fn), name, protocol); @@ -324,7 +324,7 @@ function checkDeviceWidth() { deviceDPR = pixelRatio; isIOS = platform === 'ios'; } -const upx2px = createSyncApi('upx2px', (number, newDeviceWidth) => { +const upx2px = defineSyncApi('upx2px', (number, newDeviceWidth) => { if (deviceWidth === 0) { checkDeviceWidth(); } @@ -506,7 +506,7 @@ function removeHook(hooks, hook) { hooks.splice(index, 1); } } -const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => { +const addInterceptor = defineSyncApi('addInterceptor', (method, interceptor) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); } @@ -514,7 +514,7 @@ const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => mergeInterceptorHook(globalInterceptors, method); } }, AddInterceptorProtocol); -const removeInterceptor = createSyncApi('removeInterceptor', (method, interceptor) => { +const removeInterceptor = defineSyncApi('removeInterceptor', (method, interceptor) => { if (typeof method === 'string') { if (isPlainObject(interceptor)) { removeInterceptorHook(scopedInterceptors[method], interceptor); diff --git a/packages/uni-quickapp-webview/src/platform/index.ts b/packages/uni-quickapp-webview/src/platform/index.ts index 2d4565e6a..712a47d9a 100644 --- a/packages/uni-quickapp-webview/src/platform/index.ts +++ b/packages/uni-quickapp-webview/src/platform/index.ts @@ -1,3 +1,4 @@ export function getBaseSystemInfo() { return qa.getSystemInfoSync() } +export function getRealPath() {} -- GitLab