index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <!-- 基础设置页面 class="pointer-events-auto"-->
  3. <div>
  4. <n-drawer
  5. v-model:show="active"
  6. :width="240"
  7. placement="right"
  8. :trap-focus="false"
  9. :block-scroll="false"
  10. :show-mask="false"
  11. :mask-closable="false"
  12. to="#drawer-target"
  13. style="--n-body-padding: 0px"
  14. >
  15. <n-drawer-content title="数字人播报">
  16. <div class="drawerContent m-5">
  17. <!-- <div class="text-lg my-2.5">数字人播报</div>-->
  18. <n-list
  19. v-if="list"
  20. style="--n-color-modal: none"
  21. :show-divider="false"
  22. >
  23. <!-- {{list}}-->
  24. <n-list-item
  25. v-for="(vi, index) in list"
  26. :key="index"
  27. style="width: 100%"
  28. >
  29. <div class="mb-5">
  30. {{ `当前空间${vi.media ? '视频' : '模型'}` }} ID: {{ vi.sid }}
  31. </div>
  32. <n-select
  33. v-model:value="vi.audioId"
  34. :options="audioOptions"
  35. :placeholder="'请绑定对应音频'"
  36. @update:value="(val) => handleSelect(val, vi.sid)"
  37. ></n-select>
  38. </n-list-item>
  39. </n-list>
  40. </div>
  41. </n-drawer-content>
  42. </n-drawer>
  43. </div>
  44. </template>
  45. <script setup lang="ts">
  46. import {
  47. ref,
  48. computed,
  49. onMounted,
  50. // reactive,
  51. onUnmounted,
  52. watchEffect,
  53. watch
  54. } from 'vue'
  55. import { useMainStore } from '@/store'
  56. import { NList, NListItem } from 'naive-ui'
  57. import { fetchTtsList, SaveTOTTSParams } from '@/api'
  58. defineProps<{ msg: string }>()
  59. const main = useMainStore()
  60. const active = ref(true)
  61. const boxVideos = computed(() => main.sceneInfo.boxVideos)
  62. const boxModels = computed(() => main.sceneInfo.boxModels)
  63. const aiData = computed(() => main.getEditorData.aiSetting)
  64. const list = ref<
  65. { sid: string; audioFilePath: string; audioId: string; media: any }[]
  66. >([])
  67. const audiolist = ref<any[]>([])
  68. const audioOptions = ref<any[]>([])
  69. onMounted(async () => {
  70. active.value = true
  71. const res = await fetchTtsList(main.sceneCode)
  72. if (res) {
  73. const result = Array.from(res as any as SaveTOTTSParams[]).filter(
  74. (i) => i.type === 'tts'
  75. )
  76. audiolist.value = result
  77. const arr = result.map((item) => {
  78. return {
  79. label: item.name,
  80. value: item.id
  81. }
  82. })
  83. console.log('array', arr)
  84. audioOptions.value = arr
  85. }
  86. watchEffect(() => {
  87. if (boxVideos.value?.length || boxModels.value?.length) {
  88. // debugger
  89. const videoData = JSON.parse(boxVideos.value)
  90. const boxData = JSON.parse(boxModels.value)
  91. console.log('boxVideos', videoData)
  92. if (videoData && aiData.value.length === 0) {
  93. list.value = list.value.concat(
  94. videoData.map((item) => {
  95. return {
  96. ...item,
  97. audioId: null,
  98. audioFilePath: null
  99. }
  100. })
  101. )
  102. }
  103. if (videoData && aiData.value.length === 0) {
  104. list.value = list.value.concat(
  105. boxData.map((item) => {
  106. return {
  107. ...item,
  108. audioId: null,
  109. audioFilePath: null
  110. }
  111. })
  112. )
  113. }
  114. }
  115. })
  116. })
  117. watchEffect(() => {
  118. if (aiData.value.length > 0) {
  119. list.value = aiData.value
  120. }
  121. })
  122. onUnmounted(() => {
  123. // setWidthSceneRef(0)
  124. })
  125. const handleSelect = (audioId: any, vid: any) => {
  126. const file = audiolist.value.find((i) => i.id === audioId)
  127. const models = Array.from(list.value.flat() || []).find((i) => i.sid === vid)
  128. const fileName = file.voicePath.substring(file.voicePath.lastIndexOf('/') + 1)
  129. if (file.voicePath?.length && models) {
  130. // debugger
  131. models.audioFilePath = fileName
  132. console.log('models', models)
  133. main.syncAISetting(list.value)
  134. }
  135. }
  136. </script>
  137. <style lang="sass" scoped>
  138. .list
  139. .listItem
  140. div
  141. display: flex
  142. justify-content: space-between
  143. </style>