wangzhibo
2026-10-08 220e4fab27b7f419b3e89e2f2d28ae789aac09d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<template>
  <CustomDialog
    :title="title"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    width="600px"
    @close="handleClose"
    @open="handleOpen"
    @cancel="handleCancel"
    @confirm="handleSubmit"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="auto">
      <el-form-item :label="$t('voiceClone.platformName')" prop="modelId">
        <el-select v-model="form.modelId" :placeholder="$t('voiceClone.platformNamePlaceholder')" filterable
          style="width: 100%" @change="handlePlatformChange">
          <el-option v-for="model in platformList" :key="model.id" :label="model.modelName" :value="model.id">
          </el-option>
        </el-select>
      </el-form-item>
 
      <el-form-item :label="$t('voiceClone.voiceId')" prop="voiceIds">
        <el-select v-model="form.voiceIds" :placeholder="$t('voiceClone.voiceIdPlaceholder')" filterable multiple
          allow-create default-first-option style="width: 100%">
          <el-option v-for="voiceId in voiceIdList" :key="voiceId" :label="voiceId" :value="voiceId">
          </el-option>
        </el-select>
      </el-form-item>
 
      <el-form-item :label="$t('voiceClone.userId')" prop="userId">
        <el-select v-model="form.userId" :placeholder="$t('voiceClone.userIdPlaceholder')" filterable remote
          :remote-method="remoteSearchUser" :loading="userLoading" style="width: 100%">
          <el-option v-for="user in userList" :key="user.userid" :label="user.mobile" :value="user.userid">
          </el-option>
        </el-select>
      </el-form-item>
 
      <el-form-item :label="$t('voiceClone.languages')" prop="languages">
        <el-input v-model="form.languages" :placeholder="$t('voiceClone.languagesPlaceholder')" style="width: 100%">
        </el-input>
      </el-form-item>
    </el-form>
  </CustomDialog>
</template>
 
<script>
import Api from '@/apis/api';
import CustomDialog from './CustomDialog.vue';
 
export default {
  name: 'VoiceCloneDialog',
  components: { CustomDialog },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: ''
    },
    form: {
      type: Object,
      default: () => ({})
    }
  },
 
  data() {
    return {
      dialogVisible: this.visible,
      platformList: [],
      voiceIdList: [],
      userList: [],
      userLoading: false,
      rules: {
        modelId: [
          { required: true, message: this.$t('voiceClone.platformNameRequired'), trigger: 'change' }
        ],
        voiceIds: [
          { required: true, message: this.$t('voiceClone.voiceIdRequired'), trigger: 'change' }
        ],
        userId: [
          { required: true, message: this.$t('voiceClone.userIdRequired'), trigger: 'change' }
        ],
        languages: [
          { required: true, message: this.$t('voiceClone.languagesRequired'), trigger: 'blur' }
        ]
      }
    }
  },
 
  watch: {
    visible(val) {
      this.dialogVisible = val;
    },
    dialogVisible(val) {
      this.$emit('update:visible', val);
    }
  },
 
  methods: {
    handleClose() {
      this.dialogVisible = false;
      this.$emit('cancel');
    },
 
    handleCancel() {
      this.$refs.form.clearValidate();
      this.$emit('cancel');
    },
 
    handleSubmit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.$emit('submit', this.form);
        }
      });
    },
 
    handleOpen() {
      // 对话框打开时加载平台列表
      this.fetchPlatformList();
      // 重置音色ID列表
      this.voiceIdList = [];
    },
 
    handlePlatformChange(modelId) {
      // 清空音色ID选择
      this.form.voiceIds = [];
    },
 
    // 获取TTS平台列表
    fetchPlatformList() {
      Api.voiceResource.getTtsPlatformList((res) => {
        if (res.data.code === 0) {
          this.platformList = res.data.data;
        }
      });
    },
 
    // 远程搜索用户
    remoteSearchUser(query) {
      if (query !== '') {
        this.userLoading = true;
        const params = {
          page: 1,
          limit: 20,
          mobile: query
        };
        Api.admin.getUserList(params, (res) => {
          this.userLoading = false;
          if (res.data.code === 0) {
            this.userList = res.data.data.list;
          }
        });
      } else {
        this.userList = [];
      }
    }
  }
}
</script>