index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. Tencent is pleased to support the open source community by making Face-2-Face Translator available.
  3. Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
  4. Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
  5. http://opensource.org/licenses/MIT
  6. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  7. */
  8. const loadingIcon = '../../image/loading.gif'
  9. Component({
  10. properties: {
  11. playType: {
  12. type: String,
  13. value: 'wait',
  14. observer: function(newVal, oldVal){
  15. if(oldVal == 'loading' && newVal == 'playing') {
  16. let loadingTransitionTime = 1240;
  17. let nowTime = + new Date()
  18. let loadingStartTime = this.data.loadingStartTime
  19. let loadingTime = nowTime - loadingStartTime
  20. let loadingCount = parseInt(loadingTime / loadingTransitionTime); // 完整播放次数
  21. let timeLeft = loadingTransitionTime - loadingTime % loadingTransitionTime; // 剩余播放时间
  22. if(loadingCount > 0 && timeLeft > 1000) {
  23. this.setData({
  24. realPlayType: newVal,
  25. loadingImg: '',
  26. })
  27. } else {
  28. setTimeout( ()=>{
  29. this.setData({
  30. realPlayType: newVal,
  31. })
  32. }, timeLeft)
  33. }
  34. } else if (newVal == 'loading'){
  35. this.setData({
  36. loadingStartTime: + new Date(),
  37. realPlayType: newVal,
  38. })
  39. } else {
  40. this.setData({
  41. realPlayType: newVal,
  42. })
  43. }
  44. },
  45. }
  46. },
  47. data: {
  48. realPlayType: 'wait', // 真正wxml中使用的type变量
  49. loadingStartTime: 0,
  50. },
  51. ready: function () {
  52. },
  53. // 组件生命周期函数,在组件实例被从页面节点树移除时执行
  54. detached: function() {
  55. },
  56. methods: {
  57. }
  58. });