From f34dc72f6919c995686c2d9d58a995d6c36ccf2c Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Thu, 15 Apr 2021 18:14:34 +0800 Subject: [PATCH] chore: getSystemInfoSync --- packages/uni-api/src/helpers/api/callback.ts | 5 ++++- packages/uni-api/src/helpers/api/index.ts | 3 ++- packages/uni-api/src/helpers/protocol.ts | 4 ++-- packages/uni-api/src/index.ts | 1 + packages/uni-api/src/protocols/ui/tabBar.ts | 3 +-- .../uni-h5/src/service/api/base/getBaseSystemInfo.ts | 2 ++ .../uni-h5/src/service/api/device/getSystemInfoSync.ts | 5 +++++ packages/uni-shared/src/utils.ts | 9 +++++++++ 8 files changed, 26 insertions(+), 6 deletions(-) diff --git a/packages/uni-api/src/helpers/api/callback.ts b/packages/uni-api/src/helpers/api/callback.ts index abdef8dcb..66bcfd434 100644 --- a/packages/uni-api/src/helpers/api/callback.ts +++ b/packages/uni-api/src/helpers/api/callback.ts @@ -81,7 +81,10 @@ export const API_SUCCESS = 'success' export const API_FAIL = 'fail' export const API_COMPLETE = 'complete' -type CALLBACK_TYPES = typeof API_SUCCESS | typeof API_FAIL | typeof API_COMPLETE +export type CALLBACK_TYPES = + | typeof API_SUCCESS + | typeof API_FAIL + | typeof API_COMPLETE type ApiCallbacks = { [key in CALLBACK_TYPES]?: Function diff --git a/packages/uni-api/src/helpers/api/index.ts b/packages/uni-api/src/helpers/api/index.ts index 4f65cc486..14ea1407d 100644 --- a/packages/uni-api/src/helpers/api/index.ts +++ b/packages/uni-api/src/helpers/api/index.ts @@ -15,6 +15,7 @@ import { createKeepAliveApiCallback, removeKeepAliveApiCallback, } from './callback' +import type { CALLBACK_TYPES } from './callback' import { promisify } from './promise' function formatApiArgs( @@ -219,7 +220,7 @@ export function defineSyncApi( export function defineAsyncApi>( name: string, fn: ( - args: Omit, + args: Omit, res: { resolve: (res?: AsyncApiRes

) => void reject: (err?: string) => void diff --git a/packages/uni-api/src/helpers/protocol.ts b/packages/uni-api/src/helpers/protocol.ts index fbed29944..9b858be23 100644 --- a/packages/uni-api/src/helpers/protocol.ts +++ b/packages/uni-api/src/helpers/protocol.ts @@ -23,8 +23,8 @@ export const HTTP_METHODS = [ 'CONNECT', ] -export function elemInArray(str: string, arr: string[]) { - if (arr.indexOf(str) === -1) { +export function elemInArray(str: T, arr: T[]) { + if (!str || arr.indexOf(str) === -1) { return arr[0] } return str diff --git a/packages/uni-api/src/index.ts b/packages/uni-api/src/index.ts index 5e3ba6ede..1c77e0772 100644 --- a/packages/uni-api/src/index.ts +++ b/packages/uni-api/src/index.ts @@ -23,6 +23,7 @@ export * from './protocols/location/openLocation' export * from './protocols/media/chooseImage' export * from './protocols/media/chooseVideo' +export * from './protocols/media/chooseFile' export * from './protocols/media/getImageInfo' export * from './protocols/network/request' diff --git a/packages/uni-api/src/protocols/ui/tabBar.ts b/packages/uni-api/src/protocols/ui/tabBar.ts index 219b5a667..b848edb10 100644 --- a/packages/uni-api/src/protocols/ui/tabBar.ts +++ b/packages/uni-api/src/protocols/ui/tabBar.ts @@ -1,8 +1,7 @@ import { extend } from '@vue/shared' -import { getLen } from '@dcloudio/uni-shared' +import { getLen, removeLeadingSlash } from '@dcloudio/uni-shared' import { getRealPath } from '@dcloudio/uni-platform' import { getCurrentPageMeta } from '@dcloudio/uni-core' -import { removeLeadingSlash } from '@dcloudio/uni-shared' const IndexProtocol: ApiProtocol = { index: { diff --git a/packages/uni-h5/src/service/api/base/getBaseSystemInfo.ts b/packages/uni-h5/src/service/api/base/getBaseSystemInfo.ts index c08bffe6e..0b3080af4 100644 --- a/packages/uni-h5/src/service/api/base/getBaseSystemInfo.ts +++ b/packages/uni-h5/src/service/api/base/getBaseSystemInfo.ts @@ -10,6 +10,8 @@ export const isMac = /Macintosh|Mac/i.test(ua) export const isLinux = /Linux|X11/i.test(ua) +export const isIPadOS = isMac && navigator.maxTouchPoints > 0 + export function getScreenFix() { return ( /^Apple/.test(navigator.vendor) && typeof window.orientation === 'number' diff --git a/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts b/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts index 116ccc3ba..c8665069d 100644 --- a/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts +++ b/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts @@ -11,6 +11,7 @@ import { isWindows, isMac, isLinux, + isIPadOS, isLandscape, getScreenFix, getScreenWidth, @@ -88,6 +89,10 @@ export const getSystemInfoSync = defineSyncApi( break } } + } else if (isIPadOS) { + model = 'iPad' + osname = 'iOS' + osversion = typeof window.BigInt === 'function' ? '14.0' : '13.0' } else if (isWindows || isMac || isLinux) { model = 'PC' osname = 'PC' diff --git a/packages/uni-shared/src/utils.ts b/packages/uni-shared/src/utils.ts index a0131bf19..5cb574bfd 100644 --- a/packages/uni-shared/src/utils.ts +++ b/packages/uni-shared/src/utils.ts @@ -13,3 +13,12 @@ export const invokeArrayFns = (fns: Function[], arg?: any) => { } return ret } + +export function updateElementStyle( + element: HTMLElement, + styles: Partial +) { + for (const attrName in styles) { + element.style[attrName] = styles[attrName]! + } +} -- GitLab