提交 911735e0 编写于 作者: DCloud-yyl's avatar DCloud-yyl

同步代码@HBuilderX4.29

上级 328b51ff
{
"id": "uni-addPhoneContact",
"displayName": "uni-addPhoneContact",
"version": "1.0.0",
"description": "uni-addPhoneContact",
"keywords": [
"uni-addPhoneContact"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"uni-ext-api": {
"uni": {
"addPhoneContact": {
"name": "addPhoneContact",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
}
}
},
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
# uni-addPhoneContact
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts/-/tree/dev)
import { AddPhoneContact, AddPhoneContactOptions, AddPhoneContactSuccess } from '../interface.uts';
import { API_ADD_PHONE_CONTACT, AddPhoneContactApiOptions, AddPhoneContactApiProtocol } from '../protocol.uts';
import { contact } from '@kit.ContactsKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { UTSHarmony } from '@dcloudio/uni-runtime';
export const addPhoneContact: AddPhoneContact = defineAsyncApi<AddPhoneContactOptions, AddPhoneContactSuccess>(
API_ADD_PHONE_CONTACT,
(args: AddPhoneContactOptions, executor: ApiExecutor<AddPhoneContactSuccess>) => {
UTSHarmony.requestSystemPermission(['ohos.permission.WRITE_CONTACTS'], (allRight: boolean) => {
if (allRight) {
const {
photoFilePath,
nickName = '',
lastName = '',
middleName = '',
firstName = '',
remark = '',
mobilePhoneNumber = '',
weChatNumber,
addressCountry = '',
addressState = '',
addressCity = '',
addressStreet = '',
addressPostalCode = '',
organization = '',
url = '',
workPhoneNumber = '',
workFaxNumber = '',
hostNumber = '',
email = '',
title = '',
workAddressCountry = '',
workAddressState = '',
workAddressCity = '',
workAddressStreet = '',
workAddressPostalCode,
homeFaxNumber = '',
homePhoneNumber = '',
homeAddressCountry = '',
homeAddressState = '',
homeAddressCity = '',
homeAddressStreet = '',
homeAddressPostalCode = ''
} = args
const contactInfo: contact.Contact = {
name: {
familyName: lastName!,
middleName: middleName!,
givenName: firstName!,
fullName: lastName! + middleName! + firstName!
},
nickName: {
nickName: nickName!
},
emails: [{
email: email!,
displayName: '邮箱'
}],
phoneNumbers: [{
phoneNumber: homePhoneNumber!,
labelId: contact.PhoneNumber.NUM_HOME
}, {
phoneNumber: mobilePhoneNumber!,
labelId: contact.PhoneNumber.NUM_MOBILE
}, {
phoneNumber: homeFaxNumber!,
labelId: contact.PhoneNumber.NUM_FAX_HOME
}, {
phoneNumber: workFaxNumber!,
labelId: contact.PhoneNumber.NUM_FAX_WORK
}, {
phoneNumber: workPhoneNumber!,
labelId: contact.PhoneNumber.NUM_WORK
}, {
phoneNumber: hostNumber!,
labelId: contact.PhoneNumber.NUM_COMPANY_MAIN
}],
portrait: { uri: photoFilePath! },
postalAddresses: [{
city: homeAddressCity!,
country: homeAddressCountry!,
postcode: homeAddressPostalCode!,
street: homeAddressStreet!,
postalAddress: homeAddressCountry! + homeAddressState! + homeAddressCity + homeAddressStreet,
labelId: contact.PostalAddress.ADDR_HOME
}, {
city: workAddressCity!,
country: workAddressCountry!,
postcode: workAddressPostalCode!,
street: workAddressStreet!,
postalAddress: workAddressCountry! + workAddressState! + workAddressCity + workAddressStreet,
labelId: contact.PostalAddress.ADDR_WORK
}, {
city: addressCity!,
country: addressCountry!,
postcode: addressPostalCode!,
street: addressStreet!,
postalAddress: addressCountry! + addressState! + addressCity + addressStreet,
labelId: contact.PostalAddress.CUSTOM_LABEL
}],
websites: [{ website: url! }],
note: { noteContent: remark! },
organization: {
name: organization!,
title: title!
}
}
contact.addContact(getContext(), contactInfo)
.then((contactId) => {
executor.resolve(contactId)
})
.catch((err: BusinessError) => {
executor.reject(err.message)
})
} else {
executor.reject('Permission denied')
}
}, () => executor.reject('Permission denied'))
},
AddPhoneContactApiProtocol,
AddPhoneContactApiOptions
) as AddPhoneContact
export interface Uni {
/**
* 手机通讯录联系人和联系方式的增加
* @tutorial https://uniapp.dcloud.net.cn/api/system/contact.html
* @tutorial-uni-app https://uniapp.dcloud.net.cn/api/system/contact.html
*
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.25",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* "mp":{
* weixin: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* alipay: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* baidu: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* toutiao: {
* hostVer: 'x',
* uniVer: 'x',
* unixVer: 'x'
* },
* lark: {
* hostVer: 'x',
* uniVer: 'x',
* unixVer: 'x'
* },
* qq: {
* hostVer: 'x',
* uniVer: 'x',
* unixVer: 'x'
* },
* kuaishou: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* jd: {
* hostVer: 'x',
* uniVer: 'x',
* unixVer: 'x'
* }
* }
* }
*/
addPhoneContact: AddPhoneContact;
}
export type AddPhoneContact = (options: AddPhoneContactOptions) => void;
export type AddPhoneContactSuccess = {};
export type UniError = {
errSubject: string,
errCode: number,
errMsg: string,
data?: object | null,
cause?: any | null
};
export type AddPhoneContactSuccessCallback = (result: AddPhoneContactSuccess) => void;
export type AddPhoneContactFail = UniError;
export type AddPhoneContactFailCallback = (result: AddPhoneContactFail) => void;
export type AddPhoneContactComplete = any;
export type AddPhoneContactCompleteCallback = (result: AddPhoneContactComplete) => void;
export type AddPhoneContactOptions = {
/**
* 头像本地文件路径
*/
photoFilePath?: string | null,
/**
* 昵称
*/
nickName?: string | null,
/**
* 姓氏
*/
lastName?: string | null,
/**
* 中间名
*/
middleName?: string | null,
/**
* 名字
*/
firstName?: string | null,
/**
* 备注
*/
remark?: string | null,
/**
* 手机号
*/
mobilePhoneNumber?: string | null,
/**
* 微信号
*/
weChatNumber?: string | null,
/**
* 联系地址国家
*/
addressCountry?: string | null,
/**
* 联系地址省份
*/
addressState?: string | null,
/**
* 联系地址城市
*/
addressCity?: string | null,
/**
* 联系地址街道
*/
addressStreet?: string | null,
/**
* 联系地址邮政编码
*/
addressPostalCode?: string | null,
/**
* 公司
*/
organization?: string | null,
/**
* 职位
*/
title?: string | null,
/**
* 工作传真
*/
workFaxNumber?: string | null,
/**
* 工作电话
*/
workPhoneNumber?: string | null,
/**
* 公司电话
*/
hostNumber?: string | null,
/**
* 电子邮件
*/
email?: string | null,
/**
* 网站
*/
url?: string | null,
/**
* 工作地址国家
*/
workAddressCountry?: string | null,
/**
* 工作地址省份
*/
workAddressState?: string | null,
/**
* 工作地址城市
*/
workAddressCity?: string | null,
/**
* 工作地址街道
*/
workAddressStreet?: string | null,
/**
* 工作地址邮政编码
*/
workAddressPostalCode?: string | null,
/**
* 住宅传真
*/
homeFaxNumber?: string | null,
/**
* 住宅电话
*/
homePhoneNumber?: string | null,
/**
* 住宅地址国家
*/
homeAddressCountry?: string | null,
/**
* 住宅地址省份
*/
homeAddressState?: string | null,
/**
* 住宅地址城市
*/
homeAddressCity?: string | null,
/**
* 住宅地址街道
*/
homeAddressStreet?: string | null,
/**
* 住宅地址邮政编码
*/
homeAddressPostalCode?: string | null,
/**
* 接口调用成功的回调函数
*/
success?: AddPhoneContactSuccessCallback | null,
/**
* 接口调用失败的回调函数
*/
fail?: AddPhoneContactFailCallback | null,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
complete?: AddPhoneContactCompleteCallback | null
};
import { AddPhoneContactOptions } from './interface.uts';
export const API_ADD_PHONE_CONTACT = 'addPhoneContact'
export const AddPhoneContactApiOptions: ApiOptions<AddPhoneContactOptions> = {
formatArgs: new Map<string, ((firstName: string) => string | undefined)>([
['firstName', function (firstName: string) {
if (!firstName) {
return 'addPhoneContact:fail parameter error: parameter.firstName should not be empty;'
}
return undefined
}]
])
}
export const AddPhoneContactApiProtocol = new Map<string, ProtocolOptions>([
['firstName', { type: 'string', required: true }],
['photoFilePath', { type: 'string' }],
['nickName', { type: 'string' }],
['lastName', { type: 'string' }],
['middleName', { type: 'string' }],
['remark', { type: 'string' }],
['mobilePhoneNumber', { type: 'string' }],
['weChatNumber', { type: 'string' }],
['addressCountry', { type: 'string' }],
['addressState', { type: 'string' }],
['addressCity', { type: 'string' }],
['addressStreet', { type: 'string' }],
['addressPostalCode', { type: 'string' }],
['organization', { type: 'string' }],
['title', { type: 'string' }],
['workFaxNumber', { type: 'string' }],
['workPhoneNumber', { type: 'string' }],
['hostNumber', { type: 'string' }],
['email', { type: 'string' }],
['url', { type: 'string' }],
['workAddressCountry', { type: 'string' }],
['workAddressState', { type: 'string' }],
['workAddressCity', { type: 'string' }],
['workAddressStreet', { type: 'string' }],
['workAddressPostalCode', { type: 'string' }],
['homeFaxNumber', { type: 'string' }],
['homePhoneNumber', { type: 'string' }],
['homeAddressCountry', { type: 'string' }],
['homeAddressState', { type: 'string' }],
['homeAddressCity', { type: 'string' }],
['homeAddressStreet', { type: 'string' }],
['homeAddressPostalCode', { type: 'string' }]
]
);
{
"id": "uni-arrayBufferToBase64",
"displayName": "uni-arrayBufferToBase64",
"version": "1.0.0",
"description": "uni-arrayBufferToBase64",
"keywords": [
"uni-arrayBufferToBase64"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"uni-ext-api": {
"uni": {
"arrayBufferToBase64": {
"name": "arrayBufferToBase64",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
}
}
},
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
# uni-arrayBufferToBase64
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts/-/tree/dev)
import buffer from '@ohos.buffer';
import { ArrayBufferToBase64 } from '../interface.uts';
import { ArrayBufferToBase64Protocol, API_ARRAY_BUFFER_TO_BASE64 } from '../protocol.uts';
export const arrayBufferToBase64: ArrayBufferToBase64 = defineSyncApi<string>(
API_ARRAY_BUFFER_TO_BASE64,
(arrayBuffer: ArrayBuffer): string => {
return buffer.from(arrayBuffer).toString('base64')
},
ArrayBufferToBase64Protocol
) as ArrayBufferToBase64
export interface Uni {
/**
* 将 ArrayBuffer 对象转成 Base64 字符串
*
* @tutorial https://uniapp.dcloud.net.cn/api/arrayBufferToBase64.html
* @tutorial-uni-app https://uniapp.dcloud.net.cn/api/arrayBufferToBase64.html
*
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.23",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* },
* "mp":{
* weixin: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* alipay: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* baidu: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* toutiao: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* lark: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* qq: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* kuaishou: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* jd: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* }
* }
* }
*/
arrayBufferToBase64: ArrayBufferToBase64;
}
export type ArrayBufferToBase64 = (arrayBuffer: ArrayBuffer) => string;
export const API_ARRAY_BUFFER_TO_BASE64 = 'arrayBufferToBase64'
export const ArrayBufferToBase64Protocol = new Map<string, ProtocolOptions>([
[
'arrayBuffer',
{
type: 'arrayBuffer',
required: true,
}
]
])
{
"id": "uni-authentication",
"displayName": "uni-authentication",
"version": "1.0.0",
"description": "uni-authentication",
"keywords": [
"uni-authentication"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"uni-ext-api": {
"uni": {
"startSoterAuthentication": {
"name": "startSoterAuthentication",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
},
"checkIsSupportSoterAuthentication": {
"name": "checkIsSupportSoterAuthentication",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
},
"checkIsSoterEnrolledInDevice": {
"name": "checkIsSoterEnrolledInDevice",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
}
}
},
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
# uni-authentication
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts/-/tree/dev)
import { UTSHarmony } from '@dcloudio/uni-runtime';
import { BusinessError } from '@kit.BasicServicesKit';
import { userAuth } from '@kit.UserAuthenticationKit';
import { promptAction } from '@kit.ArkUI';
import {
StartSoterAuthentication, StartSoterAuthenticationOptions, StartSoterAuthenticationSuccess, SoterAuthMode,
CheckIsSupportSoterAuthentication, CheckIsSupportSoterAuthenticationOptions, CheckIsSupportSoterAuthenticationSuccess,
CheckIsSoterEnrolledInDevice, CheckIsSoterEnrolledInDeviceOptions, CheckIsSoterEnrolledInDeviceSuccess
} from '../interface.uts';
import {
API_START_SOTER_AUTHENTICATION, StartSoterAuthenticationApiOptions, StartSoterAuthenticationApiProtocols,
API_CHECK_IS_SOTER_ENROLLED_IN_DEVICE, CheckIsSoterEnrolledInDeviceApiOptions, CheckIsSoterEnrolledInDeviceProtocols,
API_CHECK_IS_SUPPORT_SOTER_AUTHENTICATION
} from '../protocol.uts';
function getErrorMessage(code: number): string {
switch (code) {
case 201:
return "权限认证失败";
case 401:
return "参数不正确。可能的一个原因: 强制参数未指定";
case userAuth.UserAuthResultCode.FAIL:
return "认证失败";
case userAuth.UserAuthResultCode.GENERAL_ERROR:
return "操作通用错误";
case userAuth.UserAuthResultCode.CANCELED:
return "操作取消";
case userAuth.UserAuthResultCode.TIMEOUT:
return "操作超时";
case userAuth.UserAuthResultCode.TYPE_NOT_SUPPORT:
return "不支持的认证类型";
case userAuth.UserAuthResultCode.TRUST_LEVEL_NOT_SUPPORT:
return "不支持的认证等级";
case userAuth.UserAuthResultCode.BUSY:
return "忙碌状态";
case userAuth.UserAuthResultCode.LOCKED:
return "认证器已锁定";
case userAuth.UserAuthResultCode.NOT_ENROLLED:
return "用户未录入认证信息";
case userAuth.UserAuthResultCode.CANCELED_FROM_WIDGET:
return "切换到自定义身份验证过程";
case 12500013:
return "系统锁屏密码过期";
default:
return '';
}
}
function getUniErrMsg(code: number): number {
switch (code) {
case 201:
return 90002;
case 401:
return 90004;
case userAuth.UserAuthResultCode.FAIL:
return 90009;
case userAuth.UserAuthResultCode.GENERAL_ERROR:
return 90007;
case userAuth.UserAuthResultCode.CANCELED:
return 90008;
case userAuth.UserAuthResultCode.TIMEOUT:
return 90007;
case userAuth.UserAuthResultCode.TYPE_NOT_SUPPORT:
return 90003;
case userAuth.UserAuthResultCode.TRUST_LEVEL_NOT_SUPPORT:
return 90003;
case userAuth.UserAuthResultCode.BUSY:
return 90010;
case userAuth.UserAuthResultCode.LOCKED:
return 90010;
case userAuth.UserAuthResultCode.NOT_ENROLLED:
return 90011;
case userAuth.UserAuthResultCode.CANCELED_FROM_WIDGET:
return userAuth.UserAuthResultCode.CANCELED_FROM_WIDGET;
case 12500013:
return 12500013;
default:
return -1;
}
}
function toUint8Arr(str: string) {
const buffer: number[] = [];
for (let i of str) {
const _code: number = i.charCodeAt(0);
if (_code < 0x80) {
buffer.push(_code);
} else if (_code < 0x800) {
buffer.push(0xc0 + (_code >> 6));
buffer.push(0x80 + (_code & 0x3f));
} else if (_code < 0x10000) {
buffer.push(0xe0 + (_code >> 12));
buffer.push(0x80 + (_code >> 6 & 0x3f));
buffer.push(0x80 + (_code & 0x3f));
}
}
return Uint8Array.from(buffer);
}
export const startSoterAuthentication: StartSoterAuthentication = defineAsyncApi<StartSoterAuthenticationOptions, StartSoterAuthenticationSuccess>(
API_START_SOTER_AUTHENTICATION,
(args: StartSoterAuthenticationOptions, executor: ApiExecutor<StartSoterAuthenticationSuccess>) => {
const authType: userAuth.UserAuthType[] = []
args.requestAuthModes.forEach((item) => {
if (item === 'fingerPrint') {
authType.push(userAuth.UserAuthType.FINGERPRINT)
} else if (item === 'facial') {
authType.push(userAuth.UserAuthType.FACE)
}
})
// uni的字符串challenge转换成鸿蒙的数组challenge
const challengeArr = toUint8Arr(args.challenge ?? '')
const authContent = args.authContent ?? ''
try {
const auth = userAuth.getUserAuthInstance(
{
challenge: challengeArr,
authType,
authTrustLevel: userAuth.AuthTrustLevel.ATL1
} as userAuth.AuthParam,
{
title: authContent
} as userAuth.WidgetParam
);
auth.on("result", {
onResult: (result: userAuth.UserAuthResult) => {
if (result.result === userAuth.UserAuthResultCode.SUCCESS) {
executor.resolve({
errCode: 0,
authMode: result.authType === userAuth.UserAuthType.FINGERPRINT ? 'fingerPrint' : 'facial'
} as StartSoterAuthenticationSuccess);
} else {
const errMsg = getErrorMessage(result.result)
const errCode = getUniErrMsg(result.result)
executor.reject(errMsg, { errCode } as ApiError);
}
}
} as userAuth.IAuthCallback);
if (authContent) {
promptAction.showToast({
message: authContent
} as promptAction.ShowToastOptions)
}
auth.start();
} catch (error) {
const code = (error as BusinessError).code
executor.reject(getErrorMessage(code), { errCode: getUniErrMsg(code) } as ApiError);
}
},
StartSoterAuthenticationApiProtocols,
StartSoterAuthenticationApiOptions
) as StartSoterAuthentication
function fingerPrintAvailable() {
try {
userAuth.getAvailableStatus(userAuth.UserAuthType.FINGERPRINT, userAuth.AuthTrustLevel.ATL1);
return true
} catch (error) {
return false
}
}
function faceAvailable() {
try {
userAuth.getAvailableStatus(userAuth.UserAuthType.FACE, userAuth.AuthTrustLevel.ATL1);
return true
} catch (error) {
return false
}
}
const PERMISSIONS = ['ohos.permission.ACCESS_BIOMETRIC']
export const checkIsSupportSoterAuthentication: CheckIsSupportSoterAuthentication = defineAsyncApi<CheckIsSupportSoterAuthenticationOptions, CheckIsSupportSoterAuthenticationSuccess>(
API_CHECK_IS_SUPPORT_SOTER_AUTHENTICATION,
(args: CheckIsSupportSoterAuthenticationOptions, executor: ApiExecutor<CheckIsSupportSoterAuthenticationSuccess>) => {
UTSHarmony.requestSystemPermission(PERMISSIONS, (allRight: boolean) => {
if (allRight) {
try {
const supportMode: SoterAuthMode[] = []
if (fingerPrintAvailable()) supportMode.push('fingerPrint')
if (faceAvailable()) supportMode.push('facial')
return executor.resolve({ supportMode, errMsg: '' } as CheckIsSupportSoterAuthenticationSuccess)
} catch (error) {
const code = (error as BusinessError).code
executor.reject(getErrorMessage(code), { errCode: getUniErrMsg(code) } as ApiError);
}
} else {
executor.reject(getErrorMessage(201))
}
}, () => {
executor.reject(getErrorMessage(201))
})
}
) as CheckIsSupportSoterAuthentication
function getFingerPrintEnrolledState() {
userAuth.getEnrolledState(userAuth.UserAuthType.FINGERPRINT);
return true
}
function getFaceEnrolledState() {
userAuth.getEnrolledState(userAuth.UserAuthType.FACE);
return true
}
function harmonyCheckIsSoterEnrolledInDevice(checkAuthMode: SoterAuthMode): boolean {
if (checkAuthMode === 'fingerPrint') {
return getFingerPrintEnrolledState()
} else if (checkAuthMode === 'facial') {
return getFaceEnrolledState()
}
return false
}
export const checkIsSoterEnrolledInDevice: CheckIsSoterEnrolledInDevice = defineAsyncApi<CheckIsSoterEnrolledInDeviceOptions, CheckIsSoterEnrolledInDeviceSuccess>(
API_CHECK_IS_SOTER_ENROLLED_IN_DEVICE,
(args: CheckIsSoterEnrolledInDeviceOptions, executor: ApiExecutor<CheckIsSoterEnrolledInDeviceSuccess>) => {
UTSHarmony.requestSystemPermission(PERMISSIONS, (allRight: boolean) => {
if (allRight) {
try {
const isEnrolled = harmonyCheckIsSoterEnrolledInDevice(args.checkAuthMode)
executor.resolve({
isEnrolled,
errMsg: ''
} as CheckIsSoterEnrolledInDeviceSuccess)
} catch (error) {
const code = (error as BusinessError).code
executor.reject(getErrorMessage(code), { errCode: getUniErrMsg(code) } as ApiError);
}
} else {
executor.reject(getErrorMessage(201))
}
}, () => {
executor.reject(getErrorMessage(201))
})
},
CheckIsSoterEnrolledInDeviceProtocols,
CheckIsSoterEnrolledInDeviceApiOptions
) as CheckIsSoterEnrolledInDevice
export interface Uni {
/**
* 开始 SOTER 生物认证
*
* 文档: [http://uniapp.dcloud.io/api/system/authentication?id=startsoterauthentication](http://uniapp.dcloud.io/api/system/authentication?id=startsoterauthentication)
*/
startSoterAuthentication: StartSoterAuthentication;
/**
* 获取本机支持的 SOTER 生物认证方式
*
* 文档: [http://uniapp.dcloud.io/api/system/authentication?id=checkissupportsoterauthentication](http://uniapp.dcloud.io/api/system/authentication?id=checkissupportsoterauthentication)
*/
checkIsSupportSoterAuthentication: CheckIsSupportSoterAuthentication;
/**
* 获取设备内是否录入如指纹等生物信息
*
* 文档: [http://uniapp.dcloud.io/api/system/authentication?id=checkissoterenrolledindevice](http://uniapp.dcloud.io/api/system/authentication?id=checkissoterenrolledindevice)
*/
checkIsSoterEnrolledInDevice: CheckIsSoterEnrolledInDevice;
}
export type StartSoterAuthentication = (options: StartSoterAuthenticationOptions) => void;
/**
* 生物认证方式
*/
export type SoterAuthMode =
/**
* 指纹识别
*/
'fingerPrint' |
/**
* 人脸识别(暂未支持)
*/
'facial' |
/**
* 声纹识别(暂未支持)
*/
'speech';
export type StartSoterAuthenticationSuccess = {
/**
* 错误码
*/
errCode: number,
/**
* 生物认证方式
* - fingerPrint: 指纹识别
* - facial: 人脸识别(暂未支持)
* - speech: 声纹识别(暂未支持)
*/
authMode: SoterAuthMode,
/**
* 在设备安全区域(TEE)内获得的本机安全信息以及本次认证信息
*/
resultJSON?: string | null,
/**
* 用SOTER安全密钥对 resultJSON 的签名(SHA256 with RSA/PSS, saltlen=20)
*/
resultJSONSignature?: string | null,
/**
* 接口调用结果
*/
errMsg: string
};
export type StartSoterAuthenticationSuccessCallback = (result: StartSoterAuthenticationSuccess) => void;
export type StartSoterAuthenticationFail = UniError;
export type UniError = {
errSubject: string,
errCode: number,
errMsg: string,
data?: object | null,
cause?: any | null
};
export type StartSoterAuthenticationFailCallback = (result: StartSoterAuthenticationFail) => void;
export type StartSoterAuthenticationComplete = any;
export type StartSoterAuthenticationCompleteCallback = (result: StartSoterAuthenticationComplete) => void;
export type StartSoterAuthenticationOptions = {
/**
* 请求使用的可接受的生物认证方式
*/
requestAuthModes: SoterAuthMode[],
/**
* 挑战因子
*/
challenge?: string | null,
/**
* 验证描述,即识别过程中显示在界面上的对话框提示内容
*/
authContent?: string | null,
/**
* 接口调用成功的回调函数
*/
success?: StartSoterAuthenticationSuccessCallback | null,
/**
* 接口调用失败的回调函数
*/
fail?: StartSoterAuthenticationFailCallback | null,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
complete?: StartSoterAuthenticationCompleteCallback | null
};
export type CheckIsSupportSoterAuthentication = (options: CheckIsSupportSoterAuthenticationOptions) => void;
export type CheckIsSupportSoterAuthenticationSuccess = {
/**
* 接口调用成功的回调函数
*/
supportMode: SoterAuthMode[],
/**
* 接口调用结果
*/
errMsg: string
};
export type CheckIsSupportSoterAuthenticationSuccessCallback = (result: CheckIsSupportSoterAuthenticationSuccess) => void;
export type CheckIsSupportSoterAuthenticationFail = UniError;
export type CheckIsSupportSoterAuthenticationFailCallback = (result: CheckIsSupportSoterAuthenticationFail) => void;
export type CheckIsSupportSoterAuthenticationComplete = any;
export type CheckIsSupportSoterAuthenticationCompleteCallback = (result: CheckIsSupportSoterAuthenticationComplete) => void;
export type CheckIsSupportSoterAuthenticationOptions = {
/**
* 接口调用成功的回调函数
*/
success?: CheckIsSupportSoterAuthenticationSuccessCallback | null,
/**
* 接口调用失败的回调函数
*/
fail?: CheckIsSupportSoterAuthenticationFailCallback | null,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
complete?: CheckIsSupportSoterAuthenticationCompleteCallback | null
};
export type CheckIsSoterEnrolledInDevice = (options: CheckIsSoterEnrolledInDeviceOptions) => void;
export type CheckIsSoterEnrolledInDeviceSuccess = {
/**
* 是否已录入信息
* @type boolean
*/
isEnrolled: boolean,
/**
* 错误信息
*/
errMsg: string
};
export type CheckIsSoterEnrolledInDeviceSuccessCallback = (result: CheckIsSoterEnrolledInDeviceSuccess) => void;
export type CheckIsSoterEnrolledInDeviceFail = UniError;
export type CheckIsSoterEnrolledInDeviceFailCallback = (result: CheckIsSoterEnrolledInDeviceFail) => void;
export type CheckIsSoterEnrolledInDeviceComplete = any;
export type CheckIsSoterEnrolledInDeviceCompleteCallback = (result: CheckIsSoterEnrolledInDeviceComplete) => void;
export type CheckIsSoterEnrolledInDeviceOptions = {
/**
* 生物认证方式
* - fingerPrint: 指纹识别
* - facial: 人脸识别(暂未支持)
* - speech: 声纹识别(暂未支持)
*/
checkAuthMode: SoterAuthMode,
/**
* 接口调用成功的回调函数
*/
success?: CheckIsSoterEnrolledInDeviceSuccessCallback | null,
/**
* 接口调用失败的回调函数
*/
fail?: CheckIsSoterEnrolledInDeviceFailCallback | null,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
complete?: CheckIsSoterEnrolledInDeviceCompleteCallback | null
};
import { StartSoterAuthenticationOptions, CheckIsSoterEnrolledInDeviceOptions, SoterAuthMode } from './interface.uts';
export const API_START_SOTER_AUTHENTICATION = 'startSoterAuthentication'
export const StartSoterAuthenticationApiOptions: ApiOptions<StartSoterAuthenticationOptions> = {
formatArgs: new Map<string, ((value: string) => string | undefined)>([
['requestAuthModes', function (value: string) {
if (!value.includes('fingerPrint') && !value.includes('facial')) {
return 'requestAuthModes 填写错误'
}
return undefined
}]
])
}
export const StartSoterAuthenticationApiProtocols = new Map<string, ProtocolOptions>([
[
'requestAuthModes',
{
type: 'array',
required: true
}
],
[
'challenge',
{
type: 'string'
}
],
[
'authContent',
{
type: 'string'
}
]
])
export const API_CHECK_IS_SOTER_ENROLLED_IN_DEVICE = 'checkIsSoterEnrolledInDevice'
export const checkAuthModes: SoterAuthMode[] = ['fingerPrint', 'facial', 'speech']
export const CheckIsSoterEnrolledInDeviceApiOptions: ApiOptions<CheckIsSoterEnrolledInDeviceOptions> = {
formatArgs: new Map<string, ((value: string) => string | undefined)>([
['checkAuthMode', function (value: string) {
if (!checkAuthModes.includes(value as SoterAuthMode)) {
return 'checkAuthMode 填写错误'
}
return undefined
}]
])
}
export const CheckIsSoterEnrolledInDeviceProtocols = new Map<string, ProtocolOptions>([
[
'checkAuthMode',
{
type: 'string'
}
]
])
export const API_CHECK_IS_SUPPORT_SOTER_AUTHENTICATION = 'checkIsSupportSoterAuthentication'
{
"id": "uni-base64ToArrayBuffer",
"displayName": "uni-base64ToArrayBuffer",
"version": "1.0.0",
"description": "uni-base64ToArrayBuffer",
"keywords": [
"uni-base64ToArrayBuffer"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"uni-ext-api": {
"uni": {
"base64ToArrayBuffer": {
"name": "base64ToArrayBuffer",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
}
}
},
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
# uni-base64ToArrayBuffer
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts/-/tree/dev)
import buffer from '@ohos.buffer';
import { Base64ToArrayBuffer } from '../interface.uts';
import { Base64ToArrayBufferProtocol, API_BASE64_TO_ARRAY_BUFFER } from '../protocol.uts';
export const base64ToArrayBuffer: Base64ToArrayBuffer = defineSyncApi<ArrayBuffer>(
API_BASE64_TO_ARRAY_BUFFER,
(base64: string): ArrayBuffer => {
return buffer.from(base64, 'base64').buffer
},
Base64ToArrayBufferProtocol
) as Base64ToArrayBuffer
export interface Uni {
/**
* 将 Base64 字符串转成 ArrayBuffer 对象
*
* @tutorial https://uniapp.dcloud.net.cn/api/base64ToArrayBuffer.html
* @tutorial-uni-app https://uniapp.dcloud.net.cn/api/base64ToArrayBuffer.html
*
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.23",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* },
* "mp":{
* weixin: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* alipay: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* baidu: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* toutiao: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* lark: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* qq: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* kuaishou: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* },
* jd: {
* hostVer: '√',
* uniVer: '√',
* unixVer: 'x'
* }
* }
* }
*/
base64ToArrayBuffer: Base64ToArrayBuffer;
}
export type Base64ToArrayBuffer = (base64: string) => ArrayBuffer;
export const API_BASE64_TO_ARRAY_BUFFER = 'base64ToArrayBuffer'
export const Base64ToArrayBufferProtocol = new Map<string, ProtocolOptions>([
[
'base64',
{
type: 'string',
required: true,
}
]
])
{
"id": "uni-clipboard",
"displayName": "uni-clipboard",
"version": "1.0.0",
"description": "uni-clipboard",
"keywords": [
"uni-clipboard"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"uni-ext-api": {
"uni": {
"getClipboardData": {
"name": "getClipboardData",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
},
"setClipboardData": {
"name": "setClipboardData",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
}
}
},
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
# uni-clipboard
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts/-/tree/dev)
import { clipboard } from '@dcloudio/uni-runtime';
import { SetClipboardData, GetClipboardData, SetClipboardDataOptions, SetClipboardDataSuccess, GetClipboardDataOptions, GetClipboardDataSuccess } from '../interface.uts';
import { API_GET_CLIPBOARD_DATA, API_SET_CLIPBOARD_DATA, SetClipboardDataApiOptions, SetClipboardDataProtocol } from '../protocol.uts';
export { SetClipboardData, GetClipboardData, SetClipboardDataOptions, SetClipboardDataSuccess, GetClipboardDataOptions, GetClipboardDataSuccess }
interface ClipboardModuleGetStringOptions {
result: string
data: string
}
export const getClipboardData: GetClipboardData = defineAsyncApi<GetClipboardDataOptions, GetClipboardDataSuccess>(
API_GET_CLIPBOARD_DATA,
(_: GetClipboardDataOptions, res: ApiExecutor<GetClipboardDataSuccess>) => {
clipboard.getString((ret: ClipboardModuleGetStringOptions) => {
if (ret.result === 'success') {
res.resolve({
data: ret.data,
} as GetClipboardDataSuccess)
} else {
res.reject('getClipboardData:fail')
}
})
}
) as GetClipboardData
export const setClipboardData: SetClipboardData = defineAsyncApi<SetClipboardDataOptions, SetClipboardDataSuccess>(
API_SET_CLIPBOARD_DATA,
(options: SetClipboardDataOptions, res: ApiExecutor<SetClipboardDataSuccess>) => {
clipboard.setString(options.data)
res.resolve()
},
SetClipboardDataProtocol,
SetClipboardDataApiOptions
) as SetClipboardData
export interface Uni {
/**
* 设置系统剪贴板的内容
*
* @tutorial https://uniapp.dcloud.net.cn/api/system/clipboard.html#setclipboarddata
* @tutorial-uni-app https://uniapp.dcloud.net.cn/api/system/clipboard.html#setclipboarddata
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.23",
* "unixVer": "x"
* }
* },
* "mp": {
* "weixin": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "alipay": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "baidu": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "toutiao": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "lark": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "qq": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "kuaishou": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "jd": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
setClipboardData: SetClipboardData;
/**
* 获得系统剪贴板的内容
*
* @tutorial https://uniapp.dcloud.net.cn/api/system/clipboard.html#getclipboarddata
* @tutorial-uni-app https://uniapp.dcloud.net.cn/api/system/clipboard.html#getclipboarddata
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.23",
* "unixVer": "x"
* }
* },
* "mp": {
* "weixin": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "alipay": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "baidu": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "toutiao": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "lark": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "qq": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "kuaishou": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "jd": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
getClipboardData: GetClipboardData;
}
export type SetClipboardData = (options: SetClipboardDataOptions) => void;
export type SetClipboardDataSuccess = {};
export type SetClipboardDataSuccessCallback = (result: SetClipboardDataSuccess) => void;
export type SetClipboardDataFail = UniError;
export type SetClipboardDataFailCallback = (result: SetClipboardDataFail) => void;
export type SetClipboardDataComplete = any;
export type SetClipboardDataCompleteCallback = (result: SetClipboardDataComplete) => void;
export type SetClipboardDataOptions = {
/**
* 需要设置的内容
*/
data: string,
/**
* 是否弹出提示,默认弹出提示
* @type boolean
*/
showToast?: boolean | null,
/**
* 成功返回的回调函数
*/
success?: SetClipboardDataSuccessCallback | null,
/**
* 失败的回调函数
*/
fail?: SetClipboardDataFailCallback | null,
/**
* 结束的回调函数(调用成功、失败都会执行)
*/
complete?: SetClipboardDataCompleteCallback | null
};
export type GetClipboardData = (options: GetClipboardDataOptions) => void;
export type GetClipboardDataSuccess = {
/**
* 剪贴板的内容
*/
data: string
};
export type GetClipboardDataSuccessCallback = (result: GetClipboardDataSuccess) => void;
export type GetClipboardDataFail = UniError;
export type GetClipboardDataFailCallback = (result: GetClipboardDataFail) => void;
export type GetClipboardDataComplete = any;
export type GetClipboardDataCompleteCallback = (result: GetClipboardDataComplete) => void;
export type GetClipboardDataOptions = {
/**
* 成功返回的回调函数
*/
success?: GetClipboardDataSuccessCallback | null,
/**
* 失败的回调函数
*/
fail?: GetClipboardDataFailCallback | null,
/**
* 结束的回调函数(调用成功、失败都会执行)
*/
complete?: GetClipboardDataCompleteCallback | null
};
import { SetClipboardDataOptions } from './interface.uts';
export const API_GET_CLIPBOARD_DATA = 'getClipboardData'
export const API_SET_CLIPBOARD_DATA = 'setClipboardData'
export const SetClipboardDataApiOptions: ApiOptions<SetClipboardDataOptions> = {
formatArgs: new Map<string, boolean>([
['showToast', true]
])
}
export const SetClipboardDataProtocol = new Map<string, ProtocolOptions>([
[
'data',
{
type: 'string',
required: true,
}
],
[
'showToast',
{
type: 'boolean'
}
]
])
{
"id": "uni-createIntersectionObserver",
"displayName": "uni-createIntersectionObserver",
"version": "1.0.0",
"description": "uni-createIntersectionObserver",
"keywords": [
"uni-createIntersectionObserver"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"encrypt": [],
"uni-ext-api": {
"uni": {
"createIntersectionObserver": {
"name": "createIntersectionObserver",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
}
}
},
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
# uni-createIntersectionObserver
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts)
import {
resolveComponentInstance,
extend,
isFunction,
getCurrentPageVm,
getPageIdByVm,
addIntersectionObserver,
removeIntersectionObserver,
} from '@dcloudio/uni-runtime'
import { CreateIntersectionObserver, CreateIntersectionObserverOptions, ObserveCallback, IntersectionObserver } from '../interface.uts'
export { CreateIntersectionObserver, CreateIntersectionObserverOptions, ObserveCallback, IntersectionObserver }
interface AddIntersectionObserverArgs {
reqId: number
component: ComponentPublicInstance
options: ServiceIntersectionObserverOptions
callback: ObserveCallback
}
interface RemoveIntersectionObserverArgs {
reqId: number
component: ComponentPublicInstance
}
interface RequestComponentObserverOptions {
selector?: string
rootMargin?: string
relativeToSelector?: string
}
interface ServiceIntersectionObserverOptions extends CreateIntersectionObserverOptions, RequestComponentObserverOptions { }
interface Margins {
/** 节点布局区域的下边界 */
bottom?: number,
/** 节点布局区域的左边界 */
left?: number,
/** 节点布局区域的右边界 */
right?: number,
/** 节点布局区域的上边界 */
top?: number
}
const defaultOptions = {
thresholds: [0],
initialRatio: 0,
observeAll: false,
} as CreateIntersectionObserverOptions
let reqComponentObserverId = 1
function normalizeRootMargin(margins: Margins | null = {}) {
if (!margins) margins = {}
const top = Number(margins.top) || 0
const right = Number(margins.right) || 0
const bottom = Number(margins.bottom) || 0
const left = Number(margins.left) || 0
return `${top}px ${right}px ${bottom}px ${left}px`
}
class ServiceIntersectionObserver {
private _reqId?: number
private _pageId: number
private _component: ComponentPublicInstance
private _options: ServiceIntersectionObserverOptions
constructor(
component: ComponentPublicInstance,
options?: CreateIntersectionObserverOptions
) {
this._pageId = getPageIdByVm(component)!
this._component = component
if (options) {
if (typeof options.thresholds === 'undefined') options.thresholds = defaultOptions.thresholds
if (typeof options.initialRatio === 'undefined') options.initialRatio = defaultOptions.initialRatio
if (typeof options.observeAll === 'undefined') options.observeAll = defaultOptions.observeAll
}
this._options = (options ?? defaultOptions) as ServiceIntersectionObserverOptions
}
relativeTo(selector: string, margins?: Margins) {
this._options.relativeToSelector = selector
this._options.rootMargin = normalizeRootMargin(margins)
return this
}
relativeToViewport(margins?: Margins) {
this._options.relativeToSelector = undefined
this._options.rootMargin = normalizeRootMargin(margins)
return this
}
observe(
selector: string,
callback: ObserveCallback
) {
if (!isFunction(callback)) {
return
}
this._options.selector = selector
this._reqId = reqComponentObserverId++
addIntersectionObserver(
{
reqId: this._reqId,
component: this._component,
options: this._options,
callback,
} as AddIntersectionObserverArgs,
this._pageId
)
}
disconnect() {
this._reqId &&
removeIntersectionObserver(
{ reqId: this._reqId, component: this._component } as RemoveIntersectionObserverArgs,
this._pageId
)
}
}
export const createIntersectionObserver = defineSyncApi<IntersectionObserver>(
'createIntersectionObserver',
(context: ComponentPublicInstance | null, options?: CreateIntersectionObserverOptions) => {
let _options: ComponentPublicInstance | CreateIntersectionObserverOptions | null = options
context = resolveComponentInstance(context)
if (context && !getPageIdByVm(context)) {
_options = context
context = null
}
if (context) {
return new ServiceIntersectionObserver(context as ComponentPublicInstance, _options as CreateIntersectionObserverOptions)
}
return new ServiceIntersectionObserver(getCurrentPageVm()!, _options as CreateIntersectionObserverOptions)
}
) as CreateIntersectionObserver
export interface Uni {
/**
* 创建并返回一个 IntersectionObserver 对象实例
*
* @tutorial https://uniapp.dcloud.net.cn/api/ui/intersection-observer.html#createintersectionobserver
* @tutorial-uni-app https://uniapp.dcloud.net.cn/api/ui/intersection-observer.html#createintersectionobserver
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.23",
* "unixVer": "x"
* }
* },
* "mp": {
* "weixin": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "alipay": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "baidu": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "toutiao": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "lark": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "qq": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "kuaishou": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "jd": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
createIntersectionObserver: CreateIntersectionObserver;
}
export type CreateIntersectionObserver = (component: any, options: CreateIntersectionObserverOptions) => IntersectionObserver;
export interface CreateIntersectionObserverOptions {
/**
* 所有阈值
*/
thresholds?: (any[]) | null,
/**
* 初始的相交比例
*/
initialRatio?: number | null,
/**
* 是否同时观测多个参照节点(而非一个)
*/
observeAll?: boolean | null
};
export type ObserveNodeRect = {
/**
* left
*/
left: number,
/**
* right
*/
right: number,
/**
* top
*/
top: number,
/**
* bottom
*/
bottom: number
};
export type ObserveResult = {
/**
* 相交比例
*/
intersectionRatio: number,
/**
* 相交区域的边界
*/
intersectionRect: any,
/**
* 目标节点布局区域的边界
*/
boundingClientRect: ObserveNodeRect,
/**
* 参照区域的边界
*/
relativeRect: ObserveNodeRect,
/**
* 相交检测时的时间戳
*/
time: number
};
export type ObserveCallback = (result: ObserveResult) => void;
export interface IntersectionObserver {
/**
* 使用选择器指定一个节点,作为参照区域之一
*/
relativeTo(selector: string, margins?: any): IntersectionObserver;
/**
* 指定页面显示区域作为参照区域之一
*/
relativeToViewport(margins?: any): IntersectionObserver;
/**
* 指定目标节点并开始监听相交状态变化情况
*/
observe(targetSelector: string, callback: ObserveCallback): void;
/**
* 停止监听
*/
disconnect(): void;
}
{
"id": "uni-file",
"displayName": "uni-file",
"version": "1.0.0",
"description": "uni-file",
"keywords": [
"uni-file"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"uni-ext-api": {
"uni": {
"saveFile": {
"name": "saveFile",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
},
"getSavedFileList": {
"name": "getSavedFileList",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
},
"getSavedFileInfo": {
"name": "getSavedFileInfo",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
},
"removeSavedFile": {
"name": "removeSavedFile",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
},
"getFileInfo": {
"name": "getFileInfo",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
}
}
},
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "y",
"vue3": "y"
},
"App": {
"app-android": "y",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
# uni-scanCode
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts)
import {
API_SAVE_FILE,
API_GET_SAVED_FILE_LIST,
API_GET_SAVED_FILE_INFO,
API_REMOVE_SAVED_FILE,
API_GET_FILE_INFO
} from '../protocol.uts'
import {
SaveFile,
SaveFileOptions,
SaveFileSuccess,
SaveFileFail,
GetSavedFileList,
GetSavedFileListOptions,
SavedFileListItem,
GetSavedFileListSuccess,
GetSavedFileListFail,
GetSavedFileInfo,
GetSavedFileInfoOptions,
GetSavedFileInfoSuccess,
GetSavedFileInfoFail,
RemoveSavedFile,
RemoveSavedFileOptions,
RemoveSavedFileSuccess,
RemoveSavedFileFail,
GetFileInfo,
GetFileInfoOptions,
GetFileInfoSuccess,
GetFileInfoFail
} from '../interface.uts'
import {
getEnv,
getRealPath,
} from '@dcloudio/uni-runtime'
import fs from '@ohos.file.fs'
import { ListFileOptions } from '@ohos.file.fs'
import Hash from '@ohos.file.hash';
export {
SaveFile,
SaveFileOptions,
SaveFileSuccess,
SaveFileFail,
GetSavedFileList,
SavedFileListItem,
GetSavedFileListOptions,
GetSavedFileListSuccess,
GetSavedFileListFail,
GetSavedFileInfo,
GetSavedFileInfoOptions,
GetSavedFileInfoSuccess,
GetSavedFileInfoFail,
RemoveSavedFile,
RemoveSavedFileOptions,
RemoveSavedFileSuccess,
RemoveSavedFileFail,
GetFileInfo,
GetFileInfoOptions,
GetFileInfoSuccess,
GetFileInfoFail
}
function getSavedDir(appId: string) {
return getEnv().USER_DATA_PATH + '/' + appId + '/saved'
}
let savedIndex: [string, number] = ['0', 0]
function getSavedFileName(filePath: string) {
const ext = filePath.split('/').pop()?.split('.').slice(1).join('.')
let fileName = Date.now() + ''
if (savedIndex[0] === fileName) {
savedIndex[1]++
if (savedIndex[1] > 0) {
fileName += '-' + savedIndex[1]
}
} else {
savedIndex[0] = fileName
savedIndex[1] = 0
}
if (ext) {
fileName += '.' + ext
}
return fileName
}
function getFsPath(filePath: string) {
filePath = getRealPath(filePath) as string
if (!/^file:/.test(filePath)) {
return filePath
}
const rawPath = filePath.replace(/^file:\/\//, '')
if (rawPath[0] === '/') {
return rawPath
}
return filePath
}
export const saveFile: SaveFile = defineAsyncApi<SaveFileOptions, SaveFileSuccess>(
API_SAVE_FILE,
function (options: SaveFileOptions, exec: ApiExecutor<SaveFileSuccess>) {
const tempFilePath = getRealPath(options.tempFilePath) as string;
const savedPath = getSavedDir(APP_ID)
if (!fs.accessSync(savedPath)) {
fs.mkdirSync(savedPath, true)
}
let srcFile: fs.File
try {
srcFile = fs.openSync(tempFilePath, fs.OpenMode.READ_ONLY)
} catch (error) {
exec.reject((error as Error).message)
return
}
const savedFilePath = savedPath + '/' + getSavedFileName(tempFilePath);
fs.copyFile(srcFile.fd, savedFilePath, (err) => {
fs.closeSync(srcFile)
if (err) {
exec.reject(err.message)
} else {
exec.resolve({
savedFilePath: 'file://' + savedFilePath
} as SaveFileSuccess)
}
})
}
) as SaveFile
export const getSavedFileList: GetSavedFileList = defineAsyncApi<GetSavedFileListOptions, GetSavedFileListSuccess>(
API_GET_SAVED_FILE_LIST,
function (options: GetSavedFileListOptions, exec: ApiExecutor<GetSavedFileListSuccess>) {
const savedPath = getSavedDir(APP_ID)
if (!fs.accessSync(savedPath)) {
exec.resolve({
fileList: []
} as GetSavedFileListSuccess)
}
fs.listFile(savedPath, {} as ListFileOptions, (err, fileList) => {
if (err) {
exec.reject(err.message)
} else {
exec.resolve({
fileList: fileList.map((filePath: string) => {
const fullPath = savedPath + '/' + filePath
const stat = fs.statSync(fullPath)
if (!stat.isFile()) {
return null
}
return {
filePath: 'file://' + fullPath,
size: stat.size,
createTime: stat.ctime
} as SavedFileListItem
}).filter((item) => !!item)
} as GetSavedFileListSuccess)
}
})
}
) as GetSavedFileList
export const getSavedFileInfo: GetSavedFileInfo = defineAsyncApi<GetSavedFileInfoOptions, GetSavedFileInfoSuccess>(
API_GET_SAVED_FILE_INFO,
function (options: GetSavedFileInfoOptions, exec: ApiExecutor<GetSavedFileInfoSuccess>) {
const savedFilePath = getFsPath(options.filePath);
if (!fs.accessSync(savedFilePath)) {
exec.reject('file not exist')
return
}
const stat = fs.statSync(savedFilePath)
if (!stat.isFile()) {
exec.reject('file not exist')
}
exec.resolve({
size: stat.size,
createTime: stat.ctime
} as GetSavedFileInfoSuccess)
}
) as GetSavedFileInfo
export const removeSavedFile: RemoveSavedFile = defineAsyncApi<RemoveSavedFileOptions, RemoveSavedFileSuccess>(
API_REMOVE_SAVED_FILE,
function (options: RemoveSavedFileOptions, exec: ApiExecutor<RemoveSavedFileSuccess>) {
const savedFilePath = getFsPath(options.filePath);
if (!fs.accessSync(savedFilePath)) {
exec.reject('file not exist')
return
}
fs.unlink(savedFilePath, (err) => {
if (err) {
exec.reject(err.message)
} else {
exec.resolve()
}
})
}
) as RemoveSavedFile
const SupportedHashAlgorithm = ['md5', 'sha1']
export const getFileInfo: GetFileInfo = defineAsyncApi<GetFileInfoOptions, GetFileInfoSuccess>(
API_GET_FILE_INFO,
function (options: GetFileInfoOptions, exec: ApiExecutor<GetFileInfoSuccess>) {
const filePath = getFsPath(options.filePath);
const digestAlgorithm = options.digestAlgorithm && SupportedHashAlgorithm.includes(options.digestAlgorithm) ? options.digestAlgorithm : 'md5'
if (!fs.accessSync(filePath)) {
exec.reject('file not exist')
return
}
const stat = fs.statSync(filePath)
if (!stat.isFile()) {
exec.reject('file not exist')
}
Hash.hash(filePath, digestAlgorithm, (err, hash) => {
if (err) {
exec.reject(err.message)
} else {
exec.resolve({
size: stat.size,
digest: hash
} as GetFileInfoSuccess)
}
})
}
) as GetFileInfo
export type SaveFileSuccess = {
savedFilePath: string;
};
export type SaveFileSuccessCallback = (res: SaveFileSuccess) => void;
export type SaveFileFail = {};
export type SaveFileFailCallback = (res: SaveFileFail) => void;
export type SaveFileCompleteCallback = (res: any) => void;
export type SaveFileOptions = {
tempFilePath: string;
success?: SaveFileSuccessCallback | null;
fail?: SaveFileFailCallback | null;
complete?: SaveFileCompleteCallback | null;
};
export type GetFileInfoSuccess = {
digest: string;
size: number;
};
export type GetFileInfoSuccessCallback = (res: GetFileInfoSuccess) => void;
export type GetFileInfoFail = {};
export type GetFileInfoFailCallback = (res: GetFileInfoFail) => void;
export type GetFileInfoCompleteCallback = (res: any) => void;
export type GetFileInfoOptions = {
filePath: string;
digestAlgorithm?: string | null;
success?: GetFileInfoSuccessCallback | null;
fail?: GetFileInfoFailCallback | null;
complete?: GetFileInfoCompleteCallback | null;
};
export type GetSavedFileInfoSuccess = {
size: number;
createTime: number;
};
export type GetSavedFileInfoSuccessCallback = (res: GetSavedFileInfoSuccess) => void;
export type GetSavedFileInfoFail = {};
export type GetSavedFileInfoFailCallback = (res: GetSavedFileInfoFail) => void;
export type GetSavedFileInfoCompleteCallback = (res: any) => void;
export type GetSavedFileInfoOptions = {
filePath: string;
success?: GetSavedFileInfoSuccessCallback | null;
fail?: GetSavedFileInfoFailCallback | null;
complete?: GetSavedFileInfoCompleteCallback | null;
};
export type RemoveSavedFileSuccess = {};
export type RemoveSavedFileSuccessCallback = (res: RemoveSavedFileSuccess) => void;
export type RemoveSavedFileFail = {};
export type RemoveSavedFileFailCallback = (res: RemoveSavedFileFail) => void;
export type RemoveSavedFileCompleteCallback = (res: any) => void;
export type RemoveSavedFileOptions = {
filePath: string;
success?: RemoveSavedFileSuccessCallback | null;
fail?: RemoveSavedFileFailCallback | null;
complete?: RemoveSavedFileCompleteCallback | null;
};
export type SavedFileListItem = {
filePath: string;
size: number;
createTime: number;
};
export type GetSavedFileListSuccess = {
fileList: SavedFileListItem[];
};
export type GetSavedFileListSuccessCallback = (res: GetSavedFileListSuccess) => void;
export type GetSavedFileListFail = {};
export type GetSavedFileListFailCallback = (res: GetSavedFileListFail) => void;
export type GetSavedFileListCompleteCallback = (res: any) => void;
export type GetSavedFileListOptions = {
success?: GetSavedFileListSuccessCallback | null;
fail?: GetSavedFileListFailCallback | null;
complete?: GetSavedFileListCompleteCallback | null;
};
export type SaveFile = (options?: SaveFileOptions | null) => void;
export type GetFileInfo = (options?: GetFileInfoOptions | null) => void;
export type GetSavedFileInfo = (options?: GetSavedFileInfoOptions | null) => void;
export type RemoveSavedFile = (options?: RemoveSavedFileOptions | null) => void;
export type GetSavedFileList = (options?: GetSavedFileListOptions | null) => void;
export interface Uni {
/**
* 保存文件
* @uniPlatform {
* "app": {
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.25",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* @uniVueVersion 2,3 //支持的vue版本
*/
saveFile(options?: SaveFileOptions | null): void;
/**
* 获取本地已保存的文件列表
* @uniPlatform {
* "app": {
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.25",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* @uniVueVersion 2,3 //支持的vue版本
*/
getSavedFileList(options?: GetSavedFileListOptions | null): void;
/**
* 获取已保存到本地的文件信息
* @uniPlatform {
* "app": {
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.25",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* @uniVueVersion 2,3 //支持的vue版本
*/
getSavedFileInfo(options?: GetSavedFileInfoOptions | null): void;
/**
* 删除已保存的文件
* @uniPlatform {
* "app": {
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.25",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* @uniVueVersion 2,3 //支持的vue版本
*/
removeSavedFile(options?: RemoveSavedFileOptions | null): void;
/**
* 获取文件信息
* @uniPlatform {
* "app": {
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.25",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* @uniVueVersion 2,3 //支持的vue版本
*/
getFileInfo(options?: GetFileInfoOptions | null): void;
}
export const API_SAVE_FILE = 'saveFile'
export const API_GET_FILE_INFO = 'getFileInfo'
export const API_GET_SAVED_FILE_INFO = 'getSavedFileInfo'
export const API_GET_SAVED_FILE_LIST = 'getSavedFileList'
export const API_REMOVE_SAVED_FILE = 'removeSavedFile'
export const SaveFileApiProtocol = new Map<string, ProtocolOptions>([
[
'tempFilePath',
{
type: 'string',
required: true
}
]
])
export const GetFileInfoApiProtocol = new Map<string, ProtocolOptions>([
[
'filePath',
{
type: 'string',
required: true
}
],
[
'digestAlgorithm',
{
type: 'string',
required: false
}
]
])
export const GetSavedFileInfoApiProtocol = new Map<string, ProtocolOptions>([
[
'filePath',
{
type: 'string',
required: true
}
]
])
export const RemoveSavedFileApiProtocol = new Map<string, ProtocolOptions>([
[
'filePath',
{
type: 'string',
required: true
}
]
])
...@@ -2,13 +2,6 @@ ...@@ -2,13 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>TencentLBSAPIKey</key>
<string>WZCBZ-OLPCU-TJJVJ-4LZTE-SSG5O-6JFEM</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key> <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>允许使用定位权限吗</string> <string>允许使用定位权限吗</string>
<key>NSLocationAlwaysUsageDescription</key> <key>NSLocationAlwaysUsageDescription</key>
......
...@@ -2109,8 +2109,8 @@ export type GetWindowInfoResult = { ...@@ -2109,8 +2109,8 @@ export type GetWindowInfoResult = {
/** /**
* 窗口上边缘的 y 值,单位为px * 窗口上边缘的 y 值,单位为px
* *
* @uniPlatform
* @deprecated 已废弃,仅为了向下兼容保留 * @deprecated 已废弃,仅为了向下兼容保留
* @uniPlatform
* { * {
* "app": { * "app": {
* "android": { * "android": {
......
{
"id": "uni-exit",
"displayName": "uni-exit",
"version": "1.0.0",
"description": "uni-exit",
"keywords": [
"uni-exit"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"uni-ext-api": {
"uni": {
"hideKeyboard": {
"name": "hideKeyboard",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
}
}
},
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "y",
"vue3": "y"
},
"App": {
"app-android": "y",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
# uni-keyboard
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts)
import { UTSHarmony } from "@dcloudio/uni-runtime"
import {
API_HIDE_KEYBOARD
} from '../protocol.uts'
import {
HideKeyboardOptions,
HideKeyboardSuccess,
HideKeyboardFail,
HideKeyboard
} from '../interface.uts'
import inputMethod from '@ohos.inputMethod';
export {
HideKeyboardOptions,
HideKeyboardSuccess,
HideKeyboardFail,
}
export const hideKeyboard: HideKeyboard = defineAsyncApi<HideKeyboardOptions, HideKeyboardSuccess>(
API_HIDE_KEYBOARD,
function (options: HideKeyboardOptions, exec: ApiExecutor<HideKeyboardSuccess>) {
inputMethod.getController().hideTextInput().then(() => {
exec.resolve()
}, (err: Error) => {
exec.reject(err.message)
})
}
) as HideKeyboard
/**
* uni.hideKeyboard成功回调参数
*/
export type HideKeyboardSuccess = {}
export type HideKeyboardFail = {}
/**
* uni.hideKeyboard成功回调函数定义
*/
export type HideKeyboardSuccessCallback = (res: HideKeyboardSuccess) => void
/**
* uni.hideKeyboard失败回调函数定义
*/
export type HideKeyboardFailCallback = (res: HideKeyboardFail) => void
/**
* uni.hideKeyboard完成回调函数定义
*/
export type HideKeyboardCompleteCallback = (res: any) => void
/**
* uni.hideKeyboard参数定义
*/
export type HideKeyboardOptions = {
/**
* 接口调用成功的回调函数
*/
success?: HideKeyboardSuccessCallback | null,
/**
* 接口调用失败的回调函数
*/
fail?: HideKeyboardFailCallback | null,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
complete?: HideKeyboardCompleteCallback | null
}
export interface Uni {
/**
* 隐藏键盘
* @uniPlatform {
* "app": {
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.23",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
* @uniVueVersion 2,3 //支持的vue版本
*/
hideKeyboard(options?: HideKeyboardOptions | null): void;
}
export type HideKeyboard = (options?: HideKeyboardOptions | null) => void;
export const API_HIDE_KEYBOARD = 'hideKeyboard'
{
"id": "uni-makePhoneCall",
"displayName": "uni-makePhoneCall",
"version": "1.0.0",
"description": "uni-makePhoneCall",
"keywords": [
"uni-makePhoneCall"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"uni-ext-api": {
"uni": {
"makePhoneCall": {
"name": "makePhoneCall",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
}
}
},
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
# uni-makePhoneCall
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts/-/tree/dev)
import { UTSHarmony } from '@dcloudio/uni-runtime';
import { BusinessError } from '@kit.BasicServicesKit'
import call from '@ohos.telephony.call'
import { MakePhoneCall, MakePhoneCallOptions, MakePhoneCallSuccess } from '../interface.uts';
import { API_MAKE_PHONE_CALL, MakePhoneCallProtocol } from '../protocol.uts';
export { MakePhoneCall, MakePhoneCallOptions, MakePhoneCallSuccess }
function isPromise(res: any) {
if ((typeof res === "object" || typeof res === "function") && typeof (res as Promise<void>).then === "function") {
return true;
}
return false
}
function dial(number: string, confirm = true) {
if (!confirm && typeof call.dial === 'function') {
return new Promise<void>((resolve, reject) => {
UTSHarmony.requestSystemPermission(['ohos.permission.PLACE_CALL'], (allRight: boolean) => {
if (allRight) {
call
.dial(number)
.then(() => {
resolve()
})
.catch(reject)
} else {
reject('permission denied')
}
}, () => {
reject('permission denied')
})
})
} else {
return call.makeCall(number)
}
}
export const makePhoneCall: MakePhoneCall = defineAsyncApi<MakePhoneCallOptions, MakePhoneCallSuccess>(
API_MAKE_PHONE_CALL,
(options: MakePhoneCallOptions, res: ApiExecutor<MakePhoneCallSuccess>) => {
const dialRes = dial(options.phoneNumber) as unknown as Promise<void>
if (isPromise(dialRes)) {
dialRes
.then(res.resolve)
.catch((err: BusinessError<void>) => {
res.reject(err.message)
})
} else {
res.resolve()
}
},
MakePhoneCallProtocol
) as MakePhoneCall
export interface Uni {
/**
* 拨打电话
*
* @tutorial https://uniapp.dcloud.net.cn/api/system/phone.html#makephonecall
* @tutorial-uni-app https://uniapp.dcloud.net.cn/api/system/phone.html#makephonecall
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "12.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.23",
* "unixVer": "x"
* }
* },
* "mp": {
* "weixin": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "alipay": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "baidu": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "toutiao": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "lark": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "√"
* },
* "qq": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "kuaishou": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* },
* "jd": {
* "hostVer": "√",
* "uniVer": "√",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/
makePhoneCall: MakePhoneCall;
}
export type MakePhoneCall = (options: MakePhoneCallOptions) => void;
export type MakePhoneCallSuccess = {};
export type MakePhoneCallSuccessCallback = (result: MakePhoneCallSuccess) => void;
export type MakePhoneCallFail = UniError;
export type MakePhoneCallFailCallback = (result: MakePhoneCallFail) => void;
export type MakePhoneCallComplete = any;
export type MakePhoneCallCompleteCallback = (result: MakePhoneCallComplete) => void;
export type MakePhoneCallOptions = {
/**
* 需要拨打的电话号码
*/
phoneNumber: string,
/**
* 成功返回的回调函数
*/
success?: MakePhoneCallSuccessCallback | null,
/**
* 失败的回调函数
*/
fail?: MakePhoneCallFailCallback | null,
/**
* 结束的回调函数(调用成功、失败都会执行)
*/
complete?: MakePhoneCallCompleteCallback | null
};
export const API_MAKE_PHONE_CALL = 'makePhoneCall'
export const MakePhoneCallProtocol = new Map<string, ProtocolOptions>([
[
'phoneNumber',
{
type: 'string',
required: true,
}
]
])
...@@ -17,7 +17,7 @@ import { ...@@ -17,7 +17,7 @@ import {
} from "../unierror.uts" } from "../unierror.uts"
import { chooseMediaImage, chooseMediaVideo } from "./utils/ChooseMediaUtils.uts" import { chooseMediaImage, chooseMediaVideo } from "./utils/ChooseMediaUtils.uts"
import { transcodeImage, transcodeVideo } from './utils/CompressUtils.uts' import { transcodeImage, transcodeVideo } from './utils/CompressUtils.uts'
import { getVideoMetadata } from "./utils/MediaUtils.uts" import { getVideoMetadata, copyFile } from "./utils/MediaUtils.uts"
import Intent from 'android.content.Intent'; import Intent from 'android.content.Intent';
import Manifest from 'android.Manifest'; import Manifest from 'android.Manifest';
import Build from 'android.os.Build'; import Build from 'android.os.Build';
...@@ -258,10 +258,16 @@ class ImageInfoTarget extends CustomTarget<File> { ...@@ -258,10 +258,16 @@ class ImageInfoTarget extends CustomTarget<File> {
function getExif(src : string, options : GetImageInfoOptions, bitmapOption : BitmapFactory.Options | null) { function getExif(src : string, options : GetImageInfoOptions, bitmapOption : BitmapFactory.Options | null) {
var exifInfo : ExifInterface | null = null var exifInfo : ExifInterface | null = null
if(bitmapOption == null) {
bitmapOption = new BitmapFactory.Options();
bitmapOption.inJustDecodeBounds = true;
}
if (src.startsWith(ASSETS_PATH)) { if (src.startsWith(ASSETS_PATH)) {
exifInfo = new ExifInterface(UTSAndroid.getUniActivity()!.getAssets().open(src.replace(ASSETS_PATH, ""))); exifInfo = new ExifInterface(UTSAndroid.getUniActivity()!.getAssets().open(src.replace(ASSETS_PATH, "")));
BitmapFactory.decodeStream(UTSAndroid.getUniActivity()!.getAssets().open(src.replace(ASSETS_PATH, "")), null, bitmapOption)
} else if (new File(src).exists()) { } else if (new File(src).exists()) {
exifInfo = new ExifInterface(src) exifInfo = new ExifInterface(src)
BitmapFactory.decodeFile(src, bitmapOption)
} else { } else {
let imageInfoCallback = new MediaErrorImpl(1101003, UniError_GetImageInfo); let imageInfoCallback = new MediaErrorImpl(1101003, UniError_GetImageInfo);
options.fail?.(imageInfoCallback) options.fail?.(imageInfoCallback)
...@@ -269,11 +275,6 @@ function getExif(src : string, options : GetImageInfoOptions, bitmapOption : Bit ...@@ -269,11 +275,6 @@ function getExif(src : string, options : GetImageInfoOptions, bitmapOption : Bit
return return
} }
try { try {
if (bitmapOption == null) {
bitmapOption = new BitmapFactory.Options();
bitmapOption.inJustDecodeBounds = true;
BitmapFactory.decodeFile(src, bitmapOption)
}
let width = bitmapOption!.outWidth let width = bitmapOption!.outWidth
let height = bitmapOption!.outHeight let height = bitmapOption!.outHeight
let mimeType : string = bitmapOption!.outMimeType let mimeType : string = bitmapOption!.outMimeType
...@@ -326,53 +327,6 @@ function getExif(src : string, options : GetImageInfoOptions, bitmapOption : Bit ...@@ -326,53 +327,6 @@ function getExif(src : string, options : GetImageInfoOptions, bitmapOption : Bit
} }
} }
function copyFile(fromFilePath : string, toFilePath : string) : boolean {
var fis : InputStream | null = null
try {
if (fromFilePath.startsWith(ASSETS_PATH)) {
fis = UTSAndroid.getUniActivity()!.getAssets().open(fromFilePath.replace(ASSETS_PATH, ""));
} else {
let fromFile = new File(fromFilePath)
if (!fromFile.exists()) {
return false;
}
if (!fromFile.isFile()) {
return false
}
if (!fromFile.canRead()) {
return false;
}
fis = new FileInputStream(fromFile);
}
if (fis == null) {
return false
}
} catch (e) {
return false;
}
let toFile = new File(toFilePath)
if (!toFile.getParentFile().exists()) {
toFile.getParentFile().mkdirs()
}
if (!toFile.exists()) {
toFile.createNewFile()
}
try {
let fos = new FileOutputStream(toFile)
let byteArrays = ByteArray(1024)
var c = fis!!.read(byteArrays)
while (c > 0) {
fos.write(byteArrays, 0, c)
c = fis!!.read(byteArrays)
}
fis!!.close()
fos.close()
return true
} catch (e) {
return false;
}
}
export const saveImageToPhotosAlbum : SaveImageToPhotosAlbum = function (options : SaveImageToPhotosAlbumOptions) { export const saveImageToPhotosAlbum : SaveImageToPhotosAlbum = function (options : SaveImageToPhotosAlbumOptions) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
let requestPermissionList : Array<string> = [Manifest.permission.WRITE_EXTERNAL_STORAGE] let requestPermissionList : Array<string> = [Manifest.permission.WRITE_EXTERNAL_STORAGE]
......
...@@ -5,12 +5,18 @@ import { ...@@ -5,12 +5,18 @@ import {
UniError_GetVideoInfo, UniError_GetVideoInfo,
MediaErrorImpl MediaErrorImpl
} from "../../unierror.uts" } from "../../unierror.uts"
import File from 'java.io.File'; import File from 'java.io.File';
import MediaMetadataRetriever from 'android.media.MediaMetadataRetriever'; import MediaMetadataRetriever from 'android.media.MediaMetadataRetriever';
import BigDecimal from 'java.math.BigDecimal'; import BigDecimal from 'java.math.BigDecimal';
import MediaExtractor from 'android.media.MediaExtractor'; import MediaExtractor from 'android.media.MediaExtractor';
import MediaFormat from 'android.media.MediaFormat'; import MediaFormat from 'android.media.MediaFormat';
import TextUtils from 'android.text.TextUtils'; import TextUtils from 'android.text.TextUtils';
import FileOutputStream from 'java.io.FileOutputStream';
import FileInputStream from 'java.io.FileInputStream';
import InputStream from 'java.io.InputStream';
const ASSETS_PATH = '/android_asset/'
export function getVideoMetadata(src : string) : any { export function getVideoMetadata(src : string) : any {
let videoInfo : GetVideoInfoSuccess = { let videoInfo : GetVideoInfoSuccess = {
...@@ -19,7 +25,16 @@ export function getVideoMetadata(src : string) : any { ...@@ -19,7 +25,16 @@ export function getVideoMetadata(src : string) : any {
height: 0, height: 0,
width: 0 width: 0
} }
let path = UTSAndroid.convert2AbsFullPath(src) var path = UTSAndroid.convert2AbsFullPath(src)
if (path.startsWith("/android_asset/")) {
var mediaCachePath = UTSAndroid.getAppCachePath() + "uni-media/_" + System.currentTimeMillis()
if (copyFile(path, mediaCachePath)) {
path = mediaCachePath
} else {
let error = new MediaErrorImpl(1101010, UniError_GetVideoInfo);
return error
}
}
let videoFile = new File(path) let videoFile = new File(path)
if (!videoFile.exists()) { if (!videoFile.exists()) {
let error = new MediaErrorImpl(1101003, UniError_GetVideoInfo); let error = new MediaErrorImpl(1101003, UniError_GetVideoInfo);
...@@ -97,4 +112,52 @@ export function getVideoMetadata(src : string) : any { ...@@ -97,4 +112,52 @@ export function getVideoMetadata(src : string) : any {
let error = new MediaErrorImpl(1101010, UniError_GetVideoInfo); let error = new MediaErrorImpl(1101010, UniError_GetVideoInfo);
return error return error
} }
}
export function copyFile(fromFilePath : string, toFilePath : string) : boolean {
var fis : InputStream | null = null
try {
if (fromFilePath.startsWith(ASSETS_PATH)) {
fis = UTSAndroid.getUniActivity()!.getAssets().open(fromFilePath.replace(ASSETS_PATH, ""));
} else {
let fromFile = new File(fromFilePath)
if (!fromFile.exists()) {
return false;
}
if (!fromFile.isFile()) {
return false
}
if (!fromFile.canRead()) {
return false;
}
fis = new FileInputStream(fromFile);
}
if (fis == null) {
return false
}
} catch (e) {
return false;
}
let toFile = new File(toFilePath)
if (!toFile.getParentFile().exists()) {
toFile.getParentFile().mkdirs()
}
if (!toFile.exists()) {
toFile.createNewFile()
}
try {
let fos = new FileOutputStream(toFile)
let byteArrays = ByteArray(1024)
var c = fis!!.read(byteArrays)
while (c > 0) {
fos.write(byteArrays, 0, c)
c = fis!!.read(byteArrays)
}
fis!!.close()
fos.close()
return true
} catch (e) {
return false;
}
} }
\ No newline at end of file
...@@ -175,9 +175,15 @@ export const getImageInfo : GetImageInfo = function (options : GetImageInfoOptio ...@@ -175,9 +175,15 @@ export const getImageInfo : GetImageInfo = function (options : GetImageInfoOptio
if (options.src.length > 0) { if (options.src.length > 0) {
if (isNetUrl(options.src)) { if (isNetUrl(options.src)) {
UTSiOS.loadImage(options.src, (image, data) => { UTSiOS.loadImage(options.src, (image, data) => {
if (data != null && image != null) { if (image != null) {
const type = getImageFormat(data!); let imageData : Data | null = null;
const path = saveImage(data!, type); if(data != null){
imageData = data;
}else{
imageData = image!.jpegData(compressionQuality= 1.0);
}
const type = getImageFormat(imageData!);
const path = saveImage(imageData!, type);
if (path.count > 0) { if (path.count > 0) {
DispatchQueue.main.async(execute = () : void => { DispatchQueue.main.async(execute = () : void => {
let successCallback : GetImageInfoSuccess = { let successCallback : GetImageInfoSuccess = {
......
...@@ -115,7 +115,6 @@ export type ChooseImageOptions = { ...@@ -115,7 +115,6 @@ export type ChooseImageOptions = {
count ?: (number) | null, count ?: (number) | null,
/** /**
* original 原图,compressed 压缩图,默认二者都有 * original 原图,compressed 压缩图,默认二者都有
* @type string | string []
* @defaultValue ['original','compressed'] * @defaultValue ['original','compressed']
* @uniPlatform { * @uniPlatform {
* "app":{ * "app":{
...@@ -250,6 +249,30 @@ export type PreviewImageOptions = { ...@@ -250,6 +249,30 @@ export type PreviewImageOptions = {
urls : Array<string.ImageURIString>, urls : Array<string.ImageURIString>,
/** /**
* 是否显示长按菜单 * 是否显示长按菜单
*
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "5.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "ios": {
* "osVer": "10.0",
* "uniVer": "√",
* "unixVer": "x"
* },
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.23",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "√",
* "unixVer": "4.0"
* }
* }
*/ */
showmenu ?: boolean | null, showmenu ?: boolean | null,
/** /**
......
{
"id": "uni-openDocument",
"displayName": "uni-openDocument",
"version": "1.0.0",
"description": "uni-openDocument",
"keywords": [
"uni-openDocument"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"uni-ext-api": {
"uni": {
"openDocument": {
"name": "openDocument",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
}
}
},
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "y",
"vue3": "y"
},
"App": {
"app-android": "y",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
# uni-openDocument
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts)
import {
API_OPEN_DOCUMENT
} from '../protocol.uts'
import {
OpenDocumentFail,
OpenDocumentSuccess,
OpenDocumentOptions,
OpenDocument
} from '../interface.uts'
import {
getAbilityContext
} from '@dcloudio/uni-runtime'
import fileUri from '@ohos.file.fileuri';
import Want from '@ohos.app.ability.Want';
import wantConstant from '@ohos.app.ability.wantConstant';
import common from '@ohos.app.ability.common';
export {
OpenDocumentFail,
OpenDocumentSuccess,
OpenDocumentOptions,
}
function getContentType(filePath: string, fileType?: string | null): string | void {
const suffix = fileType || filePath.split('.').pop();
if (!suffix) {
return;
}
switch (suffix) {
case 'doc':
case 'docx':
return 'application/msword';
case 'xls':
case 'xlsx':
return 'application/vnd.ms-excel';
case 'ppt':
case 'pptx':
return 'application/vnd.ms-powerpoint';
case 'pdf':
return 'application/pdf';
default:
return;
}
}
export const openDocument: OpenDocument = defineAsyncApi<OpenDocumentOptions, OpenDocumentSuccess>(
API_OPEN_DOCUMENT,
function (options: OpenDocumentOptions, exec: ApiExecutor<OpenDocumentSuccess>) {
const filePath = options.filePath
const uri = fileUri.getUriFromPath(filePath.replace(/^file:\/\//, ''));
const fileContentType = getContentType(filePath, options.fileType);
if (!fileContentType) {
exec.reject('file type not supported');
return
}
const want: Want = {
flags: wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION | wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION | wantConstant.Flags.FLAG_AUTH_PERSISTABLE_URI_PERMISSION,
action: 'ohos.want.action.sendData',
uri: uri,
type: fileContentType as string
}
const abilityContext = getAbilityContext() as common.UIAbilityContext
abilityContext.startAbility(want).then(() => {
exec.resolve({} as OpenDocumentSuccess)
}, (err: Error) => {
exec.reject(err.message);
})
}
) as OpenDocument
/**
* uni.openDocument成功回调参数
*/
export type OpenDocumentSuccess = {}
export type OpenDocumentFail = {}
/**
* uni.openDocument成功回调函数定义
*/
export type OpenDocumentSuccessCallback = (res: OpenDocumentSuccess) => void
/**
* uni.openDocument失败回调函数定义
*/
export type OpenDocumentFailCallback = (res: OpenDocumentFail) => void
/**
* uni.openDocument完成回调函数定义
*/
export type OpenDocumentCompleteCallback = (res: any) => void
export type OpenDocumentSupportedTypes = 'doc' | 'xls' | 'ppt' | 'pdf' | 'docx' | 'xlsx' | 'pptx'
/**
* uni.openDocument参数定义
*/
export type OpenDocumentOptions = {
/**
* 文件路径,仅支持本地路径
*/
filePath: string,
/**
* 文件类型,指定文件类型打开文件,有效值 doc, xls, ppt, pdf, docx, xlsx, pptx
*/
fileType?: OpenDocumentSupportedTypes | null,
/**
* 接口调用成功的回调函数
*/
success?: OpenDocumentSuccessCallback | null,
/**
* 接口调用失败的回调函数
*/
fail?: OpenDocumentFailCallback | null,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
complete?: OpenDocumentCompleteCallback | null
}
export interface Uni {
/**
* 打开文档
* @uniPlatform {
* "app": {
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.23",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* @uniVueVersion 2,3 //支持的vue版本
*/
openDocument(options?: OpenDocumentOptions | null): void;
}
export type OpenDocument = (options?: OpenDocumentOptions | null) => void;
export const API_OPEN_DOCUMENT = 'openDocument'
{
"id": "uni-scanCode",
"displayName": "uni-scanCode",
"version": "1.0.0",
"description": "uni-scanCode",
"keywords": [
"uni-scanCode"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"uni-ext-api": {
"uni": {
"scanCode": {
"name": "scanCode",
"app": {
"js": false,
"kotlin": false,
"swift": false,
"arkts": true
}
}
}
},
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "y",
"vue3": "y"
},
"App": {
"app-android": "y",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
# uni-scanCode
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts)
import {
API_SCAN_CODE
} from '../protocol.uts'
import {
ScanCodeFail,
ScanCodeSuccess,
ScanCodeOptions,
ScanCodeSupportedTypes,
ScanCode
} from '../interface.uts'
import {
getAbilityContext
} from '@dcloudio/uni-runtime'
import { scanCore, scanBarcode } from '@kit.ScanKit';
export {
ScanCodeFail,
ScanCodeSuccess,
ScanCodeOptions,
}
let supportedScanTypesMap: Map<ScanCodeSupportedTypes, scanCore.ScanType>
function initScanTypesMapOnce() {
if (supportedScanTypesMap) {
return
}
supportedScanTypesMap = new Map<ScanCodeSupportedTypes, scanCore.ScanType>([
['barCode', scanCore.ScanType.CODABAR_CODE],
['qrCode', scanCore.ScanType.QR_CODE],
['datamatrix', scanCore.ScanType.DATAMATRIX_CODE],
['pdf417', scanCore.ScanType.PDF417_CODE]
]);
}
function getUniScanType(scanType: scanCore.ScanType): ScanCodeSupportedTypes {
for (const [key, value] of supportedScanTypesMap.entries()) {
if (value === scanType) {
return key;
}
}
return 'qrCode';
}
export const scanCode: ScanCode = defineAsyncApi<ScanCodeOptions, ScanCodeSuccess>(
API_SCAN_CODE,
function (options: ScanCodeOptions, exec: ApiExecutor<ScanCodeSuccess>) {
if (!canIUse('SystemCapability.Multimedia.Scan.ScanBarcode')) {
exec.reject('not support');
return
}
initScanTypesMapOnce();
let scanTypes: scanCore.ScanType[] = [scanCore.ScanType.ALL];
if (options.scanType && Array.isArray(options.scanType) && options.scanType.length > 0) {
scanTypes = options.scanType.filter((type) => {
return supportedScanTypesMap.has(type);
}).map((type) => {
return supportedScanTypesMap.get(type)!;
})
}
const scanOptions: scanBarcode.ScanOptions = {
scanTypes,
enableMultiMode: true,
enableAlbum: !options.onlyFromCamera
};
scanBarcode.startScanForResult(getAbilityContext()!, scanOptions, (err, data) => {
if (err) {
exec.reject(err.message);
return;
}
exec.resolve({
result: data.originalValue,
scanType: getUniScanType(data.scanType),
} as ScanCodeSuccess)
})
}
) as ScanCode
/**
* uni.scanCode成功回调参数
*/
export type ScanCodeSuccess = {
result: string,
scanType: ScanCodeSupportedTypes
}
export type ScanCodeFail = {}
/**
* uni.scanCode成功回调函数定义
*/
export type ScanCodeSuccessCallback = (res: ScanCodeSuccess) => void
/**
* uni.scanCode失败回调函数定义
*/
export type ScanCodeFailCallback = (res: ScanCodeFail) => void
/**
* uni.scanCode完成回调函数定义
*/
export type ScanCodeCompleteCallback = (res: any) => void
export type ScanCodeSupportedTypes = 'barCode' | 'qrCode' | 'datamatrix' | 'pdf417'
/**
* uni.scanCode参数定义
*/
export type ScanCodeOptions = {
/**
* 是否只能从相机扫码,不允许从相册选择图片
*/
onlyFromCamera?: boolean | null,
/**
* 扫码类型
*/
scanType?: ScanCodeSupportedTypes[] | null,
/**
* 接口调用成功的回调函数
*/
success?: ScanCodeSuccessCallback | null,
/**
* 接口调用失败的回调函数
*/
fail?: ScanCodeFailCallback | null,
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
complete?: ScanCodeCompleteCallback | null
}
export interface Uni {
/**
* 扫码
* @uniPlatform {
* "app": {
* "harmony": {
* "osVer": "3.0",
* "uniVer": "4.23",
* "unixVer": "x"
* }
* },
* "web": {
* "uniVer": "x",
* "unixVer": "x"
* }
* }
* @uniVueVersion 2,3 //支持的vue版本
*/
scanCode(options?: ScanCodeOptions | null): void;
}
export type ScanCode = (options?: ScanCodeOptions | null) => void;
export const API_SCAN_CODE = 'scanCode'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册