123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- <template>
- <view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
- <cus-header title='创建角色' bgColor="transparent"></cus-header>
- <div class="box">
- <div class="title adfac">角色形象<span>*</span></div>
- <div class="upload">
- <div class="sc">
- <u-upload width="188rpx" height="188rpx"
- :fileList="fileList"
- @afterRead="afterRead"
- @delete="deletePic"
- :maxCount="1"
- >
- <div class="imgs">
- <image class="img1" src="http://106.54.209.120:8188/static/role_upload.png"></image>
- <image class="img2" src="http://106.54.209.120:8188/static/upload_add.png"></image>
- </div>
- </u-upload>
- </div>
- <div class="text">上传角色形象</div>
- </div>
- </div>
- <div class="box adfacjb">
- <div class="title">角色昵称<span>*</span></div>
- <input type="text" placeholder="请输入角色昵称" placeholder-class="ph">
- </div>
- <div class="box adfacjb" @tap="selectModel">
- <div class="title">角色模板<span>*</span></div>
- <div class="right adfac">
- <div class="mtext" :class="{'active':modelText!=='请选择角色模版'}">{{modelText}}</div>
- <image src="http://106.54.209.120:8188/static/arrow_right.png"></image>
- </div>
- </div>
- <div class="box">
- <div class="top adfacjb">
- <div class="title">设备描述</div>
- <div class="tip">回显不可编辑</div>
- </div>
- <div class="desc">{{''}}</div>
- </div>
- <div class="box adfacjb">
- <div class="title">音色<span>*</span></div>
- <div class="right adfac">
- <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>
- <u-picker :itemHeight="88" title="角色音色" :show="show" :columns="voiceList" keyName="name"
- @cancel="show=false" @confirm="confirm" :immediateChange="true" style="height: 500rpx;">
- </u-picker>
- </view>
- </template>
- <script>
- const baseApi = require('@/http/baseApi.js')
- export default {
- data(){
- return {
- modelText:'请选择角色模版',
- voiceText:'请选择音色',
- fileList:[],
- show:false,
- voiceList:[],
- modelMap:new Map(),
- agentDto:{
-
- }
- }
- },
- async onLoad() {
- await this.getAgentModelList()
- this.getModelVoiceList()
- },
- methods:{
- // 删除图片
- deletePic(event) {
- this.fileList.splice(event.index, 1);
- },
- // 新增图片
- async afterRead(event) {
- // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
- let lists = [].concat(event.file);
- let fileListLen = this.fileList.length;
- lists.map((item) => {
- this.fileList.push({
- ...item,
- status: "uploading",
- message: "上传中",
- });
- });
- for (let i = 0; i < lists.length; i++) {
- const result = await this.uploadFilePromise(lists[i].url);
- let item = this.fileList[fileListLen];
- this.fileList.splice(
- fileListLen,
- 1,
- Object.assign(item, {
- status: "success",
- message: "",
- url: result,
- })
- );
- fileListLen++;
- }
- },
- uploadFilePromise(url) {
- return new Promise((resolve, reject) => {
- let a = uni.uploadFile({
- url: baseApi.BaseApi + '/uploadFile',
- filePath: url,
- name: "file",
- success: (res) => {
- let data = JSON.parse(res.data);
- if(data){
- if(data.code!==0) return
- setTimeout(() => {
- resolve(data.data);
- }, 1000);
- }
- },
- });
- });
- },
- 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');
- }
- }
- })
- },
- 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)
- this.voiceList = [res.data.data];
- this.voiceText = res.data.data.find(v=>v.id===this.agentDto.ttsVoiceId)?.name||'';
- })
- },
- confirm(e){
- this.show = false;
- this.agentDto.ttsVoiceId = e.value[0].id;
- this.voiceText = e.value[0].name;
- },
- comfirmSure(){
- let dto = JSON.parse(JSON.stringify(this.agentDto));
- this.$api.post('/agent',dto).then(res=>{
- if(res.data.code!==0) return this.$showToast(res.data.msg)
- this.$showToast('创建成功');
- setTimeout(()=>{
- uni.reLaunch({
- url:'/pages/home'
- })
- },1500)
- })
- },
- }
- }
- </script>
- <style scoped lang="less">
- .ph{
- font-family: PingFangSC, PingFang SC;
- font-weight: 400;
- font-size: 28rpx;
- color: #A6A6A6;
- line-height: 40rpx;
- text-align: right;
- }
- .page{
- background: #F7F6F9;
- padding: 0 30rpx 30rpx;
- .box{
- background: #FFFFFF;
- border-radius: 24rpx;
- margin-top: 20rpx;
- width: 100%;
- padding: 40rpx 30rpx;
- box-sizing: border-box;
-
- .title{
- font-family: PingFang-SC, PingFang-SC;
- font-weight: bold;
- font-size: 30rpx;
- color: #111111;
- line-height: 32rpx;
- span{
- font-size: 32rpx;
- color: #F31616;
- }
- }
- .upload{
- margin-top: 12rpx;
- display: flex;
- flex-direction: column;
- align-items: center;
- .sc{
- width: 188rpx;
- height: 188rpx;
- }
- .text{
- font-family: PingFangSC, PingFang SC;
- font-weight: 400;
- font-size: 26rpx;
- color: #A6A6A6;
- line-height: 37rpx;
- text-align: center;
- margin-top: 8rpx;
- }
- }
- .right{
- .mtext{
- font-family: PingFangSC, PingFang SC;
- font-weight: 400;
- font-size: 28rpx;
- color: #A6A6A6;
- line-height: 40rpx;
- text-align: right;
- &.active{
- color: #111111;
- }
- }
- image{
- width: 36rpx;
- height: 36rpx;
- margin-left: 10rpx;
- }
- }
- .desc{
- margin-top: 20rpx;
- min-height: 200rpx;
- }
- .tip{
- font-family: PingFangSC, PingFang SC;
- font-weight: 400;
- font-size: 28rpx;
- color: #A6A6A6;
- line-height: 40rpx;
- text-align: right;
- }
- .imgs{
- width: 188rpx;
- height: 188rpx;
- border-radius: 50%;
- position: relative;
- .img1{
- width: 188rpx;
- height: 188rpx;
- border-radius: 50%;
- position: absolute;
- z-index: 2;
- }
- .img2{
- width: 42rpx;
- height: 42rpx;
- position: absolute;
- right: 0;
- bottom: 0;
- z-index: 3;
- }
- }
- }
- .zt_btn{
- margin-top: 54rpx;
- }
- input{
- border: none;
- text-align: right;
- font-size: 28rpx;
- }
- }
- </style>
|