diff --git a/packages/api-proxy/src/common/js/promisify.js b/packages/api-proxy/src/common/js/promisify.js index 3eb20590b4..3f19af391a 100644 --- a/packages/api-proxy/src/common/js/promisify.js +++ b/packages/api-proxy/src/common/js/promisify.js @@ -70,14 +70,22 @@ function promisify (listObj, whiteList, customBlackList) { result[key] = function (...args) { const obj = args[0] || {} // 不需要转换 or 用户已定义回调,则不处理 - if (!promisifyFilter(key) || obj.success || obj.fail) { + if (!promisifyFilter(key)) { return listObj[key].apply(ENV_OBJ, args) } else { // 其他情况进行转换 if (!args[0]) args.unshift(obj) let returned const promise = new Promise((resolve, reject) => { - obj.success = resolve - obj.fail = reject + const originSuccess = obj.success + const originFail = obj.fail + obj.success = function (res) { + originSuccess && originSuccess.call(this, res) + resolve(res) + } + obj.fail = function (e) { + originFail && originFail.call(this, e) + reject(e) + } returned = listObj[key].apply(ENV_OBJ, args) }) promise.__returned = returned diff --git a/packages/api-proxy/src/platform/api/create-intersection-observer/rnIntersectionObserver.js b/packages/api-proxy/src/platform/api/create-intersection-observer/rnIntersectionObserver.js index 1f4a2d523b..059ae453b0 100644 --- a/packages/api-proxy/src/platform/api/create-intersection-observer/rnIntersectionObserver.js +++ b/packages/api-proxy/src/platform/api/create-intersection-observer/rnIntersectionObserver.js @@ -85,7 +85,7 @@ class RNIntersectionObserver { _getWindowRect () { if (this.windowRect) return this.windowRect - const navigation = getFocusedNavigation() + const navigation = getFocusedNavigation() || {} const screen = Dimensions.get('screen') const navigationLayout = navigation.layout || { x: 0, diff --git a/packages/api-proxy/src/platform/api/request/index.web.js b/packages/api-proxy/src/platform/api/request/index.web.js index d16e3a420d..b3c04364c3 100644 --- a/packages/api-proxy/src/platform/api/request/index.web.js +++ b/packages/api-proxy/src/platform/api/request/index.web.js @@ -107,10 +107,9 @@ function request (options = { url: '' }) { errMsg: `request:fail ${err}`, statusCode: response.status, header: response.headers, - data: response.data, - stack: realError.stack, - ...realError + data: response.data } + Object.assign(res, realError) failHandle(res, fail, complete) }) diff --git a/packages/api-proxy/src/platform/api/set-navigation-bar/index.ios.js b/packages/api-proxy/src/platform/api/set-navigation-bar/index.ios.js index 3f83c65f34..1171cd7b68 100644 --- a/packages/api-proxy/src/platform/api/set-navigation-bar/index.ios.js +++ b/packages/api-proxy/src/platform/api/set-navigation-bar/index.ios.js @@ -7,7 +7,7 @@ function setNavigationBarTitle (options = {}) { failHandle({ errMsg: 'setNavigationBarTitle:fail' }, fail, complete) } else { nextTick(() => { - navigation.setOptions({ headerTitle: title }) + navigation.setOptions({ title }) successHandle({ errMsg: 'setNavigationBarTitle:ok' }, success, complete) }) } diff --git a/packages/api-proxy/src/platform/api/system/index.ios.js b/packages/api-proxy/src/platform/api/system/index.ios.js index b108997da8..6633441b55 100644 --- a/packages/api-proxy/src/platform/api/system/index.ios.js +++ b/packages/api-proxy/src/platform/api/system/index.ios.js @@ -1 +1,84 @@ -export * from './rnSystem' +import DeviceInfo from 'react-native-device-info' +import { PixelRatio } from 'react-native' +import { successHandle, failHandle, defineUnsupportedProps } from '../../../common/js' +import { getWindowInfo, getLaunchOptionsSync, getEnterOptionsSync } from './rnSystem' + +const getSystemInfoSync = function () { + const windowInfo = getWindowInfo() + const { screenWidth, screenHeight } = windowInfo + + const result = { + brand: DeviceInfo.getBrand(), + model: DeviceInfo.getModel(), + system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`, + platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(), + deviceOrientation: screenWidth > screenHeight ? 'portrait' : 'landscape', + fontSizeSetting: PixelRatio.getFontScale() + } + Object.assign(result, windowInfo) + defineUnsupportedProps(result, [ + 'language', + 'version', + 'SDKVersion', + 'benchmarkLevel', + 'albumAuthorized', + 'cameraAuthorized', + 'locationAuthorized', + 'microphoneAuthorized', + 'notificationAuthorized', + 'phoneCalendarAuthorized', + 'host', + 'enableDebug', + 'notificationAlertAuthorized', + 'notificationBadgeAuthorized', + 'notificationSoundAuthorized', + 'bluetoothEnabled', + 'locationEnabled', + 'wifiEnabled', + 'locationReducedAccuracy', + 'theme' + ]) + return result +} + +const getSystemInfo = function (options = {}) { + const { success, fail, complete } = options + try { + const systemInfo = getSystemInfoSync() + Object.assign(systemInfo, { + errMsg: 'setStorage:ok' + }) + successHandle(systemInfo, success, complete) + } catch (err) { + const result = { + errMsg: `getSystemInfo:fail ${err}` + } + failHandle(result, fail, complete) + } +} + +const getDeviceInfo = function () { + const deviceInfo = {} + if (__mpx_mode__ === 'android') { + const deviceAbi = DeviceInfo.supported64BitAbisSync() || [] + deviceInfo.deviceAbi = deviceAbi[0] || null + } + defineUnsupportedProps(deviceInfo, ['benchmarkLevel', 'abi', 'cpuType']) + Object.assign(deviceInfo, { + brand: DeviceInfo.getBrand(), + model: DeviceInfo.getModel(), + system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`, + platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(), + memorySize: DeviceInfo.getTotalMemorySync() / (1024 * 1024) + }) + return deviceInfo +} + +export { + getSystemInfo, + getSystemInfoSync, + getDeviceInfo, + getWindowInfo, + getLaunchOptionsSync, + getEnterOptionsSync +} diff --git a/packages/api-proxy/src/platform/api/system/rnSystem.js b/packages/api-proxy/src/platform/api/system/rnSystem.js index 23ec485f9c..2284971c9b 100644 --- a/packages/api-proxy/src/platform/api/system/rnSystem.js +++ b/packages/api-proxy/src/platform/api/system/rnSystem.js @@ -1,77 +1,43 @@ -import DeviceInfo from 'react-native-device-info' -import { PixelRatio } from 'react-native' -import { successHandle, failHandle, defineUnsupportedProps } from '../../../common/js' -import { getWindowInfo } from './rnWindowInfo' +import { PixelRatio, Dimensions } from 'react-native' +import { initialWindowMetrics } from 'react-native-safe-area-context' +import { getFocusedNavigation } from '../../../common/js' -const getSystemInfoSync = function () { - const windowInfo = getWindowInfo() - const { screenWidth, screenHeight } = windowInfo - - const result = { - brand: DeviceInfo.getBrand(), - model: DeviceInfo.getModel(), - system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`, - platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(), - deviceOrientation: screenWidth > screenHeight ? 'portrait' : 'landscape', - fontSizeSetting: PixelRatio.getFontScale() - } - Object.assign(result, windowInfo) - defineUnsupportedProps(result, [ - 'language', - 'version', - 'SDKVersion', - 'benchmarkLevel', - 'albumAuthorized', - 'cameraAuthorized', - 'locationAuthorized', - 'microphoneAuthorized', - 'notificationAuthorized', - 'phoneCalendarAuthorized', - 'host', - 'enableDebug', - 'notificationAlertAuthorized', - 'notificationBadgeAuthorized', - 'notificationSoundAuthorized', - 'bluetoothEnabled', - 'locationEnabled', - 'wifiEnabled', - 'locationReducedAccuracy', - 'theme' - ]) - return result -} - -const getSystemInfo = function (options = {}) { - const { success, fail, complete } = options +const getWindowInfo = function () { + const dimensionsScreen = Dimensions.get('screen') + const navigation = getFocusedNavigation() || {} + const initialWindowMetricsInset = initialWindowMetrics?.insets || {} + const navigationInsets = navigation.insets || {} + const insets = Object.assign(initialWindowMetricsInset, navigationInsets) + let safeArea = {} + const { top = 0, bottom = 0, left = 0, right = 0 } = insets + const screenHeight = dimensionsScreen.height + const screenWidth = dimensionsScreen.width + const layout = navigation.layout || {} + const layoutHeight = layout.height || 0 + const layoutWidth = layout.width || 0 + const windowHeight = layoutHeight || screenHeight try { - const systemInfo = getSystemInfoSync() - Object.assign(systemInfo, { - errMsg: 'setStorage:ok' - }) - successHandle(systemInfo, success, complete) - } catch (err) { - const result = { - errMsg: `getSystemInfo:fail ${err}` + safeArea = { + left, + right: screenWidth - right, + top, + bottom: screenHeight - bottom, + height: screenHeight - top - bottom, + width: screenWidth - left - right } - failHandle(result, fail, complete) + } catch (error) { } -} - -const getDeviceInfo = function () { - const deviceInfo = {} - if (__mpx_mode__ === 'android') { - const deviceAbi = DeviceInfo.supported64BitAbisSync() || [] - deviceInfo.deviceAbi = deviceAbi[0] || null + const result = { + pixelRatio: PixelRatio.get(), + windowWidth: layoutWidth || screenWidth, + windowHeight, // 取不到layout的时候有个兜底 + screenWidth: screenWidth, + screenHeight: screenHeight, + screenTop: screenHeight - windowHeight, + statusBarHeight: safeArea.top, + safeArea } - defineUnsupportedProps(deviceInfo, ['benchmarkLevel', 'abi', 'cpuType']) - Object.assign(deviceInfo, { - brand: DeviceInfo.getBrand(), - model: DeviceInfo.getModel(), - system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`, - platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(), - memorySize: DeviceInfo.getTotalMemorySync() / (1024 * 1024) - }) - return deviceInfo + return result } const getLaunchOptionsSync = function () { @@ -90,9 +56,6 @@ const getEnterOptionsSync = function () { } export { - getSystemInfo, - getSystemInfoSync, - getDeviceInfo, getWindowInfo, getLaunchOptionsSync, getEnterOptionsSync diff --git a/packages/api-proxy/src/platform/api/system/rnWindowInfo.js b/packages/api-proxy/src/platform/api/system/rnWindowInfo.js deleted file mode 100644 index 13e8c771b5..0000000000 --- a/packages/api-proxy/src/platform/api/system/rnWindowInfo.js +++ /dev/null @@ -1,42 +0,0 @@ -import { PixelRatio, Dimensions } from 'react-native' -import { initialWindowMetrics } from 'react-native-safe-area-context' -import { getFocusedNavigation } from '../../../common/js' - -const getWindowInfo = function () { - const dimensionsScreen = Dimensions.get('screen') - const navigation = getFocusedNavigation() - const insets = Object.assign(initialWindowMetrics?.insets, navigation?.insets) - let safeArea = {} - const { top = 0, bottom = 0, left = 0, right = 0 } = insets - const screenHeight = dimensionsScreen.height - const screenWidth = dimensionsScreen.width - const layout = navigation?.layout || {} - const layoutHeight = layout.height || 0 - const layoutWidth = layout.width || 0 - const windowHeight = layoutHeight || screenHeight - try { - safeArea = { - left, - right: screenWidth - right, - top, - bottom: screenHeight - bottom, - height: screenHeight - top - bottom, - width: screenWidth - left - right - } - } catch (error) { - } - const result = { - pixelRatio: PixelRatio.get(), - windowWidth: layoutWidth || screenWidth, - windowHeight, // 取不到layout的时候有个兜底 - screenWidth: screenWidth, - screenHeight: screenHeight, - screenTop: screenHeight - windowHeight, - safeArea - } - return result -} - -export { - getWindowInfo -} diff --git a/packages/api-proxy/src/platform/api/toast/rnToast.jsx b/packages/api-proxy/src/platform/api/toast/rnToast.jsx index 0fd46a89f2..e780ffb556 100644 --- a/packages/api-proxy/src/platform/api/toast/rnToast.jsx +++ b/packages/api-proxy/src/platform/api/toast/rnToast.jsx @@ -1,24 +1,27 @@ -import { View, Text, Image, StyleSheet, ActivityIndicator } from 'react-native' +import { View, Text, Image, StyleSheet, ActivityIndicator, Dimensions } from 'react-native' import { successHandle, failHandle } from '../../../common/js' import { Portal } from '@ant-design/react-native' let toastKey let isLoadingShow +const dimensionsScreen = Dimensions.get('screen') +const screenHeight = dimensionsScreen.height +const contentTop = parseInt(screenHeight * 0.35) let tId // show duration 计时id const styles = StyleSheet.create({ toastContent: { - minWdth: 150, maxWidth: '60%', backgroundColor: 'rgba(20, 20, 20, 0.7)', paddingTop: 15, paddingBottom: 15, - paddingLeft: 20, - paddingRight: 20, + paddingLeft: 10, + paddingRight: 10, borderRadius: 5, display: 'flex', flexDirection: 'column', justifyContent: 'center', - alignItems: 'center' + alignItems: 'center', + marginTop: contentTop // 小程序里面展示偏上一点 }, toastWrap: { left: 0, @@ -28,25 +31,29 @@ const styles = StyleSheet.create({ zIndex: 10000, position: "absolute", display: 'flex', - justifyContent: 'center', alignItems: 'center' }, + toastHasIcon: { + height: 110, + width: 120 + }, toastImg: { width: 40, height: 40, marginLeft: 'auto', - marginRight: 'auto', - marginBottom: 10 + marginRight: 'auto' }, toastText: { textAlign: 'center', color: '#ffffff', - fontSize: 14, + fontSize: 12, lineHeight: 18, height: 18, - overflow: 'hidden' + overflow: 'hidden', + marginTop: 10 } }) + function showToast (options = {}) { const { title, icon = 'success', image, duration = 1500, mask = false, success, fail, complete, isLoading } = options let ToastView @@ -64,29 +71,29 @@ function showToast (options = {}) { tId = null if (image || icon === 'success' || icon === 'error') { ToastView = - + - {title} + { title ? {title} : null } } else if (icon === 'loading') { ToastView = - + - {title} + { title ? {title} : null } } else { ToastView = - {title} + { title ? {title} : null } }