index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <div class="textToaudio p-4">
  3. <div class="tablehader flex justify-between items-center mb-2.5 text-wrap">
  4. <div class="title">文字语音互转</div>
  5. <div class="bottomList">
  6. <n-space>
  7. <n-button type="primary" @click="handleAddTTS"> 音转文</n-button>
  8. <n-button type="primary"> 文转音</n-button>
  9. </n-space>
  10. </div>
  11. </div>
  12. <!-- <n-scrollbar style="max-height: calc(100vh - 100px)" trigger="none"> -->
  13. <n-data-table
  14. pagination-behavior-on-filter="first"
  15. :columns="columns"
  16. :data="data"
  17. :pagination="paginationReactive"
  18. />
  19. <TtsModel
  20. :show="showTTSModel.show"
  21. @close="showTTSModel.show = false"
  22. ></TtsModel>
  23. </div>
  24. </template>
  25. <script setup lang="ts">
  26. import { h, reactive, onMounted, watchEffect, ref } from 'vue'
  27. import { NButton, NTooltip } from 'naive-ui'
  28. import { fetchTtsList } from '@/api'
  29. import { useMainStore } from '@/store'
  30. import type { TTSItem } from './type'
  31. import TtsModel from './ttsModel.vue'
  32. defineProps<{ msg: string }>()
  33. const main = useMainStore()
  34. const data = ref<TTSItem[]>([])
  35. const showTTSModel = ref({
  36. show: false,
  37. isEditing: false,
  38. data: {}
  39. })
  40. const paginationReactive = reactive({
  41. page: 1,
  42. pageSize: 5,
  43. showSizePicker: true,
  44. pageSizes: [3, 5, 7],
  45. onChange: (page) => {
  46. paginationReactive.page = page
  47. },
  48. onUpdatePageSize: (pageSize) => {
  49. paginationReactive.pageSize = pageSize
  50. paginationReactive.page = 1
  51. }
  52. })
  53. onMounted(async () => {
  54. watchEffect(async () => {
  55. if (main.sceneCode) {
  56. const res = await fetchTtsList(main.sceneCode)
  57. console.log('data', res)
  58. data.value = res as never as TTSItem[]
  59. }
  60. })
  61. })
  62. const columns = [
  63. {
  64. title: '序号',
  65. key: 'id',
  66. width: 70
  67. },
  68. {
  69. title: '类型',
  70. key: 'type',
  71. width: 80,
  72. render(row) {
  73. return row.type === 'asr' ? h('span', '语音') : h('span', '文字')
  74. }
  75. },
  76. {
  77. title: '内容',
  78. key: 'document',
  79. width: 500,
  80. resizable: true,
  81. render(row) {
  82. return h(
  83. NTooltip,
  84. { trigger: 'hover', placement: 'top', style: { maxWidth: '500px' } },
  85. {
  86. trigger: () => h('span', row.document.slice(0, 100) + '...'),
  87. default: () => h('span', row.document)
  88. }
  89. )
  90. }
  91. // resizable: true,
  92. },
  93. {
  94. title: '语音文件',
  95. key: 'voicePath',
  96. width: 300,
  97. resizable: true
  98. },
  99. {
  100. title: '状态',
  101. key: 'status',
  102. minWidth: 100,
  103. render(row) {
  104. return row.status == 1
  105. ? h('span', '转换成功')
  106. : row.status == 0
  107. ? h('span', '转换中')
  108. : h('span', '转换失败')
  109. }
  110. },
  111. {
  112. title: '创建时间',
  113. key: 'updateTime'
  114. },
  115. {
  116. title: '操作',
  117. key: 'actions',
  118. fixed: 'right',
  119. minWidth: 200,
  120. render(row, index) {
  121. return [
  122. h(
  123. NButton,
  124. {
  125. quaternary: true,
  126. type: 'info',
  127. size: 'small',
  128. onClick: () => {
  129. openEdit(row)
  130. }
  131. },
  132. {
  133. default: () => '编辑'
  134. }
  135. ),
  136. h(
  137. NButton,
  138. {
  139. quaternary: true,
  140. type: 'error',
  141. size: 'small',
  142. style: { marginLeft: '2px' },
  143. onClick: () => {
  144. // _doDelete(row.id)
  145. }
  146. },
  147. {
  148. default: () => '删除'
  149. }
  150. )
  151. ]
  152. }
  153. }
  154. ]
  155. const handleAddTTS = () => {
  156. showTTSModel.value.show = true
  157. }
  158. const openEdit = () => {}
  159. </script>
  160. <style lang="sass" scoped>
  161. a
  162. color: #42b983
  163. label
  164. margin: 0 0.5em
  165. font-weight: bold
  166. code
  167. background-color: #eee
  168. padding: 2px 4px
  169. border-radius: 4px
  170. color: #304455
  171. .textToaudio
  172. min-height: 100%
  173. border-left: 1px solid
  174. </style>