diff --git a/build.gradle b/build.gradle index bf479ca657fb6b63c48c13c097af23041e8b2e1e..60b8bd7c4a6e8a4486188dbed0291e3566bfe4c6 100644 --- a/build.gradle +++ b/build.gradle @@ -19,8 +19,8 @@ buildscript { jcenter() } dependencies { - classpath 'com.huawei.ohos:hap:2.4.5.0' - classpath 'com.huawei.ohos:decctest:1.2.4.1' + classpath 'com.huawei.ohos:hap:2.4.5.5' + classpath 'com.huawei.ohos:decctest:1.2.5.1' } } diff --git a/entry/src/main/config.json b/entry/src/main/config.json index 14a60b0e443f0cb7a5c5fb92d1690f806bd57b79..33e946daff4dacfc891eeb3fff2ba8a7e9726db0 100644 --- a/entry/src/main/config.json +++ b/entry/src/main/config.json @@ -32,7 +32,7 @@ ] } ], - "orientation": "unspecified", + "orientation": "portrait", "name": "com.stx.xhb.customwaterview.MainAbility", "icon": "$media:icon", "description": "$string:mainability_description", @@ -42,7 +42,7 @@ }, { - "orientation": "unspecified", + "orientation": "portrait", "icon": "$media:icon", "name": "com.stx.xhb.customwaterview.JsForestAbility", "description": "", diff --git a/entry/src/main/java/com/stx/xhb/customwaterview/components/WaterFlake.java b/entry/src/main/java/com/stx/xhb/customwaterview/components/WaterFlake.java index 51935b5548b4d07fe201dbaabb3ba7c4a042491a..b4b650a01c98c9f7498c4b1e04c0112bec325525 100644 --- a/entry/src/main/java/com/stx/xhb/customwaterview/components/WaterFlake.java +++ b/entry/src/main/java/com/stx/xhb/customwaterview/components/WaterFlake.java @@ -182,6 +182,9 @@ public class WaterFlake extends StackLayout implements Component.EstimateSizeLis view.setClickedListener(new ClickedListener() { @Override public void onClick(Component component) { + if (isCollect) { + return; + } if (mOnWaterItemListener != null) { mOnWaterItemListener.onItemClick(waterModel); collectAnimator(view); diff --git a/entry/src/main/js/default/common/component/waterflake/waterFlake.js b/entry/src/main/js/default/common/component/waterflake/waterFlake.js index 30f469a0e2ec74e89b09f71fb0cc0a98bf0bff46..63c0d0b750c7d0091189a372d1d6299cc511f5b5 100644 --- a/entry/src/main/js/default/common/component/waterflake/waterFlake.js +++ b/entry/src/main/js/default/common/component/waterflake/waterFlake.js @@ -15,28 +15,29 @@ export default { props: { - //后台返回的小球信息 + //后台返回的小球信息 ballList: { default: [10, 11, 12, 13, 14], }, - // 收集能量动画结束的X坐标 + // 收集能量动画结束的X坐标 collDestinationX: { default: 0 }, - // 收集能量动画结束的Y坐标 + // 收集能量动画结束的Y坐标 collDestinationY: { default: 600 } }, data() { return { - /** + /** * ballDataList的每个对象包括以下属性: * content(小球显示的文本信息) * x(横坐标)、 * y(纵坐标)、 */ ballDataList: [], + collectionAnimation: null, isCollect: false // 是否正在执行收集能量动画 }; }, @@ -44,45 +45,56 @@ export default { this.$watch('ballList', 'onBallListChange'); //注册数据变化监听 }, onReady() { - let width = 720 //组件的款第 - let height = 600 //组件的高度 - // 生成小球的x坐标数组 - let xRandom = this.randomCommon(1, 8, this.ballList.length) - if (xRandom == null) { - return - } - let all_x = xRandom.map(item => { - return item * width * 0.10 - }); - //生成小球的y坐标数组 - let yRandom = this.randomCommon(1, 8, this.ballList.length); - if (yRandom == null) { - return + this.initData() + }, + initData() { + if (this.collectionAnimation != null) { + this.collectionAnimation.cancel() } - let all_y = yRandom.map(item => { - return item * height * 0.08 - }) - let dataList = [] - for (let index = 0; index < this.ballList.length; index++) { - dataList.push({ - content: this.ballList[index] + 'g', - x: all_x[index], - y: all_y[index] + setTimeout(() => { + let width = 720 //组件的款第 + let height = 600 //组件的高度 + // 生成小球的x坐标数组 + let xRandom = this.randomCommon(1, 8, this.ballList.length) + if (xRandom == null) { + return + } + let all_x = xRandom.map(item => { + return item * width * 0.10 + }); + //生成小球的y坐标数组 + let yRandom = this.randomCommon(1, 8, this.ballList.length); + if (yRandom == null) { + return + } + let all_y = yRandom.map(item => { + return item * height * 0.08 }) - } - this.ballDataList = dataList; // 触发视图更新 - console.info('onReady ballDataList = ' + JSON.stringify(this.ballDataList)); + let dataList = [] + for (let index = 0; index < this.ballList.length; index++) { + dataList.push({ + content: this.ballList[index] + 'g', + x: all_x[index], + y: all_y[index] + }) + } + this.ballDataList = dataList; // 触发视图更新 + console.info('onReady ballDataList = ' + JSON.stringify(this.ballDataList)); - this.playShakeAnimate() // 开始执行抖动动画 + this.playShakeAnimate() // 开始执行抖动动画 + }, 50) }, onBallClick(index, item) { console.info('onBallClick index = ' + index); console.info('onBallClick item = ' + JSON.stringify(item)); + if (this.isCollect || item.isCollected) { // 正在执行收集动画或者是已经被回收的 + return + } this.$emit('ballClick', item); let el = this.$element(`ball${index}`) this.playCollectionAnimate(el, index) }, -/** + /** * 执行收集的动画 * @param el * @param index @@ -113,24 +125,20 @@ export default { opacity: 0 } ]; - let animation = el.animate(frames, options); let _t = this - animation.onfinish = function () { + _t.collectionAnimation = el.animate(frames, options); + _t.collectionAnimation.onfinish = function () { console.info('onBallClick collection animation onFinish'); _t.isCollect = false; - _t.ballDataList.splice(index, 1); - console.info(JSON.stringify(_t.ballDataList)); - - // 调用splice方法后,原index位置的小球不再执行动画,故手动再创建动画 - if (index <= _t.ballDataList.length) { - setTimeout(() => { - let animate = _t.createShakeAnimate(el) - animate.play() - }, 5) - } + _t.ballDataList[index].isCollected = true + console.info('xwg1: ' + JSON.stringify(_t.ballDataList)); }; + _t.collectionAnimation.oncancel = function () { + console.info('xwg1: collectionAnimation oncancel'); + _t.isCollect = false; + } this.isCollect = true - animation.play() + _t.collectionAnimation.play() }, createShakeAnimate(el) { if (el == undefined) { @@ -176,7 +184,7 @@ export default { } }, 50) }, -/** + /** * 随机指定范围内N个不重复的数 * 最简单最基本的方法 * @@ -209,6 +217,6 @@ export default { }, onBallListChange(newV) { // 外部数据发生变化 重新渲染组件 console.log('onBallListChange newV = ' + JSON.stringify(newV)) - this.onReady() + this.initData() } }