提交 84969ca6 编写于 作者: fxy060608's avatar fxy060608

refactor: type cast => generics

上级 de71b7e4
......@@ -96,7 +96,7 @@ export class MapContext implements UniApp.MapContext {
}
}
export const createMapContext = <API_TYPE_CREATE_MAP_CONTEXT>defineSyncApi(
export const createMapContext = defineSyncApi<API_TYPE_CREATE_MAP_CONTEXT>(
API_CREATE_MAP_CONTEXT,
(id, context) => {
if (context) {
......
......@@ -206,12 +206,12 @@ class SelectorQuery implements UniApp.SelectorQuery {
}
}
export const createSelectorQuery = <typeof uni.createSelectorQuery>(
defineSyncApi('createSelectorQuery', (context?: any) => {
context = resolveComponentInstance(context)
if (context && !getPageIdByVm(context)) {
context = null
}
return new SelectorQuery(context || getCurrentPageVm()!)
})
)
export const createSelectorQuery = defineSyncApi<
typeof uni.createSelectorQuery
>('createSelectorQuery', (context?: any) => {
context = resolveComponentInstance(context)
if (context && !getPageIdByVm(context)) {
context = null
}
return new SelectorQuery(context || getCurrentPageVm()!)
})
......@@ -18,7 +18,10 @@ export const getLocale = defineSyncApi<typeof uni.getLocale>(
}
)
export const onLocaleChange = defineOnApi(API_ON_LOCALE_CHANGE, () => {})
export const onLocaleChange = defineOnApi<typeof uni.onLocaleChange>(
API_ON_LOCALE_CHANGE,
() => {}
)
export const setLocale = defineSyncApi<typeof uni.setLocale>(
API_SET_LOCALE,
......
......@@ -10872,13 +10872,13 @@ class SelectorQuery {
this._queueCb.push(callback);
}
}
const createSelectorQuery = (defineSyncApi('createSelectorQuery', (context) => {
const createSelectorQuery = defineSyncApi('createSelectorQuery', (context) => {
context = resolveComponentInstance(context);
if (context && !getPageIdByVm(context)) {
context = null;
}
return new SelectorQuery(context || getCurrentPageVm());
}));
});
// import { elemInArray } from '../../helpers/protocol'
const API_CREATE_ANIMATION = 'createAnimation';
......@@ -13030,7 +13030,7 @@ function parseGetStorage(type, value) {
}
return data;
}
const getStorageSync = defineSyncApi(API_GET_STORAGE_SYNC, (key, t) => {
const getStorageSync = defineSyncApi(API_GET_STORAGE_SYNC, (key) => {
const value = plus.storage.getItem(key);
const typeOrigin = plus.storage.getItem(key + STORAGE_DATA_TYPE) || '';
const type = typeOrigin.toLowerCase();
......@@ -13065,13 +13065,13 @@ const removeStorage = defineAsyncApi(API_REMOVE_STORAGE, ({ key }, { resolve, re
plus.storage.removeItemAsync(key + STORAGE_DATA_TYPE);
plus.storage.removeItemAsync(key, resolve, warpPlusErrorCallback(reject));
}, RemoveStorageProtocol);
const clearStorageSync = (defineSyncApi('clearStorageSync', () => {
const clearStorageSync = defineSyncApi('clearStorageSync', () => {
plus.storage.clear();
}));
const clearStorage = (defineAsyncApi('clearStorage', (_, { resolve, reject }) => {
});
const clearStorage = defineAsyncApi('clearStorage', (_, { resolve, reject }) => {
plus.storage.clearAsync(resolve, warpPlusErrorCallback(reject));
}));
const getStorageInfoSync = (defineSyncApi('getStorageInfoSync', () => {
});
const getStorageInfoSync = defineSyncApi('getStorageInfoSync', () => {
const length = plus.storage.getLength() || 0;
const keys = [];
let currentSize = 0;
......@@ -13091,10 +13091,10 @@ const getStorageInfoSync = (defineSyncApi('getStorageInfoSync', () => {
currentSize: Math.ceil((currentSize * 2) / 1024),
limitSize: Number.MAX_VALUE,
};
}));
const getStorageInfo = (defineAsyncApi('getStorageInfo', (_, { resolve }) => {
});
const getStorageInfo = defineAsyncApi('getStorageInfo', (_, { resolve }) => {
resolve(getStorageInfoSync());
}));
});
const getFileInfo$1 = defineAsyncApi(API_GET_FILE_INFO, (options, { resolve, reject }) => {
plus.io.getFileInfo(extend(options, {
......@@ -13144,7 +13144,7 @@ function getSavedFileDir(success, fail) {
}, success, fail);
}, fail);
}
const getSavedFileList = (defineAsyncApi(API_GET_SAVED_LIST, (_, { resolve, reject }) => {
const getSavedFileList = defineAsyncApi(API_GET_SAVED_LIST, (_, { resolve, reject }) => {
const errorCallback = warpPlusErrorCallback(reject);
getSavedFileDir((entry) => {
var reader = entry.createReader();
......@@ -13173,7 +13173,7 @@ const getSavedFileList = (defineAsyncApi(API_GET_SAVED_LIST, (_, { resolve, reje
}
}, errorCallback);
}, errorCallback);
}));
});
const getSavedFileInfo = defineAsyncApi(API_GET_SAVED_FILE_INFO, ({ filePath }, { resolve, reject }) => {
const errorCallback = warpPlusErrorCallback(reject);
......@@ -13626,13 +13626,13 @@ const getSystemInfo = defineAsyncApi('getSystemInfo', (_, { resolve }) => {
});
let listener$1 = null;
const onCompassChange = (defineOnApi(API_ON_COMPASS, () => {
const onCompassChange = defineOnApi(API_ON_COMPASS, () => {
startCompass();
}));
const offCompassChange = (defineOffApi(API_OFF_COMPASS, () => {
});
const offCompassChange = defineOffApi(API_OFF_COMPASS, () => {
stopCompass();
}));
const startCompass = (defineAsyncApi(API_START_COMPASS, (_, { resolve, reject }) => {
});
const startCompass = defineAsyncApi(API_START_COMPASS, (_, { resolve, reject }) => {
if (!listener$1) {
listener$1 = plus.orientation.watchOrientation((res) => {
UniServiceJSBridge.invokeOnCallback(API_ON_COMPASS, {
......@@ -13646,14 +13646,14 @@ const startCompass = (defineAsyncApi(API_START_COMPASS, (_, { resolve, reject })
});
}
setTimeout(resolve, DEVICE_FREQUENCY);
}));
const stopCompass = (defineAsyncApi(API_STOP_COMPASS, (_, { resolve }) => {
});
const stopCompass = defineAsyncApi(API_STOP_COMPASS, (_, { resolve }) => {
if (listener$1) {
plus.orientation.clearWatch(listener$1);
listener$1 = null;
}
resolve();
}));
});
const vibrateShort = defineAsyncApi(API_VIBRATE_SHORT, (_, { resolve }) => {
plus.device.vibrate(15);
......@@ -13665,13 +13665,13 @@ const vibrateLong = defineAsyncApi(API_VIBRATE_LONG, (_, { resolve }) => {
});
let listener = null;
const onAccelerometerChange = (defineOnApi(API_ON_ACCELEROMETER, () => {
const onAccelerometerChange = defineOnApi(API_ON_ACCELEROMETER, () => {
startAccelerometer();
}));
const offAccelerometerChange = (defineOffApi(API_OFF_ACCELEROMETER, () => {
});
const offAccelerometerChange = defineOffApi(API_OFF_ACCELEROMETER, () => {
stopAccelerometer();
}));
const startAccelerometer = (defineAsyncApi(API_START_ACCELEROMETER, (_, { resolve, reject }) => {
});
const startAccelerometer = defineAsyncApi(API_START_ACCELEROMETER, (_, { resolve, reject }) => {
if (!listener) {
listener = plus.accelerometer.watchAcceleration((res) => {
UniServiceJSBridge.invokeOnCallback(API_ON_ACCELEROMETER, {
......@@ -13687,14 +13687,14 @@ const startAccelerometer = (defineAsyncApi(API_START_ACCELEROMETER, (_, { resolv
});
}
setTimeout(resolve, DEVICE_FREQUENCY);
}));
const stopAccelerometer = (defineAsyncApi(API_STOP_ACCELEROMETER, (_, { resolve }) => {
});
const stopAccelerometer = defineAsyncApi(API_STOP_ACCELEROMETER, (_, { resolve }) => {
if (listener) {
plus.accelerometer.clearWatch(listener);
listener = null;
}
resolve();
}));
});
const onBluetoothDeviceFound = defineOnApi(API_ON_BLUETOOTH_DEVICE_FOUND, warpPlusEvent(() => plus.bluetooth.onBluetoothDeviceFound.bind(plus.bluetooth), API_ON_BLUETOOTH_DEVICE_FOUND));
const onBluetoothAdapterStateChange = defineOnApi(API_ON_BLUETOOTH_ADAPTER_STATE_CHANGE, warpPlusEvent(() => plus.bluetooth.onBluetoothAdapterStateChange.bind(plus.bluetooth), API_ON_BLUETOOTH_ADAPTER_STATE_CHANGE));
......@@ -16183,7 +16183,7 @@ let watchId = 0;
/**
* 开始更新定位
*/
const startLocationUpdate = (defineAsyncApi(API_START_LOCATION_UPDATE, (_, { resolve, reject }) => {
const startLocationUpdate = defineAsyncApi(API_START_LOCATION_UPDATE, (_, { resolve, reject }) => {
if (plus.geolocation && watchId === 0) {
watchId = plus.geolocation.watchPosition((res) => {
UniServiceJSBridge.invokeOnCallback(API_ON_LOCATION_CHANGE, res.coords);
......@@ -16198,9 +16198,9 @@ const startLocationUpdate = (defineAsyncApi(API_START_LOCATION_UPDATE, (_, { res
UniServiceJSBridge.invokeOnCallback(API_ON_LOCATION_CHANGE_ERROR, 'onLocationChange:fail');
}
resolve();
}, StartLocationUpdateProtocol, StartLocationUpdateOptions));
const onLocationChange = (defineOnApi(API_ON_LOCATION_CHANGE, () => { }));
const stopLocationUpdate = (defineAsyncApi(API_STOP_LOCATION_UPDATE, (_, { resolve, reject }) => {
}, StartLocationUpdateProtocol, StartLocationUpdateOptions);
const onLocationChange = defineOnApi(API_ON_LOCATION_CHANGE, () => { });
const stopLocationUpdate = defineAsyncApi(API_STOP_LOCATION_UPDATE, (_, { resolve, reject }) => {
if (watchId) {
plus.geolocation.clearWatch(watchId);
watchId = 0;
......@@ -16209,12 +16209,12 @@ const stopLocationUpdate = (defineAsyncApi(API_STOP_LOCATION_UPDATE, (_, { resol
else {
reject('stopLocationUpdate:fail');
}
}));
const offLocationChange = (defineOffApi(API_OFF_LOCATION_CHANGE, () => {
});
const offLocationChange = defineOffApi(API_OFF_LOCATION_CHANGE, () => {
stopLocationUpdate();
}));
const onLocationChangeError = (defineOnApi(API_ON_LOCATION_CHANGE_ERROR, () => { }));
const offLocationChangeError = (defineOnApi(API_OFF_LOCATION_CHANGE_ERROR, () => { }));
});
const onLocationChangeError = defineOnApi(API_ON_LOCATION_CHANGE_ERROR, () => { });
const offLocationChangeError = defineOnApi(API_OFF_LOCATION_CHANGE_ERROR, () => { });
const showModal = defineAsyncApi(API_SHOW_MODAL, ({ title = '', content = '', showCancel = true, cancelText, cancelColor, confirmText, confirmColor, editable = false, placeholderText = '', } = {}, { resolve }) => {
const buttons = showCancel ? [cancelText, confirmText] : [confirmText];
......@@ -17367,9 +17367,9 @@ class RewardedVideoAd extends AdBase {
this._loadAd();
}
}
const createRewardedVideoAd = (defineSyncApi(API_CREATE_REWARDED_VIDEO_AD, (options) => {
const createRewardedVideoAd = defineSyncApi(API_CREATE_REWARDED_VIDEO_AD, (options) => {
return new RewardedVideoAd(options);
}, CreateRewardedVideoAdProtocol, CreateRewardedVideoAdOptions));
}, CreateRewardedVideoAdProtocol, CreateRewardedVideoAdOptions);
class FullScreenVideoAd extends AdBase {
constructor(options) {
......@@ -17377,9 +17377,9 @@ class FullScreenVideoAd extends AdBase {
this.preload = false;
}
}
const createFullScreenVideoAd = (defineSyncApi(API_CREATE_FULL_SCREEN_VIDEO_AD, (options) => {
const createFullScreenVideoAd = defineSyncApi(API_CREATE_FULL_SCREEN_VIDEO_AD, (options) => {
return new FullScreenVideoAd(options);
}, CreateFullScreenVideoAdProtocol, CreateFullScreenVideoAdOptions));
}, CreateFullScreenVideoAdProtocol, CreateFullScreenVideoAdOptions);
class InterstitialAd extends AdBase {
constructor(options) {
......@@ -17388,9 +17388,9 @@ class InterstitialAd extends AdBase {
this._loadAd();
}
}
const createInterstitialAd = (defineSyncApi(API_CREATE_INTERSTITIAL_AD, (options) => {
const createInterstitialAd = defineSyncApi(API_CREATE_INTERSTITIAL_AD, (options) => {
return new InterstitialAd(options);
}, CreateInterstitialAdProtocol, CreateInterstitialAdOptions));
}, CreateInterstitialAdProtocol, CreateInterstitialAdOptions);
const sdkCache = {};
const sdkQueue = {};
......@@ -17598,9 +17598,9 @@ class InteractiveAd extends AdEventHandler {
return new Error(JSON.stringify(err));
}
}
const createInteractiveAd = (defineSyncApi(API_CREATE_INTERACTIVE_AD, (options) => {
const createInteractiveAd = defineSyncApi(API_CREATE_INTERACTIVE_AD, (options) => {
return new InteractiveAd(options);
}, CreateInteractiveAdProtocol, CreateInteractiveAdOptions));
}, CreateInteractiveAdProtocol, CreateInteractiveAdOptions);
const downgrade = plus.os.name === 'Android' && parseInt(plus.os.version) < 6;
const ANI_SHOW = downgrade ? 'slide-in-right' : 'pop-in';
......
......@@ -18,8 +18,8 @@ class FullScreenVideoAd
}
}
export const createFullScreenVideoAd = <API_TYPE_CREATE_FULL_SCREEN_VIDEO_AD>(
defineSyncApi(
export const createFullScreenVideoAd =
defineSyncApi<API_TYPE_CREATE_FULL_SCREEN_VIDEO_AD>(
API_CREATE_FULL_SCREEN_VIDEO_AD,
(options) => {
return new FullScreenVideoAd(options)
......@@ -27,4 +27,3 @@ export const createFullScreenVideoAd = <API_TYPE_CREATE_FULL_SCREEN_VIDEO_AD>(
CreateFullScreenVideoAdProtocol,
CreateFullScreenVideoAdOptions
)
)
......@@ -258,8 +258,8 @@ class InteractiveAd
}
}
export const createInteractiveAd = <API_TYPE_CREATE_INTERACTIVE_AD>(
defineSyncApi(
export const createInteractiveAd =
defineSyncApi<API_TYPE_CREATE_INTERACTIVE_AD>(
API_CREATE_INTERACTIVE_AD,
(options) => {
return new InteractiveAd(options)
......@@ -267,4 +267,3 @@ export const createInteractiveAd = <API_TYPE_CREATE_INTERACTIVE_AD>(
CreateInteractiveAdProtocol,
CreateInteractiveAdOptions
)
)
......@@ -16,8 +16,8 @@ class InterstitialAd extends AdBase implements UniApp.InterstitialAdContext {
}
}
export const createInterstitialAd = <API_TYPE_CREATE_INTERSTITIAL_AD>(
defineSyncApi(
export const createInterstitialAd =
defineSyncApi<API_TYPE_CREATE_INTERSTITIAL_AD>(
API_CREATE_INTERSTITIAL_AD,
(options) => {
return new InterstitialAd(options)
......@@ -25,4 +25,3 @@ export const createInterstitialAd = <API_TYPE_CREATE_INTERSTITIAL_AD>(
CreateInterstitialAdProtocol,
CreateInterstitialAdOptions
)
)
......@@ -16,8 +16,8 @@ class RewardedVideoAd extends AdBase implements UniApp.RewardedVideoAdContext {
}
}
export const createRewardedVideoAd = <API_TYPE_CREATE_REWARDED_VIDEO_AD>(
defineSyncApi(
export const createRewardedVideoAd =
defineSyncApi<API_TYPE_CREATE_REWARDED_VIDEO_AD>(
API_CREATE_REWARDED_VIDEO_AD,
(options) => {
return new RewardedVideoAd(options)
......@@ -25,4 +25,3 @@ export const createRewardedVideoAd = <API_TYPE_CREATE_REWARDED_VIDEO_AD>(
CreateRewardedVideoAdProtocol,
CreateRewardedVideoAdOptions
)
)
......@@ -15,20 +15,19 @@ import { DEVICE_FREQUENCY } from '../constants'
let listener: number | null = null
export const onAccelerometerChange = <API_TYPE_ON_ACCELEROMETER_CHANGE>(
defineOnApi(API_ON_ACCELEROMETER, () => {
export const onAccelerometerChange =
defineOnApi<API_TYPE_ON_ACCELEROMETER_CHANGE>(API_ON_ACCELEROMETER, () => {
startAccelerometer()
})
)
export const offAccelerometerChange = <API_TYPE_OFF_ACCELEROMETER_CHANGE>(
defineOffApi(API_OFF_ACCELEROMETER, () => {
export const offAccelerometerChange =
defineOffApi<API_TYPE_OFF_ACCELEROMETER_CHANGE>(API_OFF_ACCELEROMETER, () => {
stopAccelerometer()
})
)
export const startAccelerometer = <API_TYPE_START_ACCELEROMETER>(
defineAsyncApi(API_START_ACCELEROMETER, (_, { resolve, reject }) => {
export const startAccelerometer = defineAsyncApi<API_TYPE_START_ACCELEROMETER>(
API_START_ACCELEROMETER,
(_, { resolve, reject }) => {
if (!listener) {
listener = plus.accelerometer.watchAcceleration(
(res) => {
......@@ -49,15 +48,16 @@ export const startAccelerometer = <API_TYPE_START_ACCELEROMETER>(
}
setTimeout(resolve, DEVICE_FREQUENCY)
})
}
)
export const stopAccelerometer = <API_TYPE_STOP_ACCELEROMETER>(
defineAsyncApi(API_STOP_ACCELEROMETER, (_, { resolve }) => {
export const stopAccelerometer = defineAsyncApi<API_TYPE_STOP_ACCELEROMETER>(
API_STOP_ACCELEROMETER,
(_, { resolve }) => {
if (listener) {
plus.accelerometer.clearWatch(listener)
listener = null
}
resolve()
})
}
)
......@@ -15,20 +15,23 @@ import { DEVICE_FREQUENCY } from '../constants'
let listener: number | null = null
export const onCompassChange = <API_TYPE_ON_COMPASS_CHANGE>(
defineOnApi(API_ON_COMPASS, () => {
export const onCompassChange = defineOnApi<API_TYPE_ON_COMPASS_CHANGE>(
API_ON_COMPASS,
() => {
startCompass()
})
}
)
export const offCompassChange = <API_TYPE_OFF_COMPASS_CHANGE>(
defineOffApi(API_OFF_COMPASS, () => {
export const offCompassChange = defineOffApi<API_TYPE_OFF_COMPASS_CHANGE>(
API_OFF_COMPASS,
() => {
stopCompass()
})
}
)
export const startCompass = <API_TYPE_START_COMPASS>(
defineAsyncApi(API_START_COMPASS, (_, { resolve, reject }) => {
export const startCompass = defineAsyncApi<API_TYPE_START_COMPASS>(
API_START_COMPASS,
(_, { resolve, reject }) => {
if (!listener) {
listener = plus.orientation.watchOrientation(
(res) => {
......@@ -46,15 +49,16 @@ export const startCompass = <API_TYPE_START_COMPASS>(
)
}
setTimeout(resolve, DEVICE_FREQUENCY)
})
}
)
export const stopCompass = <API_TYPE_STOP_COMPASS>(
defineAsyncApi(API_STOP_COMPASS, (_, { resolve }) => {
export const stopCompass = defineAsyncApi<API_TYPE_STOP_COMPASS>(
API_STOP_COMPASS,
(_, { resolve }) => {
if (listener) {
plus.orientation.clearWatch(listener)
listener = null
}
resolve()
})
}
)
......@@ -11,7 +11,7 @@ import {
warpPlusErrorCallback,
} from '../../../helpers/plus'
export const getFileInfo = <API_TYPE_GET_FILE_INFO>defineAsyncApi(
export const getFileInfo = defineAsyncApi<API_TYPE_GET_FILE_INFO>(
API_GET_FILE_INFO,
(options, { resolve, reject }) => {
plus.io.getFileInfo(
......
......@@ -7,7 +7,7 @@ import {
} from '@dcloudio/uni-api'
import { warpPlusErrorCallback } from '../../../helpers/plus'
export const getSavedFileInfo = <API_TYPE_GET_SAVED_FILE_INFO>defineAsyncApi(
export const getSavedFileInfo = defineAsyncApi<API_TYPE_GET_SAVED_FILE_INFO>(
API_GET_SAVED_FILE_INFO,
({ filePath }, { resolve, reject }) => {
const errorCallback = warpPlusErrorCallback(reject)
......
......@@ -30,20 +30,21 @@ function getSavedFileDir(
)
}
export const getSavedFileList = <API_TYPE_GET_SAVED_LIST>(
defineAsyncApi(API_GET_SAVED_LIST, (_, { resolve, reject }) => {
export const getSavedFileList = defineAsyncApi<API_TYPE_GET_SAVED_LIST>(
API_GET_SAVED_LIST,
(_, { resolve, reject }) => {
const errorCallback = warpPlusErrorCallback(reject)
getSavedFileDir((entry) => {
var reader = entry.createReader()
var fileList: object[] = []
var fileList: UniApp.GetSavedFileListSuccessFileItem[] = []
reader.readEntries((entries: any[]) => {
if (entries && entries.length) {
entries.forEach((entry) => {
entry.getMetadata(
(meta: {
modificationTime: { getTime: () => void }
modificationTime: { getTime: () => number }
size: any
}) => {
fileList.push({
......@@ -68,5 +69,5 @@ export const getSavedFileList = <API_TYPE_GET_SAVED_LIST>(
}
}, errorCallback)
}, errorCallback)
})
}
)
......@@ -7,7 +7,7 @@ import {
} from '@dcloudio/uni-api'
import { warpPlusErrorCallback } from '../../../helpers/plus'
export const removeSavedFile = <API_TYPE_REMOVE_SAVED_FILE>defineAsyncApi(
export const removeSavedFile = defineAsyncApi<API_TYPE_REMOVE_SAVED_FILE>(
API_REMOVE_SAVED_FILE,
({ filePath }, { resolve, reject }) => {
const errorCallback = warpPlusErrorCallback(reject)
......
......@@ -35,7 +35,7 @@ function getSavedFileDir(
)
}
export const saveFile = <API_TYPE_SAVE_FILE>defineAsyncApi(
export const saveFile = defineAsyncApi<API_TYPE_SAVE_FILE>(
API_SAVE_FILE,
({ tempFilePath }, { resolve, reject }) => {
const errorCallback = warpPlusErrorCallback(reject)
......
......@@ -9,7 +9,7 @@ import { showPage } from '@dcloudio/uni-core'
import { getStatusBarStyle } from '../../../helpers/statusBar'
import { extend } from '@vue/shared'
export const chooseLocation = <API_TYPE_CHOOSE_LOCATION>defineAsyncApi(
export const chooseLocation = defineAsyncApi<API_TYPE_CHOOSE_LOCATION>(
API_CHOOSE_LOCATION,
(options, { resolve, reject }) => {
const statusBarStyle = getStatusBarStyle()
......
......@@ -39,7 +39,7 @@ function getLocationSuccess(
})
}
export const getLocation = <API_TYPE_GET_LOCATION>defineAsyncApi(
export const getLocation = defineAsyncApi<API_TYPE_GET_LOCATION>(
API_GET_LOCATION,
(
{
......
......@@ -23,8 +23,8 @@ let watchId: number = 0
/**
* 开始更新定位
*/
export const startLocationUpdate = <API_TYPE_START_LOCATION_UPDATE>(
defineAsyncApi(
export const startLocationUpdate =
defineAsyncApi<API_TYPE_START_LOCATION_UPDATE>(
API_START_LOCATION_UPDATE,
(_, { resolve, reject }) => {
if (plus.geolocation && watchId === 0) {
......@@ -54,14 +54,15 @@ export const startLocationUpdate = <API_TYPE_START_LOCATION_UPDATE>(
StartLocationUpdateProtocol,
StartLocationUpdateOptions
)
)
export const onLocationChange = <API_TYPE_ON_LOCATION_CHANGE>(
defineOnApi(API_ON_LOCATION_CHANGE, () => {})
export const onLocationChange = defineOnApi<API_TYPE_ON_LOCATION_CHANGE>(
API_ON_LOCATION_CHANGE,
() => {}
)
export const stopLocationUpdate = <API_TYPE_STOP_LOCATION_UPDATE>(
defineAsyncApi(API_STOP_LOCATION_UPDATE, (_, { resolve, reject }) => {
export const stopLocationUpdate = defineAsyncApi<API_TYPE_STOP_LOCATION_UPDATE>(
API_STOP_LOCATION_UPDATE,
(_, { resolve, reject }) => {
if (watchId) {
plus.geolocation.clearWatch(watchId)
watchId = 0
......@@ -69,19 +70,24 @@ export const stopLocationUpdate = <API_TYPE_STOP_LOCATION_UPDATE>(
} else {
reject('stopLocationUpdate:fail')
}
})
}
)
export const offLocationChange = <API_TYPE_OFF_LOCATION_CHANGE>(
defineOffApi(API_OFF_LOCATION_CHANGE, () => {
export const offLocationChange = defineOffApi<API_TYPE_OFF_LOCATION_CHANGE>(
API_OFF_LOCATION_CHANGE,
() => {
stopLocationUpdate()
})
}
)
export const onLocationChangeError = <API_TYPE_ON_LOCATION_CHANGE_ERROR>(
defineOnApi(API_ON_LOCATION_CHANGE_ERROR, () => {})
)
export const onLocationChangeError =
defineOnApi<API_TYPE_ON_LOCATION_CHANGE_ERROR>(
API_ON_LOCATION_CHANGE_ERROR,
() => {}
)
export const offLocationChangeError = <API_TYPE_OFF_LOCATION_CHANGE_ERROR>(
defineOnApi(API_OFF_LOCATION_CHANGE_ERROR, () => {})
)
export const offLocationChangeError =
defineOnApi<API_TYPE_OFF_LOCATION_CHANGE_ERROR>(
API_OFF_LOCATION_CHANGE_ERROR,
() => {}
)
......@@ -9,7 +9,7 @@ import {
import { showPage } from '@dcloudio/uni-core'
import { extend } from '@vue/shared'
export const openLocation = <API_TYPE_OPEN_LOCATION>defineAsyncApi(
export const openLocation = defineAsyncApi<API_TYPE_OPEN_LOCATION>(
API_OPEN_LOCATION,
(data, { resolve, reject }) => {
showPage({
......
......@@ -7,7 +7,7 @@ import {
} from '@dcloudio/uni-api'
import { warpPlusErrorCallback } from '../../../helpers/plus'
export const getVideoInfo = <API_TYPE_GET_VIDEO_INFO>defineAsyncApi(
export const getVideoInfo = defineAsyncApi<API_TYPE_GET_VIDEO_INFO>(
API_GET_VIDEO_INFO,
(options, { resolve, reject }) => {
plus.io.getVideoInfo({
......
......@@ -14,7 +14,7 @@ import { initI18nPreviewImageMsgsOnce, useI18n } from '@dcloudio/uni-core'
import { getRealPath } from '../../../platform/getRealPath'
export const previewImage = <API_TYPE_PREVIEW_IMAGE>defineAsyncApi(
export const previewImage = defineAsyncApi<API_TYPE_PREVIEW_IMAGE>(
API_PREVIEW_IMAGE,
(
{ current = 0, indicator = 'number', loop = false, urls, longPressActions },
......
......@@ -53,7 +53,7 @@ function parseValue(value: any) {
} catch (error) {}
}
export const setStorageSync = <API_TYPE_SET_STORAGE_SYNC>defineSyncApi(
export const setStorageSync = defineSyncApi<API_TYPE_SET_STORAGE_SYNC>(
API_SET_STORAGE_SYNC,
(key, data) => {
const type = typeof data
......@@ -76,7 +76,7 @@ export const setStorageSync = <API_TYPE_SET_STORAGE_SYNC>defineSyncApi(
SetStorageSyncProtocol
)
export const setStorage = <API_TYPE_SET_STORAGE>defineAsyncApi(
export const setStorage = defineAsyncApi<API_TYPE_SET_STORAGE>(
API_SET_STORAGE,
({ key, data }, { resolve, reject }) => {
const type = typeof data
......@@ -135,9 +135,9 @@ function parseGetStorage(type: string, value: string) {
return data
}
export const getStorageSync = <API_TYPE_GET_STORAGE_SYNC>defineSyncApi(
export const getStorageSync = defineSyncApi<API_TYPE_GET_STORAGE_SYNC>(
API_GET_STORAGE_SYNC,
(key: string, t: boolean) => {
(key: string) => {
const value = plus.storage.getItem(key)
const typeOrigin = plus.storage.getItem(key + STORAGE_DATA_TYPE) || ''
const type = typeOrigin.toLowerCase()
......@@ -149,7 +149,7 @@ export const getStorageSync = <API_TYPE_GET_STORAGE_SYNC>defineSyncApi(
GetStorageSyncProtocol
)
export const getStorage = <API_TYPE_GET_STORAGE>defineAsyncApi(
export const getStorage = defineAsyncApi<API_TYPE_GET_STORAGE>(
API_GET_STORAGE,
({ key }, { resolve, reject }) => {
const storage = plus.storage
......@@ -179,7 +179,7 @@ export const getStorage = <API_TYPE_GET_STORAGE>defineAsyncApi(
GetStorageProtocol
)
export const removeStorageSync = <API_TYPE_REMOVE_STORAGE_SYNC>defineSyncApi(
export const removeStorageSync = defineSyncApi<API_TYPE_REMOVE_STORAGE_SYNC>(
API_REMOVE_STORAGE,
(key) => {
plus.storage.removeItem(key + STORAGE_DATA_TYPE)
......@@ -188,7 +188,7 @@ export const removeStorageSync = <API_TYPE_REMOVE_STORAGE_SYNC>defineSyncApi(
RemoveStorageSyncProtocol
)
export const removeStorage = <API_TYPE_REMOVE_STORAGE>defineAsyncApi(
export const removeStorage = defineAsyncApi<API_TYPE_REMOVE_STORAGE>(
API_REMOVE_STORAGE,
({ key }, { resolve, reject }) => {
// 兼容App端历史格式
......@@ -198,20 +198,23 @@ export const removeStorage = <API_TYPE_REMOVE_STORAGE>defineAsyncApi(
RemoveStorageProtocol
)
export const clearStorageSync = <typeof uni.clearStorageSync>(
defineSyncApi('clearStorageSync', () => {
export const clearStorageSync = defineSyncApi<typeof uni.clearStorageSync>(
'clearStorageSync',
() => {
plus.storage.clear()
})
}
)
export const clearStorage = <typeof uni.clearStorage>(
defineAsyncApi('clearStorage', (_, { resolve, reject }) => {
export const clearStorage = defineAsyncApi<typeof uni.clearStorage>(
'clearStorage',
(_, { resolve, reject }) => {
plus.storage.clearAsync(resolve, warpPlusErrorCallback(reject))
})
}
)
export const getStorageInfoSync = <typeof uni.getStorageInfoSync>(
defineSyncApi('getStorageInfoSync', () => {
export const getStorageInfoSync = defineSyncApi<typeof uni.getStorageInfoSync>(
'getStorageInfoSync',
() => {
const length = plus.storage.getLength() || 0
const keys: string[] = []
let currentSize = 0
......@@ -233,11 +236,12 @@ export const getStorageInfoSync = <typeof uni.getStorageInfoSync>(
currentSize: Math.ceil((currentSize * 2) / 1024),
limitSize: Number.MAX_VALUE,
}
})
}
)
export const getStorageInfo = <typeof uni.getStorageInfo>(
defineAsyncApi('getStorageInfo', (_, { resolve }) => {
export const getStorageInfo = defineAsyncApi<typeof uni.getStorageInfo>(
'getStorageInfo',
(_, { resolve }) => {
resolve(getStorageInfoSync())
})
}
)
......@@ -118,7 +118,7 @@
"reLaunch",
"redirectTo",
"removeInterceptor",
"removeSavedFileInfo",
"removeSavedFile",
"removeStorage",
"removeStorageSync",
"removeTabBarBadge",
......
......@@ -10143,7 +10143,7 @@ function getStorageOrigin(key) {
}
return data;
}
const getStorageSync = /* @__PURE__ */ defineSyncApi(API_GET_STORAGE_SYNC, (key, t2) => {
const getStorageSync = /* @__PURE__ */ defineSyncApi(API_GET_STORAGE_SYNC, (key) => {
try {
return getStorageOrigin(key);
} catch (error) {
......
......@@ -17172,7 +17172,7 @@ function getStorageOrigin(key) {
}
return data;
}
const getStorageSync = /* @__PURE__ */ defineSyncApi(API_GET_STORAGE_SYNC, (key, t2) => {
const getStorageSync = /* @__PURE__ */ defineSyncApi(API_GET_STORAGE_SYNC, (key) => {
try {
return getStorageOrigin(key);
} catch (error) {
......@@ -20562,8 +20562,8 @@ const API_GET_SAVED_FILE_LIST = "getSavedFileList";
const getSavedFileList = /* @__PURE__ */ defineAsyncApi(API_GET_SAVED_FILE_LIST, createUnsupportedAsyncApi(API_GET_SAVED_FILE_LIST));
const API_GET_SAVED_FILE_INFO = "getSavedFileInfo";
const getSavedFileInfo = /* @__PURE__ */ defineAsyncApi(API_GET_SAVED_FILE_INFO, createUnsupportedAsyncApi(API_GET_SAVED_FILE_INFO));
const API_REMOVE_SAVED_FILE_INFO = "removeSavedFileInfo";
const removeSavedFileInfo = /* @__PURE__ */ defineAsyncApi(API_REMOVE_SAVED_FILE_INFO, createUnsupportedAsyncApi(API_REMOVE_SAVED_FILE_INFO));
const API_REMOVE_SAVED_FILE = "removeSavedFile";
const removeSavedFile = /* @__PURE__ */ defineAsyncApi(API_REMOVE_SAVED_FILE, createUnsupportedAsyncApi(API_REMOVE_SAVED_FILE));
const API_ON_MEMORY_WARNING = "onMemoryWarning";
const onMemoryWarning = /* @__PURE__ */ defineOnApi(API_ON_MEMORY_WARNING, createUnsupportedOnApi(API_ON_MEMORY_WARNING));
const API_ON_GYROSCOPE_CHANGE = "onGyroscopeChange";
......@@ -20749,7 +20749,7 @@ var api = /* @__PURE__ */ Object.defineProperty({
saveFile,
getSavedFileList,
getSavedFileInfo,
removeSavedFileInfo,
removeSavedFile,
onMemoryWarning,
onGyroscopeChange,
startGyroscope,
......@@ -22908,4 +22908,4 @@ var index = /* @__PURE__ */ defineSystemComponent({
return openBlock(), createBlock("div", clazz, [loadingVNode]);
}
});
export { $emit, $off, $on, $once, index$8 as Ad, index$7 as AdContentPage, index$6 as AdDraw, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$z as Button, index$5 as Camera, index$x as Canvas, index$v as Checkbox, index$w as CheckboxGroup, index$a as CoverImage, index$b as CoverView, index$u as Editor, index$B as Form, index$t as Icon, index$s as Image, Input, index$A as Label, LayoutComponent, index$4 as LivePlayer, index$3 as LivePusher, Map$1 as Map, MovableArea, MovableView, index$r as Navigator, index$2 as PageComponent, index$9 as Picker, PickerView, PickerViewColumn, index$q as Progress, index$o as Radio, index$p as RadioGroup, ResizeSensor, index$n as RichText, ScrollView, index$m as Slider, Swiper, SwiperItem, index$l as Switch, index$k as Text, index$j as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$f as Video, index$i as View, index$e as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closePreviewImage, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getAppBaseInfo, getClipboardData, getCurrentPages$1 as getCurrentPages, getDeviceInfo, getEnterOptionsSync, getFileInfo, getImageInfo, getLaunchOptionsSync, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getPushClientId, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, getWindowInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, interceptors, invokePushCallback, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offAppHide, offAppShow, offCompassChange, offError, offLocationChange, offLocationChangeError, offNetworkStatusChange, offPageNotFound, offPushMessage, offUnhandledRejection, offWindowResize, onAccelerometerChange, onAppHide, onAppShow, onCompassChange, onError, onGyroscopeChange, onLocaleChange, onLocationChange, onLocationChangeError, onMemoryWarning, onNetworkStatusChange, onPageNotFound, onPushMessage, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUnhandledRejection, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$g as plugin, preloadPage, previewImage, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setClipboardData, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setPageMeta, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startLocationUpdate, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopLocationUpdate, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useI18n, useTabBar, vibrateLong, vibrateShort };
export { $emit, $off, $on, $once, index$8 as Ad, index$7 as AdContentPage, index$6 as AdDraw, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$z as Button, index$5 as Camera, index$x as Canvas, index$v as Checkbox, index$w as CheckboxGroup, index$a as CoverImage, index$b as CoverView, index$u as Editor, index$B as Form, index$t as Icon, index$s as Image, Input, index$A as Label, LayoutComponent, index$4 as LivePlayer, index$3 as LivePusher, Map$1 as Map, MovableArea, MovableView, index$r as Navigator, index$2 as PageComponent, index$9 as Picker, PickerView, PickerViewColumn, index$q as Progress, index$o as Radio, index$p as RadioGroup, ResizeSensor, index$n as RichText, ScrollView, index$m as Slider, Swiper, SwiperItem, index$l as Switch, index$k as Text, index$j as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$f as Video, index$i as View, index$e as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closePreviewImage, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getAppBaseInfo, getClipboardData, getCurrentPages$1 as getCurrentPages, getDeviceInfo, getEnterOptionsSync, getFileInfo, getImageInfo, getLaunchOptionsSync, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getPushClientId, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, getWindowInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, interceptors, invokePushCallback, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offAppHide, offAppShow, offCompassChange, offError, offLocationChange, offLocationChangeError, offNetworkStatusChange, offPageNotFound, offPushMessage, offUnhandledRejection, offWindowResize, onAccelerometerChange, onAppHide, onAppShow, onCompassChange, onError, onGyroscopeChange, onLocaleChange, onLocationChange, onLocationChangeError, onMemoryWarning, onNetworkStatusChange, onPageNotFound, onPushMessage, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUnhandledRejection, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$g as plugin, preloadPage, previewImage, reLaunch, redirectTo, removeInterceptor, removeSavedFile, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setClipboardData, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setPageMeta, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startLocationUpdate, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopLocationUpdate, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useI18n, useTabBar, vibrateLong, vibrateShort };
......@@ -13,20 +13,19 @@ import {
let listener: ((event: DeviceMotionEvent) => void) | null = null
export const onAccelerometerChange = <API_TYPE_ON_ACCELEROMETER_CHANGE>(
defineOnApi(API_ON_ACCELEROMETER, () => {
export const onAccelerometerChange =
defineOnApi<API_TYPE_ON_ACCELEROMETER_CHANGE>(API_ON_ACCELEROMETER, () => {
startAccelerometer()
})
)
export const offAccelerometerChange = <API_TYPE_OFF_ACCELEROMETER_CHANGE>(
defineOnApi(API_OFF_ACCELEROMETER, () => {
export const offAccelerometerChange =
defineOnApi<API_TYPE_OFF_ACCELEROMETER_CHANGE>(API_OFF_ACCELEROMETER, () => {
stopAccelerometer()
})
)
export const startAccelerometer = <API_TYPE_START_ACCELEROMETER>(
defineAsyncApi(API_START_ACCELEROMETER, (_, { resolve, reject }) => {
export const startAccelerometer = defineAsyncApi<API_TYPE_START_ACCELEROMETER>(
API_START_ACCELEROMETER,
(_, { resolve, reject }) => {
if (!window.DeviceMotionEvent) {
reject()
return
......@@ -63,15 +62,16 @@ export const startAccelerometer = <API_TYPE_START_ACCELEROMETER>(
addEventListener()
}
resolve()
})
}
)
export const stopAccelerometer = <API_TYPE_STOP_ACCELEROMETER>(
defineAsyncApi(API_STOP_ACCELEROMETER, (_, { resolve }) => {
export const stopAccelerometer = defineAsyncApi<API_TYPE_STOP_ACCELEROMETER>(
API_STOP_ACCELEROMETER,
(_, { resolve }) => {
if (listener) {
window.removeEventListener('devicemotion', listener, false)
listener = null
}
resolve()
})
}
)
......@@ -14,20 +14,23 @@ import {
let listener: ((event: DeviceOrientationEvent) => void) | null = null
export const onCompassChange = <API_TYPE_ON_COMPASS_CHANGE>(
defineOnApi(API_ON_COMPASS, () => {
export const onCompassChange = defineOnApi<API_TYPE_ON_COMPASS_CHANGE>(
API_ON_COMPASS,
() => {
startCompass()
})
}
)
export const offCompassChange = <API_TYPE_OFF_COMPASS_CHANGE>(
defineOffApi(API_OFF_COMPASS, () => {
export const offCompassChange = defineOffApi<API_TYPE_OFF_COMPASS_CHANGE>(
API_OFF_COMPASS,
() => {
stopCompass()
})
}
)
export const startCompass = <API_TYPE_START_COMPASS>(
defineAsyncApi(API_START_COMPASS, (_, { resolve, reject }) => {
export const startCompass = defineAsyncApi<API_TYPE_START_COMPASS>(
API_START_COMPASS,
(_, { resolve, reject }) => {
if (!window.DeviceOrientationEvent) {
reject()
return
......@@ -62,15 +65,16 @@ export const startCompass = <API_TYPE_START_COMPASS>(
addEventListener()
}
resolve()
})
}
)
export const stopCompass = <API_TYPE_STOP_COMPASS>(
defineAsyncApi(API_STOP_COMPASS, (_, { resolve }) => {
export const stopCompass = defineAsyncApi<API_TYPE_STOP_COMPASS>(
API_STOP_COMPASS,
(_, { resolve }) => {
if (listener) {
window.removeEventListener('deviceorientation', listener, false)
listener = null
}
resolve()
})
}
)
......@@ -10,7 +10,7 @@ import LoctaionPicker, { Props, Poi } from './LoctaionPicker'
let state: Props | null = null
export const chooseLocation = <API_TYPE_CHOOSE_LOCATION>defineAsyncApi(
export const chooseLocation = defineAsyncApi<API_TYPE_CHOOSE_LOCATION>(
API_CHOOSE_LOCATION,
(args, { resolve, reject }) => {
if (!state) {
......
......@@ -14,7 +14,7 @@ import {
import { getJSONP } from '../../../helpers/getJSONP'
import { request } from '../network/request'
export const getLocation = <API_TYPE_GET_LOCATION>defineAsyncApi(
export const getLocation = defineAsyncApi<API_TYPE_GET_LOCATION>(
API_GET_LOCATION,
(
{ type, altitude, highAccuracyExpireTime, isHighAccuracy },
......
......@@ -24,8 +24,8 @@ let watchId: number = 0
/**
* 开始更新定位
*/
export const startLocationUpdate = <API_TYPE_START_LOCATION_UPDATE>(
defineAsyncApi(
export const startLocationUpdate =
defineAsyncApi<API_TYPE_START_LOCATION_UPDATE>(
API_START_LOCATION_UPDATE,
(_, { resolve, reject }) => {
if (navigator.geolocation && watchId === 0) {
......@@ -53,14 +53,15 @@ export const startLocationUpdate = <API_TYPE_START_LOCATION_UPDATE>(
StartLocationUpdateProtocol,
StartLocationUpdateOptions
)
)
export const onLocationChange = <API_TYPE_ON_LOCATION_CHANGE>(
defineOnApi(API_ON_LOCATION_CHANGE, () => {})
export const onLocationChange = defineOnApi<API_TYPE_ON_LOCATION_CHANGE>(
API_ON_LOCATION_CHANGE,
() => {}
)
export const stopLocationUpdate = <API_TYPE_STOP_LOCATION_UPDATE>(
defineAsyncApi(API_STOP_LOCATION_UPDATE, (_, { resolve, reject }) => {
export const stopLocationUpdate = defineAsyncApi<API_TYPE_STOP_LOCATION_UPDATE>(
API_STOP_LOCATION_UPDATE,
(_, { resolve, reject }) => {
if (watchId) {
navigator.geolocation.clearWatch(watchId)
watchId = 0
......@@ -68,19 +69,24 @@ export const stopLocationUpdate = <API_TYPE_STOP_LOCATION_UPDATE>(
} else {
reject('stopLocationUpdate:fail')
}
})
}
)
export const offLocationChange = <API_TYPE_OFF_LOCATION_CHANGE>(
defineOffApi(API_OFF_LOCATION_CHANGE, () => {
export const offLocationChange = defineOffApi<API_TYPE_OFF_LOCATION_CHANGE>(
API_OFF_LOCATION_CHANGE,
() => {
stopLocationUpdate()
})
}
)
export const onLocationChangeError = <API_TYPE_ON_LOCATION_CHANGE_ERROR>(
defineOnApi(API_ON_LOCATION_CHANGE_ERROR, () => {})
)
export const onLocationChangeError =
defineOnApi<API_TYPE_ON_LOCATION_CHANGE_ERROR>(
API_ON_LOCATION_CHANGE_ERROR,
() => {}
)
export const offLocationChangeError = <API_TYPE_OFF_LOCATION_CHANGE_ERROR>(
defineOnApi(API_OFF_LOCATION_CHANGE_ERROR, () => {})
)
export const offLocationChangeError =
defineOnApi<API_TYPE_OFF_LOCATION_CHANGE_ERROR>(
API_OFF_LOCATION_CHANGE_ERROR,
() => {}
)
......@@ -12,7 +12,7 @@ import LocationView, { Props } from './LocationView'
let state: Props | null = null
export const openLocation = <API_TYPE_OPEN_LOCATION>defineAsyncApi(
export const openLocation = defineAsyncApi<API_TYPE_OPEN_LOCATION>(
API_OPEN_LOCATION,
(args, { resolve }) => {
if (!state) {
......
......@@ -8,7 +8,7 @@ import {
import { urlToFile } from '../../../helpers/file'
export const getVideoInfo = <API_TYPE_GET_VIDEO_INFO>defineAsyncApi(
export const getVideoInfo = defineAsyncApi<API_TYPE_GET_VIDEO_INFO>(
API_GET_VIDEO_INFO,
({ src }, { resolve, reject }) => {
urlToFile(src, true)
......
......@@ -23,7 +23,7 @@ const closePreviewImageView = () => {
})
}
export const previewImage = <API_TYPE_PREVIEW_IMAGE>defineAsyncApi(
export const previewImage = defineAsyncApi<API_TYPE_PREVIEW_IMAGE>(
API_PREVIEW_IMAGE,
(args, { resolve }) => {
if (!state) {
......
......@@ -214,7 +214,7 @@ export const sendSocketMessage = defineAsyncApi<API_TYPE_SEND_SOCKET_MESSAGE>(
SendSocketMessageProtocol
)
export const closeSocket = <API_TYPE_CLOSE_SOCKET>defineAsyncApi(
export const closeSocket = defineAsyncApi<API_TYPE_CLOSE_SOCKET>(
API_CLOSE_SOCKET,
(options, { resolve, reject }) => {
const socketTask = socketTasks[0]
......
......@@ -51,7 +51,7 @@ function parseValue(value: any) {
} catch (error) {}
}
export const setStorageSync = <API_TYPE_SET_STORAGE_SYNC>defineSyncApi(
export const setStorageSync = defineSyncApi<API_TYPE_SET_STORAGE_SYNC>(
API_SET_STORAGE_SYNC,
(key, data) => {
const type = typeof data
......@@ -67,7 +67,7 @@ export const setStorageSync = <API_TYPE_SET_STORAGE_SYNC>defineSyncApi(
SetStorageSyncProtocol
)
export const setStorage = <API_TYPE_SET_STORAGE>defineAsyncApi(
export const setStorage = defineAsyncApi<API_TYPE_SET_STORAGE>(
API_SET_STORAGE,
({ key, data }, { resolve, reject }) => {
try {
......@@ -96,9 +96,9 @@ function getStorageOrigin(key: string): any {
return data
}
export const getStorageSync = <API_TYPE_GET_STORAGE_SYNC>defineSyncApi(
export const getStorageSync = defineSyncApi<API_TYPE_GET_STORAGE_SYNC>(
API_GET_STORAGE_SYNC,
(key: string, t: boolean) => {
(key: string) => {
try {
return getStorageOrigin(key)
} catch (error) {
......@@ -108,7 +108,7 @@ export const getStorageSync = <API_TYPE_GET_STORAGE_SYNC>defineSyncApi(
GetStorageSyncProtocol
)
export const getStorage = <API_TYPE_GET_STORAGE>defineAsyncApi(
export const getStorage = defineAsyncApi<API_TYPE_GET_STORAGE>(
API_GET_STORAGE,
({ key }, { resolve, reject }) => {
try {
......@@ -123,7 +123,7 @@ export const getStorage = <API_TYPE_GET_STORAGE>defineAsyncApi(
GetStorageProtocol
)
export const removeStorageSync = <API_TYPE_REMOVE_STORAGE_SYNC>defineSyncApi(
export const removeStorageSync = defineSyncApi<API_TYPE_REMOVE_STORAGE_SYNC>(
API_REMOVE_STORAGE,
(key) => {
if (localStorage) {
......@@ -133,7 +133,7 @@ export const removeStorageSync = <API_TYPE_REMOVE_STORAGE_SYNC>defineSyncApi(
RemoveStorageSyncProtocol
)
export const removeStorage = <API_TYPE_REMOVE_STORAGE>defineAsyncApi(
export const removeStorage = defineAsyncApi<API_TYPE_REMOVE_STORAGE>(
API_REMOVE_STORAGE,
({ key }, { resolve }) => {
removeStorageSync(key)
......@@ -142,23 +142,26 @@ export const removeStorage = <API_TYPE_REMOVE_STORAGE>defineAsyncApi(
RemoveStorageProtocol
)
export const clearStorageSync = <typeof uni.clearStorageSync>(
defineSyncApi('clearStorageSync', () => {
export const clearStorageSync = defineSyncApi<typeof uni.clearStorageSync>(
'clearStorageSync',
() => {
if (localStorage) {
localStorage.clear()
}
})
}
)
export const clearStorage = <typeof uni.clearStorage>(
defineAsyncApi('clearStorage', (_, { resolve }) => {
export const clearStorage = defineAsyncApi<typeof uni.clearStorage>(
'clearStorage',
(_, { resolve }) => {
clearStorageSync()
resolve()
})
}
)
export const getStorageInfoSync = <typeof uni.getStorageInfoSync>(
defineSyncApi('getStorageInfoSync', () => {
export const getStorageInfoSync = defineSyncApi<typeof uni.getStorageInfoSync>(
'getStorageInfoSync',
() => {
const length = (localStorage && localStorage.length) || 0
const keys = []
let currentSize = 0
......@@ -175,11 +178,12 @@ export const getStorageInfoSync = <typeof uni.getStorageInfoSync>(
currentSize: Math.ceil((currentSize * 2) / 1024),
limitSize: Number.MAX_VALUE,
}
})
}
)
export const getStorageInfo = <typeof uni.getStorageInfo>(
defineAsyncApi('getStorageInfo', (_, { resolve }) => {
export const getStorageInfo = defineAsyncApi<typeof uni.getStorageInfo>(
'getStorageInfo',
(_, { resolve }) => {
resolve(getStorageInfoSync())
})
}
)
......@@ -59,10 +59,10 @@ export const getSavedFileInfo = defineAsyncApi<typeof uni.getSavedFileInfo>(
API_GET_SAVED_FILE_INFO,
createUnsupportedAsyncApi(API_GET_SAVED_FILE_INFO)
)
const API_REMOVE_SAVED_FILE_INFO = 'removeSavedFileInfo'
export const removeSavedFileInfo = defineAsyncApi(
API_REMOVE_SAVED_FILE_INFO,
createUnsupportedAsyncApi(API_REMOVE_SAVED_FILE_INFO)
const API_REMOVE_SAVED_FILE = 'removeSavedFile'
export const removeSavedFile = defineAsyncApi<typeof uni.removeSavedFile>(
API_REMOVE_SAVED_FILE,
createUnsupportedAsyncApi(API_REMOVE_SAVED_FILE)
)
const API_ON_MEMORY_WARNING = 'onMemoryWarning'
......
......@@ -3,8 +3,9 @@ import { nextTick } from 'vue'
import { defineAsyncApi, defineSyncApi } from '@dcloudio/uni-api'
import { getLayoutState } from '../../../framework/components/layout'
export const showTopWindow = <typeof uni.showTopWindow>(
defineAsyncApi('showTopWindow', (_, { resolve, reject }) => {
export const showTopWindow = defineAsyncApi<typeof uni.showTopWindow>(
'showTopWindow',
(_, { resolve, reject }) => {
const state = getLayoutState()
if (!state) {
reject()
......@@ -12,11 +13,12 @@ export const showTopWindow = <typeof uni.showTopWindow>(
}
state.apiShowTopWindow = true
nextTick(resolve)
})
}
)
export const hideTopWindow = <typeof uni.hideTopWindow>(
defineAsyncApi('hideTopWindow', (_, { resolve, reject }) => {
export const hideTopWindow = defineAsyncApi<typeof uni.hideTopWindow>(
'hideTopWindow',
(_, { resolve, reject }) => {
const state = getLayoutState()
if (!state) {
reject()
......@@ -24,11 +26,12 @@ export const hideTopWindow = <typeof uni.hideTopWindow>(
}
state.apiShowTopWindow = false
nextTick(resolve)
})
}
)
export const showLeftWindow = <typeof uni.showLeftWindow>(
defineAsyncApi('showLeftWindow', (_, { resolve, reject }) => {
export const showLeftWindow = defineAsyncApi<typeof uni.showLeftWindow>(
'showLeftWindow',
(_, { resolve, reject }) => {
const state = getLayoutState()
if (!state) {
reject()
......@@ -36,11 +39,12 @@ export const showLeftWindow = <typeof uni.showLeftWindow>(
}
state.apiShowLeftWindow = true
nextTick(resolve)
})
}
)
export const hideLeftWindow = <typeof uni.hideLeftWindow>(
defineAsyncApi('hideLeftWindow', (_, { resolve, reject }) => {
export const hideLeftWindow = defineAsyncApi<typeof uni.hideLeftWindow>(
'hideLeftWindow',
(_, { resolve, reject }) => {
const state = getLayoutState()
if (!state) {
reject()
......@@ -48,11 +52,12 @@ export const hideLeftWindow = <typeof uni.hideLeftWindow>(
}
state.apiShowLeftWindow = false
nextTick(resolve)
})
}
)
export const showRightWindow = <typeof uni.showRightWindow>(
defineAsyncApi('showRightWindow', (_, { resolve, reject }) => {
export const showRightWindow = defineAsyncApi<typeof uni.showRightWindow>(
'showRightWindow',
(_, { resolve, reject }) => {
const state = getLayoutState()
if (!state) {
reject()
......@@ -60,11 +65,12 @@ export const showRightWindow = <typeof uni.showRightWindow>(
}
state.apiShowRightWindow = true
nextTick(resolve)
})
}
)
export const hideRightWindow = <typeof uni.hideRightWindow>(
defineAsyncApi('hideRightWindow', (_, { resolve, reject }) => {
export const hideRightWindow = defineAsyncApi<typeof uni.hideRightWindow>(
'hideRightWindow',
(_, { resolve, reject }) => {
const state = getLayoutState()
if (!state) {
reject()
......@@ -72,53 +78,57 @@ export const hideRightWindow = <typeof uni.hideRightWindow>(
}
state.apiShowRightWindow = false
nextTick(resolve)
})
}
)
export const getTopWindowStyle = <typeof uni.getTopWindowStyle>(
defineSyncApi('getTopWindowStyle', () => {
export const getTopWindowStyle = defineSyncApi<typeof uni.getTopWindowStyle>(
'getTopWindowStyle',
() => {
const state = getLayoutState()
return extend({}, state && state.topWindowStyle)
})
}
)
export const setTopWindowStyle = <typeof uni.setTopWindowStyle>(
defineSyncApi('setTopWindowStyle', (style) => {
export const setTopWindowStyle = defineSyncApi<typeof uni.setTopWindowStyle>(
'setTopWindowStyle',
(style) => {
const state = getLayoutState()
if (state) {
state.topWindowStyle = style
}
})
}
)
export const getLeftWindowStyle = <typeof uni.getLeftWindowStyle>(
defineSyncApi('getLeftWindowStyle', () => {
export const getLeftWindowStyle = defineSyncApi<typeof uni.getLeftWindowStyle>(
'getLeftWindowStyle',
() => {
const state = getLayoutState()
return extend({}, state && state.leftWindowStyle)
})
}
)
export const setLeftWindowStyle = <typeof uni.setLeftWindowStyle>(
defineSyncApi('setLeftWindowStyle', (style) => {
export const setLeftWindowStyle = defineSyncApi<typeof uni.setLeftWindowStyle>(
'setLeftWindowStyle',
(style) => {
const state = getLayoutState()
if (state) {
state.leftWindowStyle = style
}
})
}
)
export const getRightWindowStyle = <typeof uni.getRightWindowStyle>(
defineSyncApi('getRightWindowStyle', () => {
const state = getLayoutState()
return extend({}, state && state.rightWindowStyle)
})
)
export const getRightWindowStyle = defineSyncApi<
typeof uni.getRightWindowStyle
>('getRightWindowStyle', () => {
const state = getLayoutState()
return extend({}, state && state.rightWindowStyle)
})
export const setRightWindowStyle = <typeof uni.setRightWindowStyle>(
defineSyncApi('setRightWindowStyle', (style) => {
const state = getLayoutState()
if (state) {
state.rightWindowStyle = style
}
})
)
export const setRightWindowStyle = defineSyncApi<
typeof uni.setRightWindowStyle
>('setRightWindowStyle', (style) => {
const state = getLayoutState()
if (state) {
state.rightWindowStyle = style
}
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册