1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261 |
- <template>
- <view class="container">
- <tn-nav-bar :isBack="true" backgroundColor="#fff" :bottomShadow="false">数字人创建</tn-nav-bar>
- <view class="pos">
- </view>
- <view class="context">
- <view class="top" @click="">
- <view class="top" @click="show4=true">
- <view class="videoBox1" v-if="bgItem.scale==1&&selBgPic">
- <image class="img16" :src="selBgPic" mode=""></image>
- <view class="role">
- <image :src="selRoleItem.url" mode="" @click.stop="show3=true"></image>
- </view>
- </view>
- <view class="videoBox2" v-if="bgItem.scale==2&&selBgPic" :style="{}">
- <image class="img16" :src="selBgPic" mode=""></image>
- <view class="role" style="z-index: 2;">
- <image :src="selRoleItem.url" mode="" @click.stop="show3=true"></image>
- </view>
- </view>
- <view class="videoBox" v-if="!bgItem.scale&&!selBgPic" :style="{minHeight:!selBgPic?'465rpx':''}">
- <view class="emptyVideo" style="background: #ccc;height: 100%;"></view>
- </view>
- </view>
- <view class="videoBox" v-if="!bgItem.scale&&!selBgPic" :style="{minHeight:!selBgPic?'465rpx':''}">
- <view class="emptyVideo" style="background: #ccc;height: 100%;"></view>
- </view>
- </view>
- <view class="selCon">
- <view class="item" @click="show=true" v-if="curBobaoIndex==0">
- <view class="label">
- 语速:
- </view>
- <view class="con">
- {{roundRate}}X
- </view>
- </view>
- <view class="item" @click="show1=true" v-if="curBobaoIndex==0">
- <view class="label">
- 声音:{{selVoiceItem.name}}
- </view>
- <image class="conImg" :src="selVoiceItem.url">
- </image>
- </view>
- <view class="item" @click="show3=true">
- <view class="label">
- 角色:{{selRoleItem.name}}
- </view>
- <image class="conImg" :src="selRoleItem.url">
- </image>
- </view>
- </view>
- <view class="centerMenuBar">
- <view class="barItem" v-for="(item,index) in menuList" @click="handleSetBox(item)">
- <view class="left" style="display: flex;justify-content: flex-end;align-items: center;">
- <!-- <text class="iconfont " :class="[item.icon]" style="color: #26b3a0;font-weight: 600;"></text> -->
- <image :src="item.icon" mode=""></image>
- </view>
- <view class="right">
- {{item.name}}
- </view>
- </view>
- </view>
- <view class="robotNameBox">
- <uni-easyinput :inputBorder="true" :clearable="false" v-model="robotName"
- placeholder="请输入播报标题"></uni-easyinput>
- </view>
- <view class="audioOrTxtChange">
- <view class="item " :class="[index==curBobaoIndex?'item1':'item2']"
- v-for="(item,index) in bobaoMenuList" @click="handleChangeBobao(index)">
- {{item}}
- </view>
- </view>
- <view class="" v-if="curBobaoIndex==0">
- <u--textarea height="" :disabled="false" border="none" :autoHeight="true" maxlength="9999"
- v-model="textAreaValue" placeholder="请输入播报内容"></u--textarea>
- </view>
- <view class="" v-else style="height: 400rpx;">
- <view class="uploadVideoBtn" @click="uploadVideo">上传录音文件</view>
- <view class="audioList" v-if="audioUrl">
- <view class="">
- 已上传的音频:
- </view>
- <view class="audioListBox">
- <view class="con">
- {{audioUrl}}
- </view>
- <text @click="audioUrl=''" class="iconfont icon-shanchu rightIcon"
- :style="{fontSize:isPc?'64rpx':'32rpx'}"></text>
- </view>
- </view>
- </view>
- <view class="btnBox">
- <view class="btn draft" @click="saveDraft">
- 存草稿
- </view>
- <view class="btn" @click="genRobot" style="background: linear-gradient(to right,#06C68E,#02BCCD);">
- 合成
- </view>
- </view>
- </view>
- <u-picker :showIcon="true" :show="showMoreMenu" :columns="columns" title="更多" confirmColor=""
- @cancel="showMoreMenu=false" @confirm="handleConfirm"></u-picker>
- <u-popup :show="show" @close="close" @open="open">
- <view class="contentBox">
- <view class="toolBar">
- <view class="cancel" @click="show=false">
- <image src="/static/images/closeBtn.png" mode=""></image>
- </view>
- <view class="center">
- 全局语速
- </view>
- <view class="confirm" @click="handleBtnConfirm">
- <image src="/static/images/selected.png" mode=""></image>
- </view>
- </view>
- <view class="content" style="min-height: 300rpx;">
- <u-slider height="50" min="0.7" max="1.3" step="0.1" class="slider" :showValue='false'
- @change="handleChange" activeColor="#26b3a0" v-model="voiceRate"></u-slider>
- <view class="sliderValue">
- {{roundRate}}X
- </view>
- </view>
- </view>
- </u-popup>
- <!-- 声音 -->
- <u-popup :show="show1" @close="close1" @open="open">
- <view class="contentBox">
- <view class="toolBar">
- <view class="cancel" @click="handleAudioClose">
- <image src="/static/images/closeBtn.png" mode=""></image>
- </view>
- <view class="center">
- 声音
- </view>
- <view class="confirm" @click="handleBtnConfirm1">
- <image src="/static/images/selected.png" mode=""></image>
- </view>
- </view>
- <view class="content">
- <view class="filterConList" style="max-height: 500rpx;min-height: 500rpx;overflow-y: scroll;">
- <view class="item" v-for="(item,index) in allList">
- <view class="avtarBox" @click="handleVoiceSel(item,index)">
- <view class="imgBox">
- <image :class="[currTabIndexAll==index?'sel':'']" :src="item.url" mode="">
- </view>
- <!-- </image> -->
- <view class="nameDes">
- {{item.title}}
- </view>
- <view class="name" :class="[currTabIndexAll==index?'selTxt':'']">
- {{item.name}}
- </view>
- </view>
- <view class="playBox" style="" @click="playAudio(item.audio_url)">
- 试听
- </view>
- </view>
- </view>
- </view>
- </view>
- </u-popup>
- <!-- 模型 -->
- <u-popup :show="show3" @close="close3" @open="open">
- <view class="contentBox2">
- <view class="toolBar">
- <view class="cancel" @click="show3=false">
- <image src="/static/images/closeBtn.png" mode=""></image>
- </view>
- <view class="center">
- 角色
- </view>
- <view class="confirm" @click="handleBtnConfirm2">
- <image src="/static/images/selected.png" mode=""></image>
- </view>
- </view>
- <view class="content" style="padding: 0 20rpx;">
- <view class="filterConList">
- <view class="item" v-for="(item,index) in roleList" @click="handleRoleSel(item,index)">
- <image :class="[currTabIndexModal==index?'sel':'']" :src="item.url" mode="">
- </image>
- <view class="name" :class="[currTabIndexModal==index?'selTxt':'']">
- {{item.name}}
- </view>
- <view class="ratio">
- {{'('+item.proportion+')'}}
- </view>
- </view>
- </view>
- </view>
- </view>
- </u-popup>
- <!-- 背景 -->
- <u-popup :show="show4" @close="close4" @open="open">
- <view class="contentBox2">
- <view class="toolBar">
- <view class="cancel" @click="show4=false">
- <image src="/static/images/closeBtn.png" mode=""></image>
- </view>
- <view class="center">
- 背景
- </view>
- <view class="confirm" @click="handleBtnConfirm3">
- <image src="/static/images/selected.png" mode=""></image>
- </view>
- </view>
- <view class="content">
- <view class="filterBox">
- <view class="tabList">
- <view class="item1" style="padding-left: 40rpx;padding-right: 40rpx;"
- v-for="(item,index) in bgList" :class="[currTabIndex2==index?'tabActive':'']"
- @click="handleBgTabChange(item,index)">
- {{item}}
- </view>
- </view>
- </view>
- <view class="filterConList2" style="max-height: 500rpx;min-height: 500rpx;overflow-y: scroll;">
- <view class="pictureBox" v-if="currTabIndex2==0">
- <view class="bgBox" v-for="(item,index) in bgPicList">
- <image :class="[currTabIndexBg==index?'sel':'']" :src="item.url" mode=""
- @click="handleSelBg(item,index)"></image>
- <view class="ratio">
- {{item.scale==1?'(9:16)':'(16:9)'}}
- </view>
- </view>
- </view>
- <view class="pictureBox" v-if="currTabIndex2==1">
- <!-- <view class="color" :style="{background:item}" :class="[currTabIndexBgc==index?'sel':'']"
- v-for="(item,index) in bgColorList" @click="currTabIndexBgc=index"></view> -->
- <view class="defBox">
- <view class="type1">
- <view class="des">
- <text class="lab">尺寸:9:16</text><br>
- 背景图要求:<br>
- 像素:最高3800 × 3800px<br>
- 文件大小:5M以内
- </view>
- <!-- <view class="" style="color: #06C68E;">
- 参考图
- </view>
- <view class="referImg" @click="previewImg(refImg1)">
- <image class="ig1" :src="refImg1" mode="scaleToFill"
- style="width: 40%;height: 250rpx;"></image>
- </view> -->
- <view class="btn" @click="uploadBg1">
- 上传背景图(9:16)
- </view>
- </view>
- <view class="type1">
- <view class="des">
- <text class="lab">尺寸:16:9</text><br>
- 背景图要求:<br>
- 像素:最高3800 × 3800px<br>
- 文件大小:5M以内
- </view>
- <!-- <view class="" style="color: #06C68E;">
- 参考图
- </view>
- <view class="referImg" @click="previewImg(refImg2)">
- <image class="ig2" style="width: 70%;height: 130rpx;" :src="refImg2"
- mode="scaleToFill"></image>
- </view> -->
- <view class="btn" @click="uploadBg2">
- 上传背景图(16:9)
- </view>
- </view>
- </view>
- <view class=""
- style="margin-left: 30rpx;margin-top: 20rpx;word-break: break-all;word-wrap: break-word;">
- 已选择的背景图:<br>
- <!-- {{testCusBgImg1}} -->
- {{testCusBgImg}}
- </view>
- </view>
- </view>
- </view>
- </view>
- </u-popup>
- <!-- 声音筛选弹框 -->
- <u-popup :show="show2" @close="close" @open="open">
- <view class="contentBox">
- <view class="toolBar2">
- <view class="closeBtn" @click="show2=false">
- <!-- <image src="/static/images/selected.png" mode=""></image> -->
- X
- </view>
- </view>
- <view class="content">
- <!-- 场景 -->
- <view class="scenList">
- <view class="item " v-for="(item, index) in scenList"
- :class="[currScenIndex==index?'active':'']" @click="currScenIndex=index">
- {{item}}
- </view>
- </view>
- <!-- 性别-->
- <view class="sexList">
- <view class="item " v-for="(item, index) in sexList" :class="[currSexIndex==index?'active':'']"
- @click="currSexIndex=index">
- {{item}}
- </view>
- </view>
- <!-- 年龄-->
- <view class="ageList">
- <view class="item " v-for="(item, index) in ageList" :class="[currAgeIndex==index?'active':'']"
- @click="currAgeIndex=index">
- {{item}}
- </view>
- </view>
- <view class="filterBtn2" @click="filter">
- 确认
- </view>
- </view>
- </view>
- </u-popup>
- <!-- 备用-视频尺寸 -->
- <u-popup :show="show5" @close="close" @open="open">
- <view class="contentBox">
- <!-- <view class="toolBar2">
- <view class="closeBtn" @click="show5=false">
- X
- </view>
- </view> -->
- <view class="toolBar toolBar2">
- <view class="cancel">
- </view>
- <view class="center">
- 视频尺寸
- </view>
- <view class="confirm" @click="handleBtnConfirm2">
- <!-- <image src="/static/images/selected.png" mode=""></image> -->
- <view class="closeBtn" @click="show5=false">
- X
- </view>
- </view>
- </view>
- <view class="content">
- <view class="videoRatioBox">
- <view class="item">
- <view class="top">
- 竖版视频
- </view>
- <view class="bottom">
- 9:16
- </view>
- </view>
- <view class="item">
- <view class="top">
- 横版视频
- </view>
- <view class="bottom">
- 16:9
- </view>
- </view>
- </view>
- <view class="filterBtn2" @click="show5=false">
- 确认
- </view>
- </view>
- </view>
- </u-popup>
- <!-- <view class="" style="height: 500rpx;width:300rpx !important;" :style='genResBgImg'>
- </view> -->
- </view>
- </view>
- </template>
- <script>
- import {
- generateWork,
- roleList,
- voiceList,
- backList,
- getBg
- } from '@/api/robot/index.js'
- import indexVue from './index.vue';
- import
- uploadImgUrl
- from '@/common/config.js';
- export default {
- data() {
- return {
- bobaoMenuList: ['输入播报文本', '上传播报录音文件'],
- curBobaoIndex: 0,
- localBgPicName: '',
- refImg1: '',
- refImg2: '',
- testCusBgImg: '',
- testCusBgImg1: '',
- // tempAudioUrl: 'https://oaigc.oss-cn-chengdu.aliyuncs.com/20230804/90d3618dd8ae5a9ea50b932dba34f295.mp3',
- audioUrl: '',
- bgItem: {
- },
- show5: false,
- show4: false,
- // bgList: ['图片', '颜色'],
- bgList: ['预置', '自定义'],
- currTabIndex2: 0,
- currTabIndexBg: -1,
- currTabIndexBgc: -1,
- bgPicList: [],
- bgColorList: ['red', 'green', 'blue', 'orange', 'green', 'blue', 'orange'],
- show3: false,
- viewList: ['2D', '3D'],
- currTabIndex1: 0,
- currTabIndexModal: -1,
- modalList: [{
- img: '',
- name: '模型名称'
- },
- {
- img: '',
- name: '模型名称'
- },
- {
- img: '',
- name: '模型名称'
- },
- {
- img: '',
- name: '模型名称'
- },
- {
- img: '',
- name: '模型名称'
- },
- {
- img: '',
- name: '模型名称'
- },
- {
- img: '',
- name: '模型名称'
- },
- ],
- show2: false,
- currTabIndexAll: -1,
- scenList: ['全部场景', '热门', '新闻咨询', '影视咨询', '热门', '新闻咨询', '影视咨询'],
- currScenIndex: 0,
- sexList: ['全部性别', '男声', '女声'],
- currSexIndex: 0,
- ageList: ['全部年龄', '儿童', '少年', '青年', '中年', '老年'],
- currAgeIndex: 0,
- allList: [],
- // voiceList: ['全部', '热门', '新闻咨询', '影视综艺', '其他'],
- show1: false,
- currTabIndex: 0,
- robotName: '',
- textAreaValue: '',
- voiceRate: 1,
- selRoleId: -1,
- selVoiceId: -1,
- selBgId: -1,
- selBgPic: '',
- roleList: [],
- value: 1,
- show: false,
- menuList: [{
- icon: require('@/static/images/yusu.png'),
- name: '全局语速'
- },
- {
- icon: require('@/static/images/audio.png'),
- name: '声音'
- },
- {
- icon: require('@/static/images/bg.png'),
- name: '背景'
- },
- {
- icon: require('@/static/images/role.png'),
- name: '角色'
- },
- ],
- videoSrc: '',
- showMoreMenu: false,
- columns: [
- []
- ],
- selVoiceItem: {
- name: '',
- url: ''
- },
- selRoleItem: {
- name: '',
- url: ''
- },
- detail: {},
- roundRate: 1,
- isGenerate: false,
- isCreate: false,
- roleList2: [],
- bgPicList2: [],
- newBgItem: {
- id: -1
- },
- music: null,
- genResBgImg: "",
- // hasFirstSeledRole: false,
- isFirstSelRole: true,
- testCusBgScale: 1
- };
- },
- computed: {
- },
- onReady() {
- },
- onUnload() {
- },
- onLoad(o) {
- if (o.type == 'create') {
- this.isCreate = true
- this.selRoleId = 5
- this.selBgId = 0
- this.selVoiceId = 9
- this.roundRate = 1
- this.voiceRate = 1
- return
- console.log('create')
- }
- this.detail = getApp().draftDetail
- this.robotName = getApp().draftDetail.name
- this.textAreaValue = getApp().draftDetail.content
- this.selRoleId = getApp().draftDetail.role - 1
- this.selVoiceId = getApp().draftDetail.audio - 1
- this.voiceRate = getApp().draftDetail.stage
- this.selBgId = getApp().draftDetail.back - 1
- this.selBgPic = getApp().draftDetail.backs.url
- this.bgItem = getApp().draftDetail.backs
- this.roundRate = getApp().draftDetail.stage
- this.selVoiceItem = getApp().draftDetail.audios
- this.selRoleItem = getApp().draftDetail.roles
- this.audioUrl = getApp().draftDetail.audio_url || ''
- if (getApp().draftDetail.back_url) {
- this.testCusBgImg = getApp().draftDetail.back_url
- this.selBgPic = getApp().draftDetail.back_url
- this.bgItem.scale = getApp().draftDetail.scale
- this.currTabIndex2 = 1
- }
- if (this.audioUrl && !this.textAreaValue) {
- this.curBobaoIndex = 1
- }
- console.log('传过来的草稿项:', this.detail);
- },
- async onShow() {
- let res = await roleList({})
- if (res.code == 0) {
- // this.roleList = res.msg
- this.roleList2 = res.msg
- console.log('数字人角色列表返回值:', res);
- if (this.isCreate) {
- this.roleList = this.roleList2.filter((item, index) => {
- return item.proportion == '9:16'
- })
- this.selRoleItem = this.roleList2[5]
- this.currTabIndexModal = 3
- } else {
- if (this.detail.backs.scale == 1) {
- this.roleList = this.roleList2.filter((item, index) => {
- return item.proportion == '9:16'
- })
- this.currTabIndexModal = this.roleList.findIndex((item, index) => {
- return item.id == this.selRoleId + 1
- })
- } else {
- this.roleList = this.roleList2.filter((item, index) => {
- return item.proportion == '16:9'
- })
- this.currTabIndexModal = this.roleList.findIndex((item, index) => {
- return item.id == this.selRoleId + 1
- })
- }
- }
- } else {
- uni.showToast({
- title: res.msg,
- icon: 'none'
- })
- }
- let res1 = await voiceList({})
- if (res1.code == 0) {
- // this.roleList = res.data
- this.allList = res1.msg
- console.log('数字人声音列表返回值:', res1);
- this.currTabIndexAll = res1.msg.findIndex((item, index) => {
- return item.id == this.selVoiceId + 1
- })
- if (this.isCreate) {
- this.selVoiceItem = this.allList[9]
- }
- } else {
- uni.showToast({
- title: res1.msg,
- icon: 'none'
- })
- }
- let res3 = await backList({})
- if (res3.code == 0) {
- this.bgPicList = res3.msg
- this.bgPicList2 = res3.msg
- this.refImg1 = res3.msg[0].url
- this.refImg2 = res3.msg[3].url
- console.log('数字人背景列表返回值:', res3);
- if (!this.testCusBgImg) {
- this.currTabIndexBg = res3.msg.findIndex((item, index) => {
- return item.id == this.selBgId + 1
- })
- }
- if (this.isCreate) {
- this.selBgPic = this.bgPicList[0].url
- this.bgItem = this.bgPicList[0]
- }
- console.log('index3', this.currTabIndexBgc);
- } else {
- uni.showToast({
- title: res3.msg,
- icon: 'none'
- })
- }
- },
- onHide() {
- // this.music.src = ''
- // this.music = null
- if (this.music) this.music.destroy()
- },
- beforeDestroy() {
- console.log('beforeDestroy()');
- if (this.music) this.music.destroy()
- },
- onShareAppMessage: function(res) {
- },
- methods: {
- handleChangeBobao(index) {
- this.curBobaoIndex = index
- // if (index == 0) {
- // this.audioUrl = ''
- // }
- },
- previewImg(url) {
- uni.previewImage({
- urls: [url],
- // current:[0]
- });
- },
- handleBgTabChange(item, index) {
- this.currTabIndex2 = index
- console.log('12122', index);
- if (index == 1) {} else {}
- },
- uploadBg1() {
- let that = this;
- uni.chooseImage({
- count: 1, //默认9
- sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album', 'camera'], //从相册选择
- success: function(res) {
- that.localBgPicName = res.tempFiles[0].name
- console.log('选择图片返回值:', res, res.tempFiles[0].size, that.localBgPicName);
- if (res.tempFiles[0].size >
- 5242880) {
- return uni.showToast({
- title: '图片大小最大不能超过5M',
- icon: 'none',
- duration: 2000
- })
- }
- const tempFilePaths = res.tempFilePaths;
- //上传服务器将服务器;
- uni.uploadFile({
- url: uploadImgUrl.baseImgUrl,
- filePath: tempFilePaths[0],
- name: 'file',
- formData: {
- accept: 'image',
- upload_type: 'ali-oss'
- },
- success: res2 => {
- let a = JSON.parse(res2.data);
- if (a.code == 0) {
- that.testCusBgImg = a.data.path.trim()
- that.testCusBgImg1 = that.localBgPicName
- console.log('上传图片返回值----1:', that.testCusBgImg);
- if (that.selRoleItem.proportion != '9:16') {
- that.selRoleItem = {}
- that.currTabIndexModal = -1
- }
- that.roleList = that.roleList2.filter((item,
- index) => {
- return item.proportion == '9:16'
- })
- that.bgItem = {
- id: 9999,
- scale: 1,
- url: a.data.path.trim()
- }
- that.selBgPic = a.data.path.trim()
- that.currTabIndexBg = -1
- that.testCusBgScale = 1
- // that.ifimg = true
- } else {
- uni.showToast({
- title: '上传图片失败',
- icon: 'none'
- })
- // that.ifimg = false
- }
- }
- });
- }
- });
- },
- uploadBg2() {
- let that = this;
- uni.chooseImage({
- count: 1, //默认9
- sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album', 'camera'], //从相册选择
- success: function(res) {
- that.localBgPicName = res.tempFiles[0].name
- // console.log('选择图片返回值:', res, res.tempFiles[0].size, that.localBgPicName);
- if (res.tempFiles[0].size >
- 5242880) {
- return uni.showToast({
- title: '图片大小最大不能超过5M',
- icon: 'none',
- duration: 2000
- })
- }
- const tempFilePaths = res.tempFilePaths;
- //上传服务器将服务器;
- uni.uploadFile({
- url: uploadImgUrl.baseImgUrl,
- filePath: tempFilePaths[0],
- name: 'file',
- formData: {
- accept: 'image',
- upload_type: 'ali-oss'
- },
- success: res2 => {
- let a = JSON.parse(res2.data);
- if (a.code == 0) {
- that.testCusBgImg = a.data.path.trim()
- that.testCusBgImg1 = that.localBgPicName
- console.log('上传图片返回值---2:', that.testCusBgImg);
- if (that.selRoleItem.proportion != '16:9') {
- that.selRoleItem = {}
- that.currTabIndexModal = -1
- }
- that.roleList = that.roleList2.filter((item,
- index) => {
- return item.proportion == '16:9'
- })
- that.bgItem = {
- id: 9999,
- scale: 2,
- url: a.data.path.trim()
- }
- that.selBgPic = a.data.path.trim()
- that.currTabIndexBg = -1
- that.testCusBgScale = 2
- } else {
- uni.showToast({
- title: '上传图片失败',
- icon: 'none'
- })
- // that.ifimg = false
- }
- }
- });
- }
- });
- },
- playAudio(item) {
- if (this.music) {
- this.music.destroy()
- }
- this.music = uni.createInnerAudioContext(); //创建播放器对象
- this.music.autoplay = true;
- this.music.src =
- item; //音频地址
- // this.music.play();
- },
- uploadVideo() {
- let _this = this
- uni.chooseFile({
- count: 1, //默认100
- extension: ['.mp3'],
- success: function(res) {
- let tempFilePaths = res.tempFilePaths;
- console.log('选择的音频文件返回值', res);
- if (!res.tempFiles[0].name.endsWith('.mp3')) {
- return uni.showToast({
- title: "请上传mp3音频文件",
- icon: 'none'
- });
- }
- uni.showLoading({
- title: "上传中...",
- });
- uni.uploadFile({
- url: uploadImgUrl.baseImgUrl,
- filePath: tempFilePaths[0],
- // filePath: JSON.stringify(res.tempFilePaths),
- name: 'file',
- fileType: "audio",
- formData: {
- accept: 'audio',
- upload_type: 'ali-oss'
- },
- success: (uploadFileRes) => {
- uni.hideLoading();
- const ret = JSON.parse(uploadFileRes.data);
- if (ret.code == 0) {
- _this.audioUrl = ret.data.path
- console.log(ret);
- }
- }
- });
- }
- });
- },
- close() {
- this.show = false
- },
- close1() {
- // this.music.src = ''; //音频地址
- // this.music.stop(); //执行播放
- if (this.music) {
- this.music.destroy()
- }
- this.show1 = false
- },
- close3() {
- this.show3 = false
- },
- close4() {
- this.show4 = false
- },
- handleSelBg(item, index) {
- this.isFirstSelRole = false
- if (this.testCusBgImg) {
- this.testCusBgImg = ''
- }
- if (this.testCusBgImg1) {
- this.testCusBgImg1 = ''
- }
- this.bgItem = item
- this.newBgItem = item
- console.log('111111111', item);
- if (this.selRoleItem.proportion == '9:16') {
- if (item.scale != 1) {
- this.selRoleItem = {}
- this.currTabIndexModal = -1
- }
- } else {
- if (item.scale != 2) {
- this.selRoleItem = {}
- this.currTabIndexModal = -1
- }
- }
- if (item.scale == 1) {
- this.roleList = this.roleList2.filter((item, index) => {
- return item.proportion == '9:16'
- })
- } else {
- this.roleList = this.roleList2.filter((item, index) => {
- return item.proportion == '16:9'
- })
- }
- this.bgItem = item
- this.selBgPic = item.url
- this.selBgId = item.id - 1
- this.currTabIndexBg = index
- },
- handleVoiceSel(item, index) {
- this.music.src = ''; //音频地址
- this.music.stop(); //执行播放
- this.selVoiceItem = item
- this.selVoiceId = item.id - 1
- this.currTabIndexAll = index
- },
- async handleRoleSel(item, index) {
- if (this.isFirstSelRole) {
- this.selRoleItem = item
- this.selRoleId = item.id - 1
- this.currTabIndexModal = index
- console.log('获取合成背景参数:', {
- roleId: item.id,
- backId: this.bgItem.id
- });
- } else {
- // if (this.bgItem.id != this.newBgItem.id) {
- // return uni.showToast({
- // title: '请先选择背景图,再选择角色',
- // icon: 'none'
- // })
- // }
- this.selRoleItem = item
- this.selRoleId = item.id - 1
- this.currTabIndexModal = index
- console.log('获取合成背景参数:', {
- roleId: item.id,
- backId: this.bgItem.id
- });
- }
- },
- async saveDraft() {
- if (!this.robotName) {
- return uni.showToast({
- title: '请输入播报标题',
- icon: 'none'
- })
- }
- let parmas = {
- name: this.robotName,
- content: this.textAreaValue,
- // role: this.selRoleId,
- // back: this.selBgId,
- // audio: this.selVoiceId,
- stage: this.roundRate,
- audio_url: this.audioUrl,
- is_draft: 1
- }
- if (this.selRoleId != -1) {
- parmas['role'] = this.selRoleId
- }
- if (this.selBgId != -1) {
- if (this.testCusBgImg) {
- parmas['back_url'] = this.testCusBgImg
- parmas['scale'] = this.testCusBgScale
- } else {
- parmas['back'] = this.selBgId
- }
- }
- if (this.selVoiceId != -1) {
- parmas['audio'] = this.selVoiceId
- }
- console.log('保存数字人草稿参数:', parmas);
- // return
- let res = await generateWork(parmas)
- if (res.code == 0) {
- uni.showToast({
- title: '保存成功!',
- icon: 'success'
- })
- setTimeout(() => {
- uni.navigateBack()
- }, 1500)
- } else {
- uni.showToast({
- title: res.msg,
- icon: 'none'
- })
- }
- console.log('保存数字人草稿返回值:', res);
- },
- async genRobot() {
- // 生成参数校验
- if (!this.robotName) {
- return uni.showToast({
- title: '请输入播报标题',
- icon: 'none'
- })
- }
- if (this.curBobaoIndex == 0 && !this.textAreaValue) {
- return uni.showToast({
- title: '请输入播报文本',
- icon: 'none'
- })
- }
- if (this.curBobaoIndex == 0 && this.textAreaValue.trim().length < 10) {
- return uni.showToast({
- title: '播报文本最少10个字',
- icon: 'none'
- })
- }
- if (this.curBobaoIndex == 1 && !this.audioUrl) {
- return uni.showToast({
- title: '请上传播报录音文件',
- icon: 'none'
- })
- }
- // return
- // 生成参数校验
- if (this.isGenerate) {
- uni.showToast({
- title: '请等待上一次生成完成后提交!',
- icon: 'none'
- })
- return
- }
- let parmas = {}
- if (this.audioUrl && !this.testCusBgImg && this.curBobaoIndex == 1) {
- parmas = {
- name: this.robotName,
- // content: this.textAreaValue,
- role: this.selRoleId,
- back: this.selBgId,
- // audio: this.selVoiceId,
- // stage: this.roundRate,
- audio_url: this.audioUrl
- }
- } else if (this.audioUrl && this.testCusBgImg && this.curBobaoIndex == 1) {
- parmas = {
- name: this.robotName,
- // content: this.textAreaValue,
- role: this.selRoleId,
- // back: this.selBgId,
- // audio: this.selVoiceId,
- // stage: this.roundRate,
- audio_url: this.audioUrl,
- back_url: this.testCusBgImg
- }
- } else if (!this.audioUrl && this.testCusBgImg) {
- parmas = {
- name: this.robotName,
- content: this.textAreaValue,
- role: this.selRoleId,
- // back: this.selBgId,
- back_url: this.testCusBgImg,
- audio: this.selVoiceId,
- stage: this.roundRate,
- // audio_url: this.audioUrl
- }
- } else if (!this.audioUrl && this.curBobaoIndex == 1) {
- return uni.showToast({
- title: '请上传录音播报文件',
- icon: 'none',
- duration: 1500
- })
- } else if (this.audioUrl && !this.textAreaValue) {
- parmas = {
- name: this.robotName,
- content: this.textAreaValue,
- role: this.selRoleId,
- // back: this.selBgId,
- back_url: this.testCusBgImg,
- audio: this.selVoiceId,
- stage: this.roundRate,
- // audio_url: this.audioUrl
- }
- } else {
- parmas = {
- name: this.robotName,
- content: this.textAreaValue,
- role: this.selRoleId,
- back: this.selBgId,
- audio: this.selVoiceId,
- stage: this.roundRate,
- // audio_url: this.audioUrl
- }
- }
- console.log('创建数字人参数:', parmas);
- // return
- let res = await generateWork(parmas)
- if (res.code == 0) {
- this.isGenerate = true
- uni.showToast({
- title: '创建数字人成功!',
- icon: 'success'
- })
- getApp().from = 'create'
- setTimeout(() => {
- uni.navigateBack()
- }, 1500)
- } else {
- uni.showToast({
- title: res.msg,
- icon: 'none'
- })
- }
- console.log('生成数字人返回值:', res);
- },
- filter() {
- this.show2 = false
- },
- handleFilter() {
- // this.show1 = false
- this.show2 = true
- },
- handleAudioClose() {
- this.show1 = false
- if (this.music) {
- this.music.destroy()
- }
- },
- handleBtnConfirm1() {
- this.show1 = false
- if (this.music) {
- this.music.destroy()
- }
- },
- handleBtnConfirm2() {
- this.show3 = false
- },
- handleBtnConfirm3() {
- this.show4 = false
- },
- handleSetBox(item) {
- if (item.name == '全局语速') {
- if (this.curBobaoIndex == 1) {
- return uni.showToast({
- title: '上传音频不支持全局语速',
- icon: 'none'
- })
- }
- this.show = true
- } else if (item.name == '声音') {
- if (this.curBobaoIndex == 1) {
- return uni.showToast({
- title: '上传音频不支持声音选择',
- icon: 'none'
- })
- }
- this.music = uni.createInnerAudioContext(); //创建播放器对象
- this.music.autoplay = true;
- this.show1 = true
- } else if (item.name == '角色') {
- this.show3 = true
- } else if (item.name == '背景') {
- this.show4 = true
- }
- },
- handleChange(e) {
- console.log(e);
- this.roundRate = e.toFixed(1)
- },
- handleBtnConfirm() {
- this.show = false
- },
- handleCreatePro() {
- uni.navigateTo({
- url: ''
- })
- },
- handleShowMoreMenu() {
- this.showMoreMenu = true
- },
- handleConfirm(e) {
- this.showMoreMenu = false
- },
- open() {
- // console.log('open() ');
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- @import './index.scss';
- </style>
|