|
@@ -1,8 +1,8 @@
|
|
|
<template>
|
|
|
<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
|
|
|
- <cus-header title='创建角色' bgColor="transparent"></cus-header>
|
|
|
+ <cus-header :title='title' bgColor="transparent"></cus-header>
|
|
|
<div class="box">
|
|
|
- <div class="title adfac">角色形象<span>*</span></div>
|
|
|
+ <div class="title adfac">角色形象</div>
|
|
|
<div class="upload">
|
|
|
<div class="sc">
|
|
|
<u-upload width="188rpx" height="188rpx"
|
|
@@ -22,7 +22,7 @@
|
|
|
</div>
|
|
|
<div class="box adfacjb">
|
|
|
<div class="title">角色昵称<span>*</span></div>
|
|
|
- <input type="text" placeholder="请输入角色昵称" placeholder-class="ph">
|
|
|
+ <input type="text" v-model="agentDto.agentName" placeholder="请输入角色昵称" placeholder-class="ph">
|
|
|
</div>
|
|
|
<div class="box adfacjb" @tap="selectModel">
|
|
|
<div class="title">角色模板<span>*</span></div>
|
|
@@ -36,16 +36,16 @@
|
|
|
<div class="title">设备描述</div>
|
|
|
<div class="tip">回显不可编辑</div>
|
|
|
</div>
|
|
|
- <div class="desc">{{''}}</div>
|
|
|
+ <div class="desc">{{deviceMemo||''}}</div>
|
|
|
</div>
|
|
|
<div class="box adfacjb">
|
|
|
<div class="title">音色<span>*</span></div>
|
|
|
- <div class="right adfac">
|
|
|
+ <div class="right adfac" @tap="show=true">
|
|
|
<div class="mtext" :class="{'active':voiceText!=='请选择音色'}">{{voiceText}}</div>
|
|
|
<image src="http://106.54.209.120:8188/static/arrow_right.png"></image>
|
|
|
</div>
|
|
|
</div>
|
|
|
- <div class="zt_btn">创建角色</div>
|
|
|
+ <div class="zt_btn" @tap="comfirmSure">{{agentId?'编辑角色':'创建角色'}}</div>
|
|
|
<u-picker :itemHeight="88" title="角色音色" :show="show" :columns="voiceList" keyName="name"
|
|
|
@cancel="show=false" @confirm="confirm" :immediateChange="true" style="height: 500rpx;">
|
|
|
</u-picker>
|
|
@@ -57,20 +57,39 @@
|
|
|
export default {
|
|
|
data(){
|
|
|
return {
|
|
|
+ title:'创建角色',
|
|
|
modelText:'请选择角色模版',
|
|
|
voiceText:'请选择音色',
|
|
|
fileList:[],
|
|
|
show:false,
|
|
|
voiceList:[],
|
|
|
+ deviceMemo:'',
|
|
|
modelMap:new Map(),
|
|
|
+ agentId:'',
|
|
|
+ deviceId:'',
|
|
|
agentDto:{
|
|
|
-
|
|
|
+ "agentName": "",
|
|
|
+ "asrModelId": "",
|
|
|
+ "vadModelId": "",
|
|
|
+ "llmModelId": "",
|
|
|
+ "ttsModelId": "",
|
|
|
+ "ttsVoiceId": "",
|
|
|
+ "memModelId": "",
|
|
|
+ "intentModelId": "",
|
|
|
+ "systemPrompt": "",
|
|
|
+ "langCode": "",
|
|
|
+ "language": "",
|
|
|
+ "deviceId": ""
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- async onLoad() {
|
|
|
- await this.getAgentModelList()
|
|
|
- this.getModelVoiceList()
|
|
|
+ onLoad(option) {
|
|
|
+ if(option.agentId){
|
|
|
+ this.title = '编辑角色';
|
|
|
+ this.agentId = option.agentId;
|
|
|
+ this.deviceId = option.deviceId;
|
|
|
+ this.getDetail();
|
|
|
+ }
|
|
|
},
|
|
|
methods:{
|
|
|
// 删除图片
|
|
@@ -106,8 +125,8 @@
|
|
|
},
|
|
|
uploadFilePromise(url) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- let a = uni.uploadFile({
|
|
|
- url: baseApi.BaseApi + '/uploadFile',
|
|
|
+ uni.uploadFile({
|
|
|
+ url: baseApi.BaseApi + '/sys/oss/uploadFile',
|
|
|
filePath: url,
|
|
|
name: "file",
|
|
|
success: (res) => {
|
|
@@ -122,38 +141,19 @@
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
- changeModel(item,index){
|
|
|
- this.midx = index;
|
|
|
- this.agentDto = this.modelMap.get(item.agentName);
|
|
|
- this.getModelVoiceList()
|
|
|
- },
|
|
|
selectModel(){
|
|
|
uni.navigateTo({
|
|
|
url:'/pagesRole/roleModel',
|
|
|
events:{
|
|
|
selectRoleModel:data=>{
|
|
|
- console.log(data,'data');
|
|
|
+ this.agentDto = {...this.agentDto,...data};
|
|
|
+ this.modelText = data.agentName||'';
|
|
|
+ this.deviceMemo = data.systemPrompt||'';
|
|
|
+ this.getModelVoiceList();
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- getAgentModelList(){
|
|
|
- return new Promise((resolve,reject)=>{
|
|
|
- this.$api.get('/agent/template').then(res=>{
|
|
|
- if(res.data.code!==0) return this.$showToast(res.data.msg)
|
|
|
- this.list = res.data.data;
|
|
|
- if(this.list.length){
|
|
|
- this.agentDto = {...this.agentDto,...this.list[0]}
|
|
|
- let map = new Map();
|
|
|
- this.list.forEach(l=>{
|
|
|
- map.set(l.agentName,l)
|
|
|
- })
|
|
|
- this.modelMap = map;
|
|
|
- }
|
|
|
- resolve();
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
getModelVoiceList(){
|
|
|
this.$api.get(`/models/${this.agentDto.ttsModelId}/voices`).then(res=>{
|
|
|
if(res.data.code!==0) return this.$showToast(res.data.msg)
|
|
@@ -167,17 +167,38 @@
|
|
|
this.voiceText = e.value[0].name;
|
|
|
},
|
|
|
comfirmSure(){
|
|
|
+ if(!this.agentDto.agentName) return this.$showToast('请输入角色昵称')
|
|
|
+ if(this.agentDto.modelText==='请选择角色模版') return this.$showToast('请选择角色模板')
|
|
|
+ if(this.agentDto.voiceText==='请选择音色') return this.$showToast('请选择音色')
|
|
|
+
|
|
|
let dto = JSON.parse(JSON.stringify(this.agentDto));
|
|
|
- this.$api.post('/agent',dto).then(res=>{
|
|
|
+ if(this.agentId) dto.deviceId = this.deviceId;
|
|
|
+ this.$api.post(this.agentId?`/agent/update/${this.agentId}`:'/agent',dto).then(res=>{
|
|
|
if(res.data.code!==0) return this.$showToast(res.data.msg)
|
|
|
- this.$showToast('创建成功');
|
|
|
+ this.$showToast(this.agentId?'编辑成功':'创建成功');
|
|
|
setTimeout(()=>{
|
|
|
- uni.reLaunch({
|
|
|
- url:'/pages/home'
|
|
|
- })
|
|
|
+ let url = this.agentId?'/pages/home':'/pages/role'
|
|
|
+ uni.reLaunch({ url })
|
|
|
},1500)
|
|
|
})
|
|
|
},
|
|
|
+ getDetail(){
|
|
|
+ this.$api.get(`/agent/${this.agentId}`).then(res=>{
|
|
|
+ if(res.data.code!==0) return this.$showToast(res.data.msg)
|
|
|
+ this.agentDto = {...this.agentDto,...res.data.data};
|
|
|
+ this.deviceMemo = this.agentDto.systemPrompt;
|
|
|
+ this.getModelVoiceList();
|
|
|
+ this.getAgentModelList();
|
|
|
+ })
|
|
|
+ },
|
|
|
+ getAgentModelList(){
|
|
|
+ this.$api.get('/agent/template').then(res=>{
|
|
|
+ if(res.data.code!==0) return this.$showToast(res.data.msg)
|
|
|
+ if(res.data.data.length){
|
|
|
+ this.modelText = res.data.data.find(d=>d.systemPrompt===this.agentDto.systemPrompt)?.agentName;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
@@ -194,6 +215,7 @@
|
|
|
.page{
|
|
|
background: #F7F6F9;
|
|
|
padding: 0 30rpx 30rpx;
|
|
|
+ box-sizing: border-box;
|
|
|
.box{
|
|
|
background: #FFFFFF;
|
|
|
border-radius: 24rpx;
|