From f9df85a0255665a51298fbf1c12002afc38d3b32 Mon Sep 17 00:00:00 2001 From: yanyilin Date: Fri, 12 Jul 2024 17:44:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81@HBuilderX4?= =?UTF-8?q?.23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utssdk/interface.uts | 4 +- .../utssdk/app-android/index.uts | 2 +- .../utssdk/app-ios/device/DeviceUtil.uts | 9 -- .../utssdk/app-ios/index.uts | 2 +- .../uni-getDeviceInfo/utssdk/interface.uts | 6 +- .../utssdk/app-ios/network/NetworkManager.uts | 141 ++++++++++-------- .../network/download/DownloadController.uts | 2 + .../network/upload/UploadController.uts | 7 + .../uni-payment-wxpay/utssdk/interface.uts | 0 .../uni-tabBar/utssdk/app-android/index.uts | 6 +- uni_modules/uni-tabBar/utssdk/interface.uts | 25 +++- 11 files changed, 127 insertions(+), 77 deletions(-) delete mode 100644 uni_modules/uni-payment-wxpay/utssdk/interface.uts diff --git a/uni_modules/uni-fileSystemManager/utssdk/interface.uts b/uni_modules/uni-fileSystemManager/utssdk/interface.uts index 854943d..49fe5d0 100644 --- a/uni_modules/uni-fileSystemManager/utssdk/interface.uts +++ b/uni_modules/uni-fileSystemManager/utssdk/interface.uts @@ -269,7 +269,7 @@ export type ReadDirOptions = { export type AccessOptions = { /** - * 要删除的目录路径 (本地路径) + * 要判断是否存在的文件/目录路径 (本地路径) */ path : string.URIString, @@ -1104,7 +1104,7 @@ export interface FileSystemManager { access(options : AccessOptions) : void; /** * FileSystemManager.access 的同步版本 - * @param path 要删除的目录路径 (本地路径) + * @param path 要判断是否存在的文件/目录路径 (本地路径) * @uniPlatform { * "app": { * "android": { diff --git a/uni_modules/uni-getDeviceInfo/utssdk/app-android/index.uts b/uni_modules/uni-getDeviceInfo/utssdk/app-android/index.uts index 8a854e0..1c14498 100644 --- a/uni_modules/uni-getDeviceInfo/utssdk/app-android/index.uts +++ b/uni_modules/uni-getDeviceInfo/utssdk/app-android/index.uts @@ -63,7 +63,7 @@ function getBaseInfo(filterArray : Array) : GetDeviceInfoResult { result.deviceId = DeviceUtil.getDeviceID(activity); } if (filterArray.indexOf("devicePixelRatio") != -1) { - result.devicePixelRatio = DeviceUtil.getScaledDensity(activity) + ""; + result.devicePixelRatio = DeviceUtil.getScaledDensity(activity); } if (filterArray.indexOf("system") != -1) { result.system = "Android " + Build.VERSION.RELEASE; diff --git a/uni_modules/uni-getDeviceInfo/utssdk/app-ios/device/DeviceUtil.uts b/uni_modules/uni-getDeviceInfo/utssdk/app-ios/device/DeviceUtil.uts index 8872959..a6dbd65 100644 --- a/uni_modules/uni-getDeviceInfo/utssdk/app-ios/device/DeviceUtil.uts +++ b/uni_modules/uni-getDeviceInfo/utssdk/app-ios/device/DeviceUtil.uts @@ -28,15 +28,6 @@ export class DeviceUtil { return orientation; } - public static getScreenScale(): string { - return UIScreen.main.scale.description; - } - - - public static getIdfa(): string { - return UTSiOS.getGgbs() - } - public static hasRootPrivilege(): boolean { return UTSiOS.isRoot() } diff --git a/uni_modules/uni-getDeviceInfo/utssdk/app-ios/index.uts b/uni_modules/uni-getDeviceInfo/utssdk/app-ios/index.uts index 06e7a9f..36c344f 100644 --- a/uni_modules/uni-getDeviceInfo/utssdk/app-ios/index.uts +++ b/uni_modules/uni-getDeviceInfo/utssdk/app-ios/index.uts @@ -64,7 +64,7 @@ function getBaseInfo(filterArray : Array) : GetDeviceInfoResult { result.deviceOrientation = DeviceUtil.getOrientation(); } if (filterArray.indexOf("devicePixelRatio") != -1) { - result.devicePixelRatio = DeviceUtil.getScreenScale(); + result.devicePixelRatio = Number.from(UIScreen.main.scale); } if (filterArray.indexOf("system") != -1) { result.system = String(format = "iOS %@", osVersion); diff --git a/uni_modules/uni-getDeviceInfo/utssdk/interface.uts b/uni_modules/uni-getDeviceInfo/utssdk/interface.uts index d007bd0..63b82c6 100644 --- a/uni_modules/uni-getDeviceInfo/utssdk/interface.uts +++ b/uni_modules/uni-getDeviceInfo/utssdk/interface.uts @@ -151,7 +151,7 @@ export type GetDeviceInfoOptions = { * } * } */ - deviceType?: string, + deviceType?: 'phone' | 'pad' | 'tv' | 'watch' | 'pc' | 'undefined' | 'car' | 'vr' | 'appliance', /** * 设备方向 竖屏 portrait、横屏 landscape * @@ -199,7 +199,7 @@ export type GetDeviceInfoOptions = { * } * } */ - devicePixelRatio?: string, + devicePixelRatio?: number, /** * 操作系统及版本 * @@ -247,7 +247,7 @@ export type GetDeviceInfoOptions = { * } * } */ - platform?: string, + platform?: 'ios' | 'android' | 'mac' | 'windows' | 'linux', /** * 是否root。iOS 为是否越狱 * diff --git a/uni_modules/uni-network/utssdk/app-ios/network/NetworkManager.uts b/uni_modules/uni-network/utssdk/app-ios/network/NetworkManager.uts index bc08afc..8a892c6 100644 --- a/uni_modules/uni-network/utssdk/app-ios/network/NetworkManager.uts +++ b/uni_modules/uni-network/utssdk/app-ios/network/NetworkManager.uts @@ -1,8 +1,8 @@ import { RequestOptions, RequestTask, UploadTask, UploadFileOptions, OnProgressUpdateResult, UploadFileProgressUpdateCallback, OnProgressDownloadResult, DownloadTask, DownloadFileOptions, DownloadFileProgressUpdateCallback } from '../interface.uts'; import { UTSiOS } from "DCloudUTSFoundation"; -import { URLSessionDataDelegate, URL, CharacterSet, URLSession, URLSessionConfiguration, OperationQueue, URLSessionTask, URLResponse, URLSessionDataTask, URLAuthenticationChallengeSender, URLAuthenticationChallenge, URLCredential, URLSessionTaskMetrics, Data, HTTPURLResponse, NSError, URLRequest, ComparisonResult } from 'Foundation'; +import { URLSessionDataDelegate, URL, CharacterSet, URLSession, URLSessionConfiguration, OperationQueue, URLSessionTask, URLResponse, URLSessionDataTask, URLAuthenticationChallengeSender, URLAuthenticationChallenge, URLCredential, URLSessionTaskMetrics, Data, HTTPURLResponse, NSError, URLRequest, ComparisonResult } from 'Foundation'; import { UploadController } from './upload/UploadController.uts'; -import { DownloadController } from './download/DownloadController.uts'; +import { DownloadController } from './download/DownloadController.uts'; class NetworkRequestListener { public onStart() : void { } @@ -14,21 +14,21 @@ class NetworkRequestListener { public onFinished(response : HTTPURLResponse) : void { } public onFail(error : NSError) : void { } -} - -interface NetworkUploadFileListener { - progressListeners: Array; - onProgress(progressUpdate: OnProgressUpdateResult): void; - onDataReceived(data : Data) : void; - onFinished(response : HTTPURLResponse) : void; - onFail(error : NSError) : void; -} - -interface NetworkDownloadFileListener { +} + +interface NetworkUploadFileListener { + progressListeners : Array; + onProgress(progressUpdate : OnProgressUpdateResult) : void; + onDataReceived(data : Data) : void; + onFinished(response : HTTPURLResponse) : void; + onFail(error : NSError) : void; +} + +interface NetworkDownloadFileListener { options : DownloadFileOptions | null; - progressListeners: Array; - onProgress(progressUpdate: OnProgressDownloadResult): void; - onFinished(response : HTTPURLResponse, filePath: string) : void; + progressListeners : Array; + onProgress(progressUpdate : OnProgressDownloadResult) : void; + onFinished(response : HTTPURLResponse, filePath : string) : void; onFail(error : NSError) : void; } @@ -80,19 +80,19 @@ class NetworkManager implements URLSessionDataDelegate { } let requestTask = new NetworkRequestTaskImpl(task); return requestTask; - } - - public uploadFile(options: UploadFileOptions, listener: NetworkUploadFileListener): UploadTask { - return UploadController.getInstance().uploadFile(options, listener); - } - - public downloadFile(options: DownloadFileOptions, listener: NetworkDownloadFileListener): DownloadTask { - return DownloadController.getInstance().downloadFile(options, listener); + } + + public uploadFile(options : UploadFileOptions, listener : NetworkUploadFileListener) : UploadTask { + return UploadController.getInstance().uploadFile(options, listener); + } + + public downloadFile(options : DownloadFileOptions, listener : NetworkDownloadFileListener) : DownloadTask { + return DownloadController.getInstance().downloadFile(options, listener); } - public createRequest(param : RequestOptions) : URLRequest | null { - const encodeUrl = this.percentEscapedString(param.url) + public createRequest(param : RequestOptions) : URLRequest | null { + const encodeUrl = this.percentEscapedString(param.url) let url = new URL(string = encodeUrl); if (url == null) { return null @@ -121,17 +121,19 @@ class NetworkManager implements URLSessionDataDelegate { let hasContentType = false; if (headers != null) { for (entry in headers!) { - let key = entry.key; + let key = entry.key; let value = entry.value; if (key.caseInsensitiveCompare("Content-Type") == ComparisonResult.orderedSame) { hasContentType = true; } - let valueStr = ""; - if (value instanceof UTSJSONObject) { - valueStr = JSON.stringify(value) ?? "" - }else{ - valueStr = `${value}` - } + let valueStr = ""; + if (value instanceof UTSJSONObject) { + valueStr = JSON.stringify(value) ?? "" + } else if (value instanceof Map) { + valueStr = JSON.stringify(new UTSJSONObject(value)) ?? "" + } else { + valueStr = `${value}` + } request.setValue(valueStr, forHTTPHeaderField = key); } } @@ -140,7 +142,7 @@ class NetworkManager implements URLSessionDataDelegate { if ("GET" != method) { request.setValue("application/json", forHTTPHeaderField = "Content-Type"); } - } + } if ("GET" == method) { const data = param.data; if (data != null) { @@ -149,10 +151,12 @@ class NetworkManager implements URLSessionDataDelegate { json = JSON.parseObject(data as string); } else if (data instanceof UTSJSONObject) { json = data as UTSJSONObject; - } + } else if (data instanceof Map) { + json = new UTSJSONObject(data!) + } if (json != null) { - let urlWithQuery = this.stringifyQuery(encodeUrl, json!) - let url = new URL(string = urlWithQuery); + let urlWithQuery = this.stringifyQuery(encodeUrl, json!) + let url = new URL(string = urlWithQuery); request.url = url; } } @@ -160,6 +164,23 @@ class NetworkManager implements URLSessionDataDelegate { let bodyData : Data | null = null; if (typeof (param.data) == 'string') { bodyData = (param.data as string).data(using = String.Encoding.utf8); + } else if (param.data instanceof Map) { + let body : string | null = ""; + const contentType = request.value(forHTTPHeaderField = "Content-Type") + const data = new UTSJSONObject(param.data!); + if (contentType != null) { + if (contentType!.indexOf("application/x-www-form-urlencoded") == 0) { + const map : Map = data.toMap(); + const bodyArray = new Array(); + map.forEach((value, key) => { + bodyArray.push(key + "=" + `${value ?? "null"}`); + }) + body = bodyArray.join("&"); + } else { + body = JSON.stringify(data); + } + bodyData = body?.data(using = String.Encoding.utf8); + } } else if (param.data instanceof UTSJSONObject) { let body : string | null = ""; const contentType = request.value(forHTTPHeaderField = "Content-Type") @@ -183,8 +204,8 @@ class NetworkManager implements URLSessionDataDelegate { } request.httpBody = bodyData; - } - + } + return request; } @@ -207,42 +228,44 @@ class NetworkManager implements URLSessionDataDelegate { newUrl = str[0] // http:xxx/xxx const pairs = query.split('&') const queryMap = new Map(); - pairs.forEach((item: string, index: number) => { + pairs.forEach((item : string, index : number) => { const temp = item.split('=') if (temp.length > 1) { queryMap[temp[0]] = temp[1] } }); const dataMap : Map = data.toMap(); - dataMap.forEach((value, key) => { - if(value == null){ - value = ""; - } - let encodeKey = encodeURIComponent(key)! - if (value instanceof UTSJSONObject || value instanceof Array){ - queryMap[encodeKey] = encodeURIComponent(JSON.stringify(value)!)! - }else{ - queryMap[encodeKey] = encodeURIComponent(`${value!}`)!; + dataMap.forEach((value, key) => { + if (value == null) { + value = ""; + } + let encodeKey = encodeURIComponent(key)! + if (value instanceof UTSJSONObject || value instanceof Array) { + queryMap[encodeKey] = encodeURIComponent(JSON.stringify(value)!)! + } else if (value instanceof Map) { + queryMap[encodeKey] = encodeURIComponent(JSON.stringify(new UTSJSONObject(value))!)! + } else { + queryMap[encodeKey] = encodeURIComponent(`${value!}`)!; } }) let queryStr = ""; queryMap.forEach((value, key) => { queryStr += key + "=" + value + "&" - }); - + }); + queryStr = queryStr.slice(0, -1); if (queryStr.length > 0) { newUrl += "?" + queryStr; } if (hash.length > 0) { newUrl += "#" + hash; - } + } return newUrl; - } - - private percentEscapedString(str: string): string { - //如果url已经有部分经过encode,那么需要先decode再encode。 - return str.removingPercentEncoding?.addingPercentEncoding(withAllowedCharacters= CharacterSet.urlQueryAllowed) ?? str + } + + private percentEscapedString(str : string) : string { + //如果url已经有部分经过encode,那么需要先decode再encode。 + return str.removingPercentEncoding?.addingPercentEncoding(withAllowedCharacters = CharacterSet.urlQueryAllowed) ?? str } @@ -287,7 +310,7 @@ class NetworkManager implements URLSessionDataDelegate { export { NetworkManager, - NetworkRequestListener, - NetworkUploadFileListener, + NetworkRequestListener, + NetworkUploadFileListener, NetworkDownloadFileListener } \ No newline at end of file diff --git a/uni_modules/uni-network/utssdk/app-ios/network/download/DownloadController.uts b/uni_modules/uni-network/utssdk/app-ios/network/download/DownloadController.uts index adcad30..a93e66f 100644 --- a/uni_modules/uni-network/utssdk/app-ios/network/download/DownloadController.uts +++ b/uni_modules/uni-network/utssdk/app-ios/network/download/DownloadController.uts @@ -91,6 +91,8 @@ export class DownloadController implements URLSessionDownloadDelegate { let valueStr = ""; if (value instanceof UTSJSONObject) { valueStr = JSON.stringify(value) ?? "" + }else if(value instanceof Map){ + valueStr = JSON.stringify(new UTSJSONObject(value)) ?? "" }else{ valueStr = `${value}` } diff --git a/uni_modules/uni-network/utssdk/app-ios/network/upload/UploadController.uts b/uni_modules/uni-network/utssdk/app-ios/network/upload/UploadController.uts index ca9429a..a4a548e 100644 --- a/uni_modules/uni-network/utssdk/app-ios/network/upload/UploadController.uts +++ b/uni_modules/uni-network/utssdk/app-ios/network/upload/UploadController.uts @@ -97,6 +97,8 @@ class UploadController implements URLSessionDataDelegate { let valueStr = ""; if (value instanceof UTSJSONObject) { valueStr = JSON.stringify(value) ?? "" + }else if(value instanceof Map){ + valueStr = JSON.stringify(new UTSJSONObject(value)) ?? "" }else{ valueStr = `${value}` } @@ -119,6 +121,11 @@ class UploadController implements URLSessionDataDelegate { if (valueStr != null) { this.fillTextPart(body, boundary, key, valueStr as string) } + }else if(value instanceof Map){ + let valueStr = JSON.stringify(new UTSJSONObject(value)) + if (valueStr != null) { + this.fillTextPart(body, boundary, key, valueStr as string) + } }else{ this.fillTextPart(body, boundary, key, `${value}`) } diff --git a/uni_modules/uni-payment-wxpay/utssdk/interface.uts b/uni_modules/uni-payment-wxpay/utssdk/interface.uts deleted file mode 100644 index e69de29..0000000 diff --git a/uni_modules/uni-tabBar/utssdk/app-android/index.uts b/uni_modules/uni-tabBar/utssdk/app-android/index.uts index ca6420b..9ae114f 100644 --- a/uni_modules/uni-tabBar/utssdk/app-android/index.uts +++ b/uni_modules/uni-tabBar/utssdk/app-android/index.uts @@ -107,7 +107,11 @@ export const setTabBarStyle = defineAsyncApi< ['backgroundImage', options.backgroundImage], ['backgroundRepeat', options.backgroundRepeat], ]) - if (isString(options.borderStyle)) { + if (isString(options.borderColor)) { + style.set( + 'borderStyle', options.borderColor as string, + ) + } else if (isString(options.borderStyle)) { style.set( 'borderStyle', getTabBarBorderStyle(options.borderStyle as string), diff --git a/uni_modules/uni-tabBar/utssdk/interface.uts b/uni_modules/uni-tabBar/utssdk/interface.uts index c784f44..1e432db 100644 --- a/uni_modules/uni-tabBar/utssdk/interface.uts +++ b/uni_modules/uni-tabBar/utssdk/interface.uts @@ -235,10 +235,33 @@ export type SetTabBarStyleOptions = { * - no-repeat: 背景图片在垂直方向和水平方向都拉伸 */ backgroundRepeat?: 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat' + /** + * tabbar上边框的颜色(优先级高于 borderStyle) + * @tutorial https://doc.dcloud.net.cn/uni-app-x/api/set-tabbar.html#settabbarstyle + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "5.0", + * "uniVer": "x", + * "unixVer": "x" + * }, + * "ios": { + * "osVer": "12.0", + * "uniVer": "x", + * "unixVer": "4.23" + * } + * }, + * "web": { + * "uniVer": "x", + * "unixVer": "4.23" + * } + * } + */ + borderColor?: string | string.ColorString /** * tabbar上边框的颜色 */ - borderStyle?: string + borderStyle?: 'black' | 'white' /** * tabbar 中间按钮 仅在 list 项为偶数时有效 * @internal -- GitLab