sheldon 2 месяцев назад
Родитель
Сommit
3e4355712c

+ 7 - 0
src/api/modules/voice.ts

@@ -32,3 +32,10 @@ export function voiceList(params: {
     content: TVoice[]
   }>(`/voice/select`, params)
 }
+
+// 激活声音
+export function activeVoice(params: {
+  id: string,
+}){
+  return request(`/anycall/activeVoice`, params)
+}

+ 7 - 2
src/views/voice-management/components/EditClone.vue

@@ -34,10 +34,11 @@ const dialogVisible = computed({
 // 表单引用
 const editFormRef = ref<FormInstance>();
 const cloneLoading = ref(false)
-const formData = ref<{gender: number, voiceName: string, audioUrl: string}>({
+const formData = ref<{gender: number, voiceName: string, audioUrl: string, feature: string}>({
   gender: 1,
   voiceName: '',
   audioUrl: '',
+  feature: '',
 });
 
 // 表单验证规则
@@ -111,6 +112,7 @@ function resetForm() {
     audioUrl: '',
     voiceName: '',
     gender: 1,
+    feature: '',
   }
 }
 
@@ -125,7 +127,10 @@ function resetForm() {
         </ElFormItem>
 
         <ElFormItem label="voice name" prop="voiceName" label-width="120">
-           <ElInput v-model="formData.voiceName" :disabled="!formData.audioUrl.length" placeholder="Enter name"  />
+           <ElInput v-model="formData.voiceName" :disabled="!formData.audioUrl.length" placeholder="Enter voice name"  />
+        </ElFormItem>
+        <ElFormItem label="feature" prop="feature" label-width="120">
+           <ElInput type="textarea" v-model="formData.feature" :disabled="!formData.audioUrl.length" placeholder="Enter feature"  />
         </ElFormItem>
         <ElFormItem label="gender" prop="gender" label-width="120">
         <ElSelect v-model="formData.gender" placeholder="选择性别" style="width: 120px; margin-bottom: 20px;">

+ 38 - 25
src/views/voice-management/index.vue

@@ -12,7 +12,7 @@ import EditClone from './components/EditClone.vue'
 
 import type { TVoice } from '@/types/voice'
 import { toast } from 'vue-sonner'
-import { voiceList, cloneVoice } from '@/api/modules/voice'
+import { voiceList, activeVoice } from '@/api/modules/voice'
 import { formatDateGeneral } from '@/utils'
 
 const tableRef = ref()
@@ -139,30 +139,6 @@ watch(
   { deep: true }
 )
 
-const handleUploadSuccess = (res: { code: number, data: { src: string, srcName: string, duration: number } }, file: any) => {
-  console.log(res, file)
-  if (res.code === 0) {
-
-    currentAudio.value = res.data
-    handleClone(res.data)
-
-  }
-}
-
-const handleClone = async (res:  { src: string, srcName: string, duration: number }) => {
-  cloneLoading.value = true
-  const {code, data} =  await cloneVoice({
-    name: res.srcName,
-    audioUrl: res.src,
-    gender: 1
-  })
-  cloneLoading.value = false
-  console.log(code, data)
-  if(code === 0){
-    toast.success('克隆成功')
-    fetchData()
-  }
-}
 
 const handleEdit = (data: TVoice) => {
   editMode.value = 'edit'
@@ -176,6 +152,23 @@ const handleEdit = (data: TVoice) => {
   editFormVisible.value = true
 }
 
+const switchLoading = ref(false)
+const handleActive = async (id: string) => {
+  switchLoading.value = true
+  try {
+    const { code } = await activeVoice({ id })
+    if(code === 0){
+      toast.success('激活成功')
+      fetchData()
+    }
+    switchLoading.value = false
+  } catch (error) {
+    switchLoading.value = false
+    return
+  }
+}
+
+
 onMounted(async () => {
   updateUrlParams(pagination.value.page, pagination.value.size)
   await fetchData()
@@ -214,6 +207,26 @@ onMounted(async () => {
         </ElTableColumn>
 
         <ElTableColumn label="feature" prop="feature" width="280" />
+        <ElTableColumn label="激活状态" prop="status" width="120">
+          <template #default="{row}">
+            <ElTag type="success" v-if="row.status === 5">
+              已激活
+            </ElTag>
+            <ElButton v-else-if="row.status === 3"  @click="() => handleActive(row.voiceId)" :disabled="switchLoading">
+              激活
+            </ElButton>
+            <div v-else>...</div>
+            <!-- <ElSwitch
+              v-model="row.status"
+              :active-value="5"
+              :inactive-value="3"
+              :disabled="switchLoading"
+              @click="() => handleActive(row.voiceId)"
+            />
+              待激活
+            </div> -->
+          </template>
+        </ElTableColumn>
         <ElTableColumn label="create time" prop="ctime" width="280">
           <template #default="{row}">
             {{ formatDateGeneral(row.ctime) }}