index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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" @click="showSTTModel.show = true">
  9. 音转文
  10. </n-button>
  11. </n-space>
  12. </div>
  13. </div>
  14. <!-- <n-scrollbar style="max-height: calc(100vh - 100px)" trigger="none"> -->
  15. <n-data-table
  16. pagination-behavior-on-filter="first"
  17. :columns="columns"
  18. :data="data"
  19. :pagination="paginationReactive"
  20. />
  21. <TtsModel
  22. :show="showTTSModel.show"
  23. :is-editing="showTTSModel.isEditing"
  24. :data="showTTSModel.data"
  25. @close="showTTSModel.show = false"
  26. @submit="noticeTTsModelDone"
  27. ></TtsModel>
  28. <SttModel
  29. :show="showSTTModel.show"
  30. :is-editing="showSTTModel.isEditing"
  31. :data="showSTTModel.data"
  32. @close="showSTTModel.show = false"
  33. @submit="noticeSTTModelDone"
  34. ></SttModel>
  35. </div>
  36. </template>
  37. <script setup lang="ts">
  38. import { h, reactive, onMounted, watchEffect, ref } from 'vue'
  39. import { NButton, NTooltip, useDialog } from 'naive-ui'
  40. import { fetchTtsList, deleteTTS } from '@/api'
  41. import { useMainStore } from '@/store'
  42. import type { TTSItem } from './type'
  43. import TtsModel from './ttsModel.vue'
  44. import SttModel from './sttModel.vue'
  45. defineProps<{ msg: string }>()
  46. const dialog = useDialog()
  47. const main = useMainStore()
  48. const data = ref<TTSItem[]>([])
  49. const showTTSModel = ref({
  50. show: false,
  51. isEditing: false,
  52. data: {}
  53. })
  54. const showSTTModel = ref({
  55. show: false,
  56. isEditing: false,
  57. data: {}
  58. })
  59. const paginationReactive = reactive({
  60. page: 1,
  61. pageSize: 5,
  62. showSizePicker: true,
  63. pageSizes: [3, 5, 7],
  64. onChange: (page) => {
  65. paginationReactive.page = page
  66. },
  67. onUpdatePageSize: (pageSize) => {
  68. paginationReactive.pageSize = pageSize
  69. paginationReactive.page = 1
  70. }
  71. })
  72. onMounted(async () => {
  73. watchEffect(async () => {
  74. if (main.sceneCode) {
  75. await refresh()
  76. }
  77. })
  78. })
  79. const refresh = async () => {
  80. console.warn('refresh')
  81. const res = await fetchTtsList(main.sceneCode)
  82. console.log('data', res)
  83. data.value = res as never as TTSItem[]
  84. }
  85. const columns = [
  86. {
  87. title: '序号',
  88. key: 'id',
  89. width: 70
  90. },
  91. {
  92. title: '类型',
  93. key: 'type',
  94. width: 80,
  95. render(row) {
  96. return row.type === 'asr' ? h('span', '语音') : h('span', '文字')
  97. }
  98. },
  99. {
  100. title: '名称',
  101. key: 'name',
  102. width: 100
  103. },
  104. {
  105. title: '内容',
  106. key: 'document',
  107. width: 500,
  108. resizable: true,
  109. render(row) {
  110. return h(
  111. NTooltip,
  112. { trigger: 'hover', placement: 'top', style: { maxWidth: '500px' } },
  113. {
  114. trigger: () => h('span', row.document.slice(0, 100) + '...'),
  115. default: () => h('span', row.document)
  116. }
  117. )
  118. }
  119. // resizable: true,
  120. },
  121. {
  122. title: '语音文件',
  123. key: 'voicePath',
  124. width: 300,
  125. resizable: true
  126. },
  127. {
  128. title: '状态',
  129. key: 'status',
  130. minWidth: 100,
  131. render(row) {
  132. return row.status == 1
  133. ? h('span', '转换成功')
  134. : row.status == 0
  135. ? h('span', '转换中')
  136. : h('span', '转换失败')
  137. }
  138. },
  139. {
  140. title: '创建时间',
  141. key: 'updateTime'
  142. },
  143. {
  144. title: '操作',
  145. key: 'actions',
  146. fixed: 'right',
  147. minWidth: 200,
  148. render(row, index) {
  149. return [
  150. h(
  151. NButton,
  152. {
  153. quaternary: true,
  154. type: 'info',
  155. size: 'small',
  156. onClick: () => {
  157. openEdit(row)
  158. }
  159. },
  160. {
  161. default: () => '编辑'
  162. }
  163. ),
  164. h(
  165. NButton,
  166. {
  167. quaternary: true,
  168. type: 'error',
  169. size: 'small',
  170. style: { marginLeft: '2px' },
  171. onClick: () => {
  172. handleDelTTS(row.id)
  173. }
  174. },
  175. {
  176. default: () => '删除'
  177. }
  178. )
  179. ]
  180. }
  181. }
  182. ]
  183. const handleAddTTS = () => {
  184. showTTSModel.value.show = true
  185. }
  186. const handleDelTTS = (id: number) => {
  187. console.log('handleDelTTS', id)
  188. dialog.warning({
  189. title: '删除',
  190. content: '是否确定删除?',
  191. negativeText: '取消',
  192. positiveText: '确认',
  193. onPositiveClick: async () => {
  194. await deleteTTS({
  195. id,
  196. num: main.sceneCode
  197. })
  198. await refresh()
  199. }
  200. })
  201. }
  202. const openEdit = (row) => {
  203. console.log('openEdit', row.type)
  204. if (row.type === 'tts') {
  205. showTTSModel.value.show = true
  206. showTTSModel.value.isEditing = true
  207. showTTSModel.value.data = row
  208. } else {
  209. showSTTModel.value.show = true
  210. showSTTModel.value.isEditing = true
  211. showSTTModel.value.data = row
  212. }
  213. }
  214. const noticeTTsModelDone = async () => {
  215. await refresh()
  216. showTTSModel.value.show = false
  217. location.reload()
  218. }
  219. const noticeSTTModelDone = async () => {
  220. await refresh()
  221. showSTTModel.value.show = false
  222. location.reload()
  223. }
  224. </script>
  225. <style lang="sass" scoped>
  226. a
  227. color: #42b983
  228. label
  229. margin: 0 0.5em
  230. font-weight: bold
  231. code
  232. background-color: #eee
  233. padding: 2px 4px
  234. border-radius: 4px
  235. color: #304455
  236. .textToaudio
  237. min-height: 100%
  238. //border-left: 1px solid
  239. </style>