您的位置:首页 > 财经 > 产业 > pta程序设计平台_设备管理系统下载_免费外链工具_新网店怎么免费推广

pta程序设计平台_设备管理系统下载_免费外链工具_新网店怎么免费推广

2025/1/4 19:05:44 来源:https://blog.csdn.net/sjw890821sjw/article/details/144798925  浏览:    关键词:pta程序设计平台_设备管理系统下载_免费外链工具_新网店怎么免费推广
pta程序设计平台_设备管理系统下载_免费外链工具_新网店怎么免费推广
1、HarmonyOS 无限循环的 animateTo 动画有办法主动停止吗?
@Component
export struct Test {@State message: string = 'Hello World';@State opacityValue: number = 1build() {Row() {Column() {Text(this.message).fontSize(50).fontWeight(FontWeight.Bold).opacity(this.opacityValue)Button("开始动画").onClick(() => {animateTo({ duration: 1000, iterations: -1, playMode: PlayMode.AlternateReverse }, () => {this.opacityValue = 0})})Button("结束动画").onClick(() => {animateTo({duration: 0, iterations: 1, onFinish: () => {this.opacityValue = 1}}, () => {this.opacityValue = 0.9})})}.width('100%')}.height('100%')}
}
2、HarmonyOS 系统右滑和左滑手势如何关闭或者如何更改手势交互?

在项目部分页面需要关闭系统右滑和左滑手势,部分页面需要修改右滑和左滑手势事件。

通过onBackPress事件拦截,返回true表示页面自己处理返回逻辑,参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs-V5/faqs-arkui-29-V5

3、HarmonyOS 登录页面跳转?

应用登录之后,进入应用首页,接着进入下一级页面,在某个下一级页面需要弹出登录页面,登录完成之后,需要显示的是应用首页,这个要怎么管控页面的跳转,才能回到应用首页

问题中提到的场景,在登录页面登录完成之后都需要回到应用首页;直接清空路由栈,然后push到首页这种是否可以满足业务场景

Button("登录").onClick((event: ClickEvent) => {//业务处理,登录校验//然后清空路由栈,跳转到首页router.clear()router.pushUrl({url:'pages/Index'})})
4、HarmonyOS Web组件如何拉起相册,相机以及文件管理器?
import web_webview from '@ohos.web.webview'
import { common } from '@kit.AbilityKit'
import { uri, util } from '@kit.ArkTS'
import fs from '@ohos.file.fs';
import picker from '@ohos.file.picker'
import { BusinessError } from '@kit.BasicServicesKit';class testClass {base64Str: stringconstructor(base64Str:string) {this.base64Str=base64Str;}test(): string {return "2123";}toString(): void {console.log('Web Component toString');}
}@Entry
@Component
struct WebComponent {controller: web_webview.WebviewController = new web_webview.WebviewController()//定义一个全局的string类型的数组,用来存放通过picker拉起后选择完图片后图片的uri@State uris: Array<string> = []@State base64Str : string = ""@State testObj: testClass = new testClass(this.base64Str);aboutToAppear() {web_webview.WebviewController.setWebDebuggingAccess(true);}build() {Column() {Web({ src: $rawfile('TestonShowFileSelector.html'), controller: this.controller }).javaScriptAccess(true).domStorageAccess(true).onShowFileSelector((event) => {// //-------调用相册-------------------------console.log('MyFileUploader onShowFileSelector invoked')const photoSelectOptions = new picker.PhotoSelectOptions();// 过滤选择媒体文件类型为IMAGE_VIDEO_TYPEphotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_VIDEO_TYPE;// 选择媒体文件的最大数目photoSelectOptions.maxSelectNumber = 8;//let uris: Array<string> = [];const photoViewPicker = new picker.PhotoViewPicker();photoViewPicker.select(photoSelectOptions).then((photoSelectResult: picker.PhotoSelectResult) => {this.uris = photoSelectResult.photoUris;let file1 = fs.openSync(this.uris[0])let array:ArrayBuffer = new ArrayBuffer(fs.statSync(file1.fd).size)fs.readSync(file1.fd,array)let unit = new Uint8Array(array)let base64 = new util.Base64Helper();let mystr = base64.encodeToStringSync(unit);this.base64Str = "myFunction(\"" + mystr + "\")"this.controller.runJavaScript(this.base64Str)console.info('photoViewPicker.select to file succeed and uris are:' + this.uris);//file://media/Photo/11/IMG_1713942933_005/IMG_20240424_151353.jpg}).catch((err: BusinessError) => {console.error(`Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`);})return false//----调用文件管理器-----------------// console.log('MyFileUploader onShowFileSelector invoked')// const documentSelectOptions = new picker.DocumentSelectOptions();// // 选择媒体文件的最大数目// documentSelectOptions.maxSelectNumber = 2;// const documentViewPicker = new picker.DocumentViewPicker();// documentViewPicker.select(documentSelectOptions).then((DocumentSelectResult: Array<string>) => {//   this.uris = DocumentSelectResult;//   console.info('photoViewPicker.select to file succeed and uris are:' + this.uris);// }).catch((err: BusinessError) => {//   console.error(`Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`);// })// return false-----相机--------------------------------// const context = getContext(this) as common.UIAbilityContext// context.startAbilityForResult({//   action:"ohos.want.action.imageCapture",//   parameters:{//     callBundleName:"com.hm.imageshow"//   }// }).then((res)=>{//   console.log("testTag - " +JSON.stringify(res));//   let str:string = res.want?.parameters!["resourceUri"] as string//   console.log("str"+str);//file://media/Photo/11/IMG_1713942933_005/IMG_20240424_151353.jpg//   let fd = fs.openSync(str).fd//   this.uris[0] = str//   let arr:ArrayBuffer = new ArrayBuffer(128)//   fs.readSync(fd,arr)//   console.log("testTag - " + str);//// })//return false})}}
}
<form id="upload-form" enctype="multipart/form-data"><!-- 修改type属性为camera --><input type="file" id="upload" name="upload" accept="image/*" capture="camera" /><!-- 添加一个图片元素用于展示图片 --><img id="preview"/>
</form>
<div id="155134"></div>
5、HarmonyOS 怎么禁止侧滑?

可以在页面生命周期中返回true onBackPress() { return true }

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com