textComponent.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div class="name-textBox">
  3. <div class="name-textBox-left">
  4. <div class="name-selectBox">
  5. <div>
  6. <n-space vertical>
  7. <n-select v-model:value="sourceLanguage" :options="options" />
  8. </n-space>
  9. </div>
  10. <div>
  11. <n-space vertical>
  12. <n-select v-model:value="targetLanguage" :options="options1" />
  13. </n-space>
  14. </div>
  15. <div style="display: flex; align-items: center;">
  16. <n-space vertical>
  17. <n-select v-model:value="model" :options="modelListData" value-field="modelDescribe"
  18. label-field="modelName" />
  19. </n-space>
  20. </div>
  21. <n-button @click="handleTranslation" type="primary">翻译</n-button>
  22. </div>
  23. <n-input v-model:value="prompt" type="textarea" placeholder="请输入文本" :resizable="false" />
  24. </div>
  25. <div class="name-textBox-right">
  26. <div class="name-textBox-right-content">
  27. {{ translationResult }}
  28. </div>
  29. </div>
  30. </div>
  31. </template>
  32. <script setup>
  33. import { ref, onMounted } from 'vue'
  34. import { NInput, NSelect, NButton } from 'naive-ui'
  35. import { modelList } from '@/api/model'
  36. import { translation } from '@/api/fanyi'
  37. const modelListData = ref([])
  38. const prompt = ref('')
  39. const sourceLanguage = ref('英文')
  40. const targetLanguage = ref('中文')
  41. const translationResult = ref('')
  42. const model = ref('')
  43. const options = ref([
  44. // { label: '自动设别', value: '' },
  45. { label: '中文', value: '中文' },
  46. { label: '英文', value: '英文' },
  47. ])
  48. const options1 = ref([
  49. { label: '中文', value: '中文' },
  50. { label: '英文', value: '英文' },
  51. ])
  52. onMounted(() => {
  53. getModelList()
  54. })
  55. async function getModelList() {
  56. const res = await modelList()
  57. modelListData.value = res.data
  58. model.value = modelListData.value[0].modelDescribe
  59. }
  60. async function handleTranslation() {
  61. if (!prompt.value) {
  62. return;
  63. }
  64. const res = await translation({
  65. prompt: prompt.value,
  66. sourceLanguage: sourceLanguage.value,
  67. targetLanguage: targetLanguage.value,
  68. model: model.value,
  69. })
  70. translationResult.value = res
  71. }
  72. </script>
  73. <style scoped lang="less">
  74. .name-textBox {
  75. display: flex;
  76. :deep(.n-input) {
  77. .n-input__border,
  78. .n-input__state-border {
  79. border: none !important;
  80. }
  81. textarea {
  82. min-height: 500px !important;
  83. }
  84. }
  85. .name-textBox-left {
  86. flex: 1;
  87. height: calc(100vh - 100px);
  88. border-radius: 10px;
  89. padding: 10px;
  90. .name-selectBox {
  91. display: flex;
  92. justify-content: space-between;
  93. margin-bottom: 10px;
  94. div {
  95. flex: 1;
  96. }
  97. }
  98. }
  99. .name-textBox-right {
  100. flex: 1;
  101. min-height: 500px;
  102. border-radius: 10px;
  103. padding: 10px;
  104. .name-selectBox {
  105. margin-bottom: 10px;
  106. }
  107. .name-textBox-right-content {
  108. min-height: 500px;
  109. border: 1px solid #ccc;
  110. border-radius: 10px;
  111. padding: 10px;
  112. margin-top: 40px;
  113. }
  114. }
  115. div {
  116. margin-right: 20px;
  117. }
  118. }
  119. </style>