index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. import { language } from '../../utils/conf.js'
  9. let buttons = []
  10. // 按钮配置
  11. language.forEach(item=>{
  12. buttons.push({
  13. buttonText: item.lang_name,
  14. lang: item.lang_content,
  15. lto: item.lang_to[0],
  16. msg: item.hold_talk,
  17. buttonType: 'normal',
  18. })
  19. })
  20. // 按钮对应图片
  21. let buttonBackground = {
  22. zh_CN: {
  23. normal: '../../image/button_zh.png',
  24. press: '../../image/button_zh_press.png',
  25. disabled: '../../image/button_zh_disabled.png',
  26. },
  27. en_US: {
  28. normal: '../../image/button_en.png',
  29. press: '../../image/button_en_press.png',
  30. disabled: '../../image/button_en_disabled.png',
  31. }
  32. }
  33. Component({
  34. properties: {
  35. buttonDisabled: {
  36. type: Boolean,
  37. value: false,
  38. observer: function(newVal, oldVal){
  39. let buttonType = newVal ? 'disabled' : 'normal'
  40. this.changeButtonType(buttonType)
  41. }
  42. },
  43. shadowShow: {
  44. type: Boolean,
  45. value: false,
  46. },
  47. },
  48. data: {
  49. buttons: buttons,
  50. buttonBackground: buttonBackground,
  51. currentButtonType: 'normal',
  52. },
  53. ready: function () {
  54. // console.log(this.data.buttonEvent,)
  55. },
  56. methods: {
  57. /**
  58. * 按下按钮开始录音
  59. */
  60. streamRecord(e) {
  61. if(this.data.buttonDisabled) {
  62. return
  63. }
  64. // 先清空背景音
  65. wx.stopBackgroundAudio()
  66. let currentButtonConf = e.currentTarget.dataset.conf
  67. this.changeButtonType('press', currentButtonConf.lang)
  68. this.triggerEvent('recordstart', {
  69. buttonItem: currentButtonConf
  70. })
  71. },
  72. /**
  73. * 松开按钮结束录音
  74. */
  75. endStreamRecord(e) {
  76. let currentButtonConf = e.currentTarget.dataset.conf
  77. console.log("currentButtonConf", currentButtonConf)
  78. this.triggerEvent('recordend', {
  79. buttonItem: currentButtonConf
  80. })
  81. },
  82. /**
  83. * 修改按钮样式
  84. */
  85. changeButtonType(buttonType, buttonLang) {
  86. let tmpButtons = this.data.buttons.slice(0)
  87. tmpButtons.forEach(button => {
  88. if(!buttonLang || buttonLang == button.lang) {
  89. button.buttonType = buttonType
  90. }
  91. })
  92. this.setData({
  93. buttons: tmpButtons
  94. })
  95. },
  96. }
  97. });