index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. const tips_language = language[0]
  10. let modalItems = [
  11. {
  12. type: 'copySource',
  13. text: tips_language.copy_source_text
  14. },
  15. {
  16. type: 'delete',
  17. text: tips_language.delete_item
  18. },
  19. {
  20. type: 'copyTarget',
  21. text: tips_language.copy_target_text
  22. },
  23. ]
  24. Component({
  25. properties: {
  26. item: {
  27. type: Object,
  28. value: {},
  29. },
  30. modalShow: {
  31. type: Boolean,
  32. value: true,
  33. },
  34. index: {
  35. type: Number,
  36. },
  37. },
  38. data: {
  39. // tips_language: language[0], // 目前只有中文
  40. modalItems: modalItems,
  41. },
  42. ready: function () {
  43. },
  44. methods: {
  45. deleteBubbleModal: function() {
  46. this.triggerEvent('modaldelete', {
  47. item: this.data.item,
  48. index: this.data.index,
  49. },{ bubbles: true, composed: true })
  50. this.leaveBubbleModal()
  51. },
  52. /**
  53. * 点击
  54. */
  55. itemTap: function(e) {
  56. let itemType = e.currentTarget.dataset.type
  57. let item = this.data.item
  58. switch(itemType) {
  59. case 'copySource':
  60. this.setClip(item.text)
  61. break;
  62. case 'copyTarget':
  63. this.setClip(item.translateText)
  64. break
  65. case 'delete':
  66. this.deleteBubbleModal()
  67. break
  68. default:
  69. break
  70. }
  71. },
  72. /**
  73. * 复制到剪贴板
  74. *
  75. * @param {string} text 需要复制到剪贴板的文字
  76. */
  77. setClip: function(text) {
  78. wx.setClipboardData({
  79. data: text,
  80. success: (res) => {
  81. this.leaveBubbleModal()
  82. wx.showToast({
  83. title: "已复制到剪切板",
  84. icon: "success",
  85. duration: 1000,
  86. success: function (res) {
  87. console.log("show succ");
  88. },
  89. fail: function (res) {
  90. console.log(res);
  91. }
  92. });
  93. }
  94. })
  95. },
  96. leaveBubbleModal: function() {
  97. this.triggerEvent('modalleave', {
  98. modalShow: this.data.modalShow
  99. })
  100. },
  101. }
  102. });