translate.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <div>
  3. <el-dialog title="翻译" v-draggable :visible.sync="visible" width="600px" custom-class="checkFile"
  4. :before-close="cancel" :modal="false" :close-on-click-modal="false" :modal-append-to-body="false">
  5. <div class="content">
  6. <div class="left">
  7. <div class="title">原文</div>
  8. <div v-html="content" class="left_content"></div>
  9. </div>
  10. <div class="right">
  11. <div class="title">译文</div>
  12. <div v-html="contentOut" class="right_content"></div>
  13. </div>
  14. </div>
  15. <div slot="footer" class="dialog-footer">
  16. <el-button @click="cancel">关 闭</el-button>
  17. </div>
  18. </el-dialog>
  19. </div>
  20. </template>
  21. <script>
  22. import { mapGetters } from 'vuex'
  23. export default {
  24. components: {},
  25. props: {},
  26. data() {
  27. return {
  28. visible:false,
  29. content:'',
  30. contentOut:''
  31. };
  32. },
  33. watch: {},
  34. computed: {
  35. ...mapGetters([ 'contextMenu']),
  36. },
  37. created() {},
  38. mounted() {},
  39. methods: {
  40. open(){
  41. let mark = this.contextMenu.mark
  42. var content = mark.id ? mark.markSelectText : mark.text
  43. if(this.content.trim() != content.trim()){
  44. this.content = content
  45. this.contentOut = ''
  46. this.getTranslateByText()
  47. }
  48. this.visible = true
  49. },
  50. cancel(){
  51. this.visible = false
  52. },
  53. //翻译
  54. getTranslateByText(){
  55. var params = {
  56. content:this.content
  57. }
  58. this.$api.getTranslateByText(params).then(res=>{
  59. if(res.code == 200){
  60. this.contentOut = res.data.translationContent
  61. }
  62. })
  63. }
  64. },
  65. };
  66. </script>
  67. <style lang="scss" scoped>
  68. .content{
  69. display: flex;
  70. align-items: stretch;
  71. height:calc(100vh - 320px);
  72. }
  73. .left,.right{
  74. width:100%;
  75. height: 100%;
  76. }
  77. .right_content,.left_content{
  78. padding: 10px;
  79. height: calc(100% - 40px);
  80. overflow: auto;
  81. }
  82. .right{
  83. background: #f8f8fb;
  84. }
  85. .title{
  86. border-bottom: 1px solid #e8e9f4;
  87. font-weight: bold;
  88. padding: 10px 5px;
  89. }
  90. </style>