index.vue 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. <template>
  2. <view class="container">
  3. <tn-nav-bar :isBack="true" backgroundColor="#fff" :bottomShadow="false">数字人创建</tn-nav-bar>
  4. <view class="pos">
  5. </view>
  6. <view class="context">
  7. <view class="top" @click="">
  8. <view class="top" @click="show4=true">
  9. <view class="videoBox1" v-if="bgItem.scale==1&&selBgPic">
  10. <image class="img16" :src="selBgPic" mode=""></image>
  11. <view class="role">
  12. <image :src="selRoleItem.url" mode="" @click.stop="show3=true"></image>
  13. </view>
  14. </view>
  15. <view class="videoBox2" v-if="bgItem.scale==2&&selBgPic" :style="{}">
  16. <image class="img16" :src="selBgPic" mode=""></image>
  17. <view class="role" style="z-index: 2;">
  18. <image :src="selRoleItem.url" mode="" @click.stop="show3=true"></image>
  19. </view>
  20. </view>
  21. <view class="videoBox" v-if="!bgItem.scale&&!selBgPic" :style="{minHeight:!selBgPic?'465rpx':''}">
  22. <view class="emptyVideo" style="background: #ccc;height: 100%;"></view>
  23. </view>
  24. </view>
  25. <view class="videoBox" v-if="!bgItem.scale&&!selBgPic" :style="{minHeight:!selBgPic?'465rpx':''}">
  26. <view class="emptyVideo" style="background: #ccc;height: 100%;"></view>
  27. </view>
  28. </view>
  29. <view class="selCon">
  30. <view class="item" @click="show=true" v-if="curBobaoIndex==0">
  31. <view class="label">
  32. 语速:
  33. </view>
  34. <view class="con">
  35. {{roundRate}}X
  36. </view>
  37. </view>
  38. <view class="item" @click="show1=true" v-if="curBobaoIndex==0">
  39. <view class="label">
  40. 声音:{{selVoiceItem.name}}
  41. </view>
  42. <image class="conImg" :src="selVoiceItem.url">
  43. </image>
  44. </view>
  45. <view class="item" @click="show3=true">
  46. <view class="label">
  47. 角色:{{selRoleItem.name}}
  48. </view>
  49. <image class="conImg" :src="selRoleItem.url">
  50. </image>
  51. </view>
  52. </view>
  53. <view class="centerMenuBar">
  54. <view class="barItem" v-for="(item,index) in menuList" @click="handleSetBox(item)">
  55. <view class="left" style="display: flex;justify-content: flex-end;align-items: center;">
  56. <!-- <text class="iconfont " :class="[item.icon]" style="color: #26b3a0;font-weight: 600;"></text> -->
  57. <image :src="item.icon" mode=""></image>
  58. </view>
  59. <view class="right">
  60. {{item.name}}
  61. </view>
  62. </view>
  63. </view>
  64. <view class="robotNameBox">
  65. <uni-easyinput :inputBorder="true" :clearable="false" v-model="robotName"
  66. placeholder="请输入播报标题"></uni-easyinput>
  67. </view>
  68. <view class="audioOrTxtChange">
  69. <view class="item " :class="[index==curBobaoIndex?'item1':'item2']"
  70. v-for="(item,index) in bobaoMenuList" @click="handleChangeBobao(index)">
  71. {{item}}
  72. </view>
  73. </view>
  74. <view class="" v-if="curBobaoIndex==0">
  75. <u--textarea height="" :disabled="false" border="none" :autoHeight="true" maxlength="9999"
  76. v-model="textAreaValue" placeholder="请输入播报内容"></u--textarea>
  77. </view>
  78. <view class="" v-else style="height: 400rpx;">
  79. <view class="uploadVideoBtn" @click="uploadVideo">上传录音文件</view>
  80. <view class="audioList" v-if="audioUrl">
  81. <view class="">
  82. 已上传的音频:
  83. </view>
  84. <view class="audioListBox">
  85. <view class="con">
  86. {{audioUrl}}
  87. </view>
  88. <text @click="audioUrl=''" class="iconfont icon-shanchu rightIcon"
  89. :style="{fontSize:isPc?'64rpx':'32rpx'}"></text>
  90. </view>
  91. </view>
  92. </view>
  93. <view class="btnBox">
  94. <view class="btn draft" @click="saveDraft">
  95. 存草稿
  96. </view>
  97. <view class="btn" @click="genRobot" style="background: linear-gradient(to right,#06C68E,#02BCCD);">
  98. 合成
  99. </view>
  100. </view>
  101. </view>
  102. <u-picker :showIcon="true" :show="showMoreMenu" :columns="columns" title="更多" confirmColor=""
  103. @cancel="showMoreMenu=false" @confirm="handleConfirm"></u-picker>
  104. <u-popup :show="show" @close="close" @open="open">
  105. <view class="contentBox">
  106. <view class="toolBar">
  107. <view class="cancel" @click="show=false">
  108. <image src="/static/images/closeBtn.png" mode=""></image>
  109. </view>
  110. <view class="center">
  111. 全局语速
  112. </view>
  113. <view class="confirm" @click="handleBtnConfirm">
  114. <image src="/static/images/selected.png" mode=""></image>
  115. </view>
  116. </view>
  117. <view class="content" style="min-height: 300rpx;">
  118. <u-slider height="50" min="0.7" max="1.3" step="0.1" class="slider" :showValue='false'
  119. @change="handleChange" activeColor="#26b3a0" v-model="voiceRate"></u-slider>
  120. <view class="sliderValue">
  121. {{roundRate}}X
  122. </view>
  123. </view>
  124. </view>
  125. </u-popup>
  126. <!-- 声音 -->
  127. <u-popup :show="show1" @close="close1" @open="open">
  128. <view class="contentBox">
  129. <view class="toolBar">
  130. <view class="cancel" @click="handleAudioClose">
  131. <image src="/static/images/closeBtn.png" mode=""></image>
  132. </view>
  133. <view class="center">
  134. 声音
  135. </view>
  136. <view class="confirm" @click="handleBtnConfirm1">
  137. <image src="/static/images/selected.png" mode=""></image>
  138. </view>
  139. </view>
  140. <view class="content">
  141. <view class="filterConList" style="max-height: 500rpx;min-height: 500rpx;overflow-y: scroll;">
  142. <view class="item" v-for="(item,index) in allList">
  143. <view class="avtarBox" @click="handleVoiceSel(item,index)">
  144. <view class="imgBox">
  145. <image :class="[currTabIndexAll==index?'sel':'']" :src="item.url" mode="">
  146. </view>
  147. <!-- </image> -->
  148. <view class="nameDes">
  149. {{item.title}}
  150. </view>
  151. <view class="name" :class="[currTabIndexAll==index?'selTxt':'']">
  152. {{item.name}}
  153. </view>
  154. </view>
  155. <view class="playBox" style="" @click="playAudio(item.audio_url)">
  156. 试听
  157. </view>
  158. </view>
  159. </view>
  160. </view>
  161. </view>
  162. </u-popup>
  163. <!-- 模型 -->
  164. <u-popup :show="show3" @close="close3" @open="open">
  165. <view class="contentBox2">
  166. <view class="toolBar">
  167. <view class="cancel" @click="show3=false">
  168. <image src="/static/images/closeBtn.png" mode=""></image>
  169. </view>
  170. <view class="center">
  171. 角色
  172. </view>
  173. <view class="confirm" @click="handleBtnConfirm2">
  174. <image src="/static/images/selected.png" mode=""></image>
  175. </view>
  176. </view>
  177. <view class="content" style="padding: 0 20rpx;">
  178. <view class="filterConList">
  179. <view class="item" v-for="(item,index) in roleList" @click="handleRoleSel(item,index)">
  180. <image :class="[currTabIndexModal==index?'sel':'']" :src="item.url" mode="">
  181. </image>
  182. <view class="name" :class="[currTabIndexModal==index?'selTxt':'']">
  183. {{item.name}}
  184. </view>
  185. <view class="ratio">
  186. {{'('+item.proportion+')'}}
  187. </view>
  188. </view>
  189. </view>
  190. </view>
  191. </view>
  192. </u-popup>
  193. <!-- 背景 -->
  194. <u-popup :show="show4" @close="close4" @open="open">
  195. <view class="contentBox2">
  196. <view class="toolBar">
  197. <view class="cancel" @click="show4=false">
  198. <image src="/static/images/closeBtn.png" mode=""></image>
  199. </view>
  200. <view class="center">
  201. 背景
  202. </view>
  203. <view class="confirm" @click="handleBtnConfirm3">
  204. <image src="/static/images/selected.png" mode=""></image>
  205. </view>
  206. </view>
  207. <view class="content">
  208. <view class="filterBox">
  209. <view class="tabList">
  210. <view class="item1" style="padding-left: 40rpx;padding-right: 40rpx;"
  211. v-for="(item,index) in bgList" :class="[currTabIndex2==index?'tabActive':'']"
  212. @click="handleBgTabChange(item,index)">
  213. {{item}}
  214. </view>
  215. </view>
  216. </view>
  217. <view class="filterConList2" style="max-height: 500rpx;min-height: 500rpx;overflow-y: scroll;">
  218. <view class="pictureBox" v-if="currTabIndex2==0">
  219. <view class="bgBox" v-for="(item,index) in bgPicList">
  220. <image :class="[currTabIndexBg==index?'sel':'']" :src="item.url" mode=""
  221. @click="handleSelBg(item,index)"></image>
  222. <view class="ratio">
  223. {{item.scale==1?'(9:16)':'(16:9)'}}
  224. </view>
  225. </view>
  226. </view>
  227. <view class="pictureBox" v-if="currTabIndex2==1">
  228. <!-- <view class="color" :style="{background:item}" :class="[currTabIndexBgc==index?'sel':'']"
  229. v-for="(item,index) in bgColorList" @click="currTabIndexBgc=index"></view> -->
  230. <view class="defBox">
  231. <view class="type1">
  232. <view class="des">
  233. <text class="lab">尺寸:9:16</text><br>
  234. 背景图要求:<br>
  235. 像素:最高3800 × 3800px<br>
  236. 文件大小:5M以内
  237. </view>
  238. <!-- <view class="" style="color: #06C68E;">
  239. 参考图
  240. </view>
  241. <view class="referImg" @click="previewImg(refImg1)">
  242. <image class="ig1" :src="refImg1" mode="scaleToFill"
  243. style="width: 40%;height: 250rpx;"></image>
  244. </view> -->
  245. <view class="btn" @click="uploadBg1">
  246. 上传背景图(9:16)
  247. </view>
  248. </view>
  249. <view class="type1">
  250. <view class="des">
  251. <text class="lab">尺寸:16:9</text><br>
  252. 背景图要求:<br>
  253. 像素:最高3800 × 3800px<br>
  254. 文件大小:5M以内
  255. </view>
  256. <!-- <view class="" style="color: #06C68E;">
  257. 参考图
  258. </view>
  259. <view class="referImg" @click="previewImg(refImg2)">
  260. <image class="ig2" style="width: 70%;height: 130rpx;" :src="refImg2"
  261. mode="scaleToFill"></image>
  262. </view> -->
  263. <view class="btn" @click="uploadBg2">
  264. 上传背景图(16:9)
  265. </view>
  266. </view>
  267. </view>
  268. <view class=""
  269. style="margin-left: 30rpx;margin-top: 20rpx;word-break: break-all;word-wrap: break-word;">
  270. 已选择的背景图:<br>
  271. <!-- {{testCusBgImg1}} -->
  272. {{testCusBgImg}}
  273. </view>
  274. </view>
  275. </view>
  276. </view>
  277. </view>
  278. </u-popup>
  279. <!-- 声音筛选弹框 -->
  280. <u-popup :show="show2" @close="close" @open="open">
  281. <view class="contentBox">
  282. <view class="toolBar2">
  283. <view class="closeBtn" @click="show2=false">
  284. <!-- <image src="/static/images/selected.png" mode=""></image> -->
  285. X
  286. </view>
  287. </view>
  288. <view class="content">
  289. <!-- 场景 -->
  290. <view class="scenList">
  291. <view class="item " v-for="(item, index) in scenList"
  292. :class="[currScenIndex==index?'active':'']" @click="currScenIndex=index">
  293. {{item}}
  294. </view>
  295. </view>
  296. <!-- 性别-->
  297. <view class="sexList">
  298. <view class="item " v-for="(item, index) in sexList" :class="[currSexIndex==index?'active':'']"
  299. @click="currSexIndex=index">
  300. {{item}}
  301. </view>
  302. </view>
  303. <!-- 年龄-->
  304. <view class="ageList">
  305. <view class="item " v-for="(item, index) in ageList" :class="[currAgeIndex==index?'active':'']"
  306. @click="currAgeIndex=index">
  307. {{item}}
  308. </view>
  309. </view>
  310. <view class="filterBtn2" @click="filter">
  311. 确认
  312. </view>
  313. </view>
  314. </view>
  315. </u-popup>
  316. <!-- 备用-视频尺寸 -->
  317. <u-popup :show="show5" @close="close" @open="open">
  318. <view class="contentBox">
  319. <!-- <view class="toolBar2">
  320. <view class="closeBtn" @click="show5=false">
  321. X
  322. </view>
  323. </view> -->
  324. <view class="toolBar toolBar2">
  325. <view class="cancel">
  326. </view>
  327. <view class="center">
  328. 视频尺寸
  329. </view>
  330. <view class="confirm" @click="handleBtnConfirm2">
  331. <!-- <image src="/static/images/selected.png" mode=""></image> -->
  332. <view class="closeBtn" @click="show5=false">
  333. X
  334. </view>
  335. </view>
  336. </view>
  337. <view class="content">
  338. <view class="videoRatioBox">
  339. <view class="item">
  340. <view class="top">
  341. 竖版视频
  342. </view>
  343. <view class="bottom">
  344. 9:16
  345. </view>
  346. </view>
  347. <view class="item">
  348. <view class="top">
  349. 横版视频
  350. </view>
  351. <view class="bottom">
  352. 16:9
  353. </view>
  354. </view>
  355. </view>
  356. <view class="filterBtn2" @click="show5=false">
  357. 确认
  358. </view>
  359. </view>
  360. </view>
  361. </u-popup>
  362. <!-- <view class="" style="height: 500rpx;width:300rpx !important;" :style='genResBgImg'>
  363. </view> -->
  364. </view>
  365. </view>
  366. </template>
  367. <script>
  368. import {
  369. generateWork,
  370. roleList,
  371. voiceList,
  372. backList,
  373. getBg
  374. } from '@/api/robot/index.js'
  375. import indexVue from './index.vue';
  376. import
  377. uploadImgUrl
  378. from '@/common/config.js';
  379. export default {
  380. data() {
  381. return {
  382. bobaoMenuList: ['输入播报文本', '上传播报录音文件'],
  383. curBobaoIndex: 0,
  384. localBgPicName: '',
  385. refImg1: '',
  386. refImg2: '',
  387. testCusBgImg: '',
  388. testCusBgImg1: '',
  389. // tempAudioUrl: 'https://oaigc.oss-cn-chengdu.aliyuncs.com/20230804/90d3618dd8ae5a9ea50b932dba34f295.mp3',
  390. audioUrl: '',
  391. bgItem: {
  392. },
  393. show5: false,
  394. show4: false,
  395. // bgList: ['图片', '颜色'],
  396. bgList: ['预置', '自定义'],
  397. currTabIndex2: 0,
  398. currTabIndexBg: -1,
  399. currTabIndexBgc: -1,
  400. bgPicList: [],
  401. bgColorList: ['red', 'green', 'blue', 'orange', 'green', 'blue', 'orange'],
  402. show3: false,
  403. viewList: ['2D', '3D'],
  404. currTabIndex1: 0,
  405. currTabIndexModal: -1,
  406. modalList: [{
  407. img: '',
  408. name: '模型名称'
  409. },
  410. {
  411. img: '',
  412. name: '模型名称'
  413. },
  414. {
  415. img: '',
  416. name: '模型名称'
  417. },
  418. {
  419. img: '',
  420. name: '模型名称'
  421. },
  422. {
  423. img: '',
  424. name: '模型名称'
  425. },
  426. {
  427. img: '',
  428. name: '模型名称'
  429. },
  430. {
  431. img: '',
  432. name: '模型名称'
  433. },
  434. ],
  435. show2: false,
  436. currTabIndexAll: -1,
  437. scenList: ['全部场景', '热门', '新闻咨询', '影视咨询', '热门', '新闻咨询', '影视咨询'],
  438. currScenIndex: 0,
  439. sexList: ['全部性别', '男声', '女声'],
  440. currSexIndex: 0,
  441. ageList: ['全部年龄', '儿童', '少年', '青年', '中年', '老年'],
  442. currAgeIndex: 0,
  443. allList: [],
  444. // voiceList: ['全部', '热门', '新闻咨询', '影视综艺', '其他'],
  445. show1: false,
  446. currTabIndex: 0,
  447. robotName: '',
  448. textAreaValue: '',
  449. voiceRate: 1,
  450. selRoleId: -1,
  451. selVoiceId: -1,
  452. selBgId: -1,
  453. selBgPic: '',
  454. roleList: [],
  455. value: 1,
  456. show: false,
  457. menuList: [{
  458. icon: require('@/static/images/yusu.png'),
  459. name: '全局语速'
  460. },
  461. {
  462. icon: require('@/static/images/audio.png'),
  463. name: '声音'
  464. },
  465. {
  466. icon: require('@/static/images/bg.png'),
  467. name: '背景'
  468. },
  469. {
  470. icon: require('@/static/images/role.png'),
  471. name: '角色'
  472. },
  473. ],
  474. videoSrc: '',
  475. showMoreMenu: false,
  476. columns: [
  477. []
  478. ],
  479. selVoiceItem: {
  480. name: '',
  481. url: ''
  482. },
  483. selRoleItem: {
  484. name: '',
  485. url: ''
  486. },
  487. detail: {},
  488. roundRate: 1,
  489. isGenerate: false,
  490. isCreate: false,
  491. roleList2: [],
  492. bgPicList2: [],
  493. newBgItem: {
  494. id: -1
  495. },
  496. music: null,
  497. genResBgImg: "",
  498. // hasFirstSeledRole: false,
  499. isFirstSelRole: true,
  500. testCusBgScale: 1
  501. };
  502. },
  503. computed: {
  504. },
  505. onReady() {
  506. },
  507. onUnload() {
  508. },
  509. onLoad(o) {
  510. if (o.type == 'create') {
  511. this.isCreate = true
  512. this.selRoleId = 5
  513. this.selBgId = 0
  514. this.selVoiceId = 9
  515. this.roundRate = 1
  516. this.voiceRate = 1
  517. return
  518. console.log('create')
  519. }
  520. this.detail = getApp().draftDetail
  521. this.robotName = getApp().draftDetail.name
  522. this.textAreaValue = getApp().draftDetail.content
  523. this.selRoleId = getApp().draftDetail.role - 1
  524. this.selVoiceId = getApp().draftDetail.audio - 1
  525. this.voiceRate = getApp().draftDetail.stage
  526. this.selBgId = getApp().draftDetail.back - 1
  527. this.selBgPic = getApp().draftDetail.backs.url
  528. this.bgItem = getApp().draftDetail.backs
  529. this.roundRate = getApp().draftDetail.stage
  530. this.selVoiceItem = getApp().draftDetail.audios
  531. this.selRoleItem = getApp().draftDetail.roles
  532. this.audioUrl = getApp().draftDetail.audio_url || ''
  533. if (getApp().draftDetail.back_url) {
  534. this.testCusBgImg = getApp().draftDetail.back_url
  535. this.selBgPic = getApp().draftDetail.back_url
  536. this.bgItem.scale = getApp().draftDetail.scale
  537. this.currTabIndex2 = 1
  538. }
  539. if (this.audioUrl && !this.textAreaValue) {
  540. this.curBobaoIndex = 1
  541. }
  542. console.log('传过来的草稿项:', this.detail);
  543. },
  544. async onShow() {
  545. let res = await roleList({})
  546. if (res.code == 0) {
  547. // this.roleList = res.msg
  548. this.roleList2 = res.msg
  549. console.log('数字人角色列表返回值:', res);
  550. if (this.isCreate) {
  551. this.roleList = this.roleList2.filter((item, index) => {
  552. return item.proportion == '9:16'
  553. })
  554. this.selRoleItem = this.roleList2[5]
  555. this.currTabIndexModal = 3
  556. } else {
  557. if (this.detail.backs.scale == 1) {
  558. this.roleList = this.roleList2.filter((item, index) => {
  559. return item.proportion == '9:16'
  560. })
  561. this.currTabIndexModal = this.roleList.findIndex((item, index) => {
  562. return item.id == this.selRoleId + 1
  563. })
  564. } else {
  565. this.roleList = this.roleList2.filter((item, index) => {
  566. return item.proportion == '16:9'
  567. })
  568. this.currTabIndexModal = this.roleList.findIndex((item, index) => {
  569. return item.id == this.selRoleId + 1
  570. })
  571. }
  572. }
  573. } else {
  574. uni.showToast({
  575. title: res.msg,
  576. icon: 'none'
  577. })
  578. }
  579. let res1 = await voiceList({})
  580. if (res1.code == 0) {
  581. // this.roleList = res.data
  582. this.allList = res1.msg
  583. console.log('数字人声音列表返回值:', res1);
  584. this.currTabIndexAll = res1.msg.findIndex((item, index) => {
  585. return item.id == this.selVoiceId + 1
  586. })
  587. if (this.isCreate) {
  588. this.selVoiceItem = this.allList[9]
  589. }
  590. } else {
  591. uni.showToast({
  592. title: res1.msg,
  593. icon: 'none'
  594. })
  595. }
  596. let res3 = await backList({})
  597. if (res3.code == 0) {
  598. this.bgPicList = res3.msg
  599. this.bgPicList2 = res3.msg
  600. this.refImg1 = res3.msg[0].url
  601. this.refImg2 = res3.msg[3].url
  602. console.log('数字人背景列表返回值:', res3);
  603. if (!this.testCusBgImg) {
  604. this.currTabIndexBg = res3.msg.findIndex((item, index) => {
  605. return item.id == this.selBgId + 1
  606. })
  607. }
  608. if (this.isCreate) {
  609. this.selBgPic = this.bgPicList[0].url
  610. this.bgItem = this.bgPicList[0]
  611. }
  612. console.log('index3', this.currTabIndexBgc);
  613. } else {
  614. uni.showToast({
  615. title: res3.msg,
  616. icon: 'none'
  617. })
  618. }
  619. },
  620. onHide() {
  621. // this.music.src = ''
  622. // this.music = null
  623. if (this.music) this.music.destroy()
  624. },
  625. beforeDestroy() {
  626. console.log('beforeDestroy()');
  627. if (this.music) this.music.destroy()
  628. },
  629. onShareAppMessage: function(res) {
  630. },
  631. methods: {
  632. handleChangeBobao(index) {
  633. this.curBobaoIndex = index
  634. // if (index == 0) {
  635. // this.audioUrl = ''
  636. // }
  637. },
  638. previewImg(url) {
  639. uni.previewImage({
  640. urls: [url],
  641. // current:[0]
  642. });
  643. },
  644. handleBgTabChange(item, index) {
  645. this.currTabIndex2 = index
  646. console.log('12122', index);
  647. if (index == 1) {} else {}
  648. },
  649. uploadBg1() {
  650. let that = this;
  651. uni.chooseImage({
  652. count: 1, //默认9
  653. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  654. sourceType: ['album', 'camera'], //从相册选择
  655. success: function(res) {
  656. that.localBgPicName = res.tempFiles[0].name
  657. console.log('选择图片返回值:', res, res.tempFiles[0].size, that.localBgPicName);
  658. if (res.tempFiles[0].size >
  659. 5242880) {
  660. return uni.showToast({
  661. title: '图片大小最大不能超过5M',
  662. icon: 'none',
  663. duration: 2000
  664. })
  665. }
  666. const tempFilePaths = res.tempFilePaths;
  667. //上传服务器将服务器;
  668. uni.uploadFile({
  669. url: uploadImgUrl.baseImgUrl,
  670. filePath: tempFilePaths[0],
  671. name: 'file',
  672. formData: {
  673. accept: 'image',
  674. upload_type: 'ali-oss'
  675. },
  676. success: res2 => {
  677. let a = JSON.parse(res2.data);
  678. if (a.code == 0) {
  679. that.testCusBgImg = a.data.path.trim()
  680. that.testCusBgImg1 = that.localBgPicName
  681. console.log('上传图片返回值----1:', that.testCusBgImg);
  682. if (that.selRoleItem.proportion != '9:16') {
  683. that.selRoleItem = {}
  684. that.currTabIndexModal = -1
  685. }
  686. that.roleList = that.roleList2.filter((item,
  687. index) => {
  688. return item.proportion == '9:16'
  689. })
  690. that.bgItem = {
  691. id: 9999,
  692. scale: 1,
  693. url: a.data.path.trim()
  694. }
  695. that.selBgPic = a.data.path.trim()
  696. that.currTabIndexBg = -1
  697. that.testCusBgScale = 1
  698. // that.ifimg = true
  699. } else {
  700. uni.showToast({
  701. title: '上传图片失败',
  702. icon: 'none'
  703. })
  704. // that.ifimg = false
  705. }
  706. }
  707. });
  708. }
  709. });
  710. },
  711. uploadBg2() {
  712. let that = this;
  713. uni.chooseImage({
  714. count: 1, //默认9
  715. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  716. sourceType: ['album', 'camera'], //从相册选择
  717. success: function(res) {
  718. that.localBgPicName = res.tempFiles[0].name
  719. // console.log('选择图片返回值:', res, res.tempFiles[0].size, that.localBgPicName);
  720. if (res.tempFiles[0].size >
  721. 5242880) {
  722. return uni.showToast({
  723. title: '图片大小最大不能超过5M',
  724. icon: 'none',
  725. duration: 2000
  726. })
  727. }
  728. const tempFilePaths = res.tempFilePaths;
  729. //上传服务器将服务器;
  730. uni.uploadFile({
  731. url: uploadImgUrl.baseImgUrl,
  732. filePath: tempFilePaths[0],
  733. name: 'file',
  734. formData: {
  735. accept: 'image',
  736. upload_type: 'ali-oss'
  737. },
  738. success: res2 => {
  739. let a = JSON.parse(res2.data);
  740. if (a.code == 0) {
  741. that.testCusBgImg = a.data.path.trim()
  742. that.testCusBgImg1 = that.localBgPicName
  743. console.log('上传图片返回值---2:', that.testCusBgImg);
  744. if (that.selRoleItem.proportion != '16:9') {
  745. that.selRoleItem = {}
  746. that.currTabIndexModal = -1
  747. }
  748. that.roleList = that.roleList2.filter((item,
  749. index) => {
  750. return item.proportion == '16:9'
  751. })
  752. that.bgItem = {
  753. id: 9999,
  754. scale: 2,
  755. url: a.data.path.trim()
  756. }
  757. that.selBgPic = a.data.path.trim()
  758. that.currTabIndexBg = -1
  759. that.testCusBgScale = 2
  760. } else {
  761. uni.showToast({
  762. title: '上传图片失败',
  763. icon: 'none'
  764. })
  765. // that.ifimg = false
  766. }
  767. }
  768. });
  769. }
  770. });
  771. },
  772. playAudio(item) {
  773. if (this.music) {
  774. this.music.destroy()
  775. }
  776. this.music = uni.createInnerAudioContext(); //创建播放器对象
  777. this.music.autoplay = true;
  778. this.music.src =
  779. item; //音频地址
  780. // this.music.play();
  781. },
  782. uploadVideo() {
  783. let _this = this
  784. uni.chooseFile({
  785. count: 1, //默认100
  786. extension: ['.mp3'],
  787. success: function(res) {
  788. let tempFilePaths = res.tempFilePaths;
  789. console.log('选择的音频文件返回值', res);
  790. if (!res.tempFiles[0].name.endsWith('.mp3')) {
  791. return uni.showToast({
  792. title: "请上传mp3音频文件",
  793. icon: 'none'
  794. });
  795. }
  796. uni.showLoading({
  797. title: "上传中...",
  798. });
  799. uni.uploadFile({
  800. url: uploadImgUrl.baseImgUrl,
  801. filePath: tempFilePaths[0],
  802. // filePath: JSON.stringify(res.tempFilePaths),
  803. name: 'file',
  804. fileType: "audio",
  805. formData: {
  806. accept: 'audio',
  807. upload_type: 'ali-oss'
  808. },
  809. success: (uploadFileRes) => {
  810. uni.hideLoading();
  811. const ret = JSON.parse(uploadFileRes.data);
  812. if (ret.code == 0) {
  813. _this.audioUrl = ret.data.path
  814. console.log(ret);
  815. }
  816. }
  817. });
  818. }
  819. });
  820. },
  821. close() {
  822. this.show = false
  823. },
  824. close1() {
  825. // this.music.src = ''; //音频地址
  826. // this.music.stop(); //执行播放
  827. if (this.music) {
  828. this.music.destroy()
  829. }
  830. this.show1 = false
  831. },
  832. close3() {
  833. this.show3 = false
  834. },
  835. close4() {
  836. this.show4 = false
  837. },
  838. handleSelBg(item, index) {
  839. this.isFirstSelRole = false
  840. if (this.testCusBgImg) {
  841. this.testCusBgImg = ''
  842. }
  843. if (this.testCusBgImg1) {
  844. this.testCusBgImg1 = ''
  845. }
  846. this.bgItem = item
  847. this.newBgItem = item
  848. console.log('111111111', item);
  849. if (this.selRoleItem.proportion == '9:16') {
  850. if (item.scale != 1) {
  851. this.selRoleItem = {}
  852. this.currTabIndexModal = -1
  853. }
  854. } else {
  855. if (item.scale != 2) {
  856. this.selRoleItem = {}
  857. this.currTabIndexModal = -1
  858. }
  859. }
  860. if (item.scale == 1) {
  861. this.roleList = this.roleList2.filter((item, index) => {
  862. return item.proportion == '9:16'
  863. })
  864. } else {
  865. this.roleList = this.roleList2.filter((item, index) => {
  866. return item.proportion == '16:9'
  867. })
  868. }
  869. this.bgItem = item
  870. this.selBgPic = item.url
  871. this.selBgId = item.id - 1
  872. this.currTabIndexBg = index
  873. },
  874. handleVoiceSel(item, index) {
  875. this.music.src = ''; //音频地址
  876. this.music.stop(); //执行播放
  877. this.selVoiceItem = item
  878. this.selVoiceId = item.id - 1
  879. this.currTabIndexAll = index
  880. },
  881. async handleRoleSel(item, index) {
  882. if (this.isFirstSelRole) {
  883. this.selRoleItem = item
  884. this.selRoleId = item.id - 1
  885. this.currTabIndexModal = index
  886. console.log('获取合成背景参数:', {
  887. roleId: item.id,
  888. backId: this.bgItem.id
  889. });
  890. } else {
  891. // if (this.bgItem.id != this.newBgItem.id) {
  892. // return uni.showToast({
  893. // title: '请先选择背景图,再选择角色',
  894. // icon: 'none'
  895. // })
  896. // }
  897. this.selRoleItem = item
  898. this.selRoleId = item.id - 1
  899. this.currTabIndexModal = index
  900. console.log('获取合成背景参数:', {
  901. roleId: item.id,
  902. backId: this.bgItem.id
  903. });
  904. }
  905. },
  906. async saveDraft() {
  907. if (!this.robotName) {
  908. return uni.showToast({
  909. title: '请输入播报标题',
  910. icon: 'none'
  911. })
  912. }
  913. let parmas = {
  914. name: this.robotName,
  915. content: this.textAreaValue,
  916. // role: this.selRoleId,
  917. // back: this.selBgId,
  918. // audio: this.selVoiceId,
  919. stage: this.roundRate,
  920. audio_url: this.audioUrl,
  921. is_draft: 1
  922. }
  923. if (this.selRoleId != -1) {
  924. parmas['role'] = this.selRoleId
  925. }
  926. if (this.selBgId != -1) {
  927. if (this.testCusBgImg) {
  928. parmas['back_url'] = this.testCusBgImg
  929. parmas['scale'] = this.testCusBgScale
  930. } else {
  931. parmas['back'] = this.selBgId
  932. }
  933. }
  934. if (this.selVoiceId != -1) {
  935. parmas['audio'] = this.selVoiceId
  936. }
  937. console.log('保存数字人草稿参数:', parmas);
  938. // return
  939. let res = await generateWork(parmas)
  940. if (res.code == 0) {
  941. uni.showToast({
  942. title: '保存成功!',
  943. icon: 'success'
  944. })
  945. setTimeout(() => {
  946. uni.navigateBack()
  947. }, 1500)
  948. } else {
  949. uni.showToast({
  950. title: res.msg,
  951. icon: 'none'
  952. })
  953. }
  954. console.log('保存数字人草稿返回值:', res);
  955. },
  956. async genRobot() {
  957. // 生成参数校验
  958. if (!this.robotName) {
  959. return uni.showToast({
  960. title: '请输入播报标题',
  961. icon: 'none'
  962. })
  963. }
  964. if (this.curBobaoIndex == 0 && !this.textAreaValue) {
  965. return uni.showToast({
  966. title: '请输入播报文本',
  967. icon: 'none'
  968. })
  969. }
  970. if (this.curBobaoIndex == 0 && this.textAreaValue.trim().length < 10) {
  971. return uni.showToast({
  972. title: '播报文本最少10个字',
  973. icon: 'none'
  974. })
  975. }
  976. if (this.curBobaoIndex == 1 && !this.audioUrl) {
  977. return uni.showToast({
  978. title: '请上传播报录音文件',
  979. icon: 'none'
  980. })
  981. }
  982. // return
  983. // 生成参数校验
  984. if (this.isGenerate) {
  985. uni.showToast({
  986. title: '请等待上一次生成完成后提交!',
  987. icon: 'none'
  988. })
  989. return
  990. }
  991. let parmas = {}
  992. if (this.audioUrl && !this.testCusBgImg && this.curBobaoIndex == 1) {
  993. parmas = {
  994. name: this.robotName,
  995. // content: this.textAreaValue,
  996. role: this.selRoleId,
  997. back: this.selBgId,
  998. // audio: this.selVoiceId,
  999. // stage: this.roundRate,
  1000. audio_url: this.audioUrl
  1001. }
  1002. } else if (this.audioUrl && this.testCusBgImg && this.curBobaoIndex == 1) {
  1003. parmas = {
  1004. name: this.robotName,
  1005. // content: this.textAreaValue,
  1006. role: this.selRoleId,
  1007. // back: this.selBgId,
  1008. // audio: this.selVoiceId,
  1009. // stage: this.roundRate,
  1010. audio_url: this.audioUrl,
  1011. back_url: this.testCusBgImg
  1012. }
  1013. } else if (!this.audioUrl && this.testCusBgImg) {
  1014. parmas = {
  1015. name: this.robotName,
  1016. content: this.textAreaValue,
  1017. role: this.selRoleId,
  1018. // back: this.selBgId,
  1019. back_url: this.testCusBgImg,
  1020. audio: this.selVoiceId,
  1021. stage: this.roundRate,
  1022. // audio_url: this.audioUrl
  1023. }
  1024. } else if (!this.audioUrl && this.curBobaoIndex == 1) {
  1025. return uni.showToast({
  1026. title: '请上传录音播报文件',
  1027. icon: 'none',
  1028. duration: 1500
  1029. })
  1030. } else if (this.audioUrl && !this.textAreaValue) {
  1031. parmas = {
  1032. name: this.robotName,
  1033. content: this.textAreaValue,
  1034. role: this.selRoleId,
  1035. // back: this.selBgId,
  1036. back_url: this.testCusBgImg,
  1037. audio: this.selVoiceId,
  1038. stage: this.roundRate,
  1039. // audio_url: this.audioUrl
  1040. }
  1041. } else {
  1042. parmas = {
  1043. name: this.robotName,
  1044. content: this.textAreaValue,
  1045. role: this.selRoleId,
  1046. back: this.selBgId,
  1047. audio: this.selVoiceId,
  1048. stage: this.roundRate,
  1049. // audio_url: this.audioUrl
  1050. }
  1051. }
  1052. console.log('创建数字人参数:', parmas);
  1053. // return
  1054. let res = await generateWork(parmas)
  1055. if (res.code == 0) {
  1056. this.isGenerate = true
  1057. uni.showToast({
  1058. title: '创建数字人成功!',
  1059. icon: 'success'
  1060. })
  1061. getApp().from = 'create'
  1062. setTimeout(() => {
  1063. uni.navigateBack()
  1064. }, 1500)
  1065. } else {
  1066. uni.showToast({
  1067. title: res.msg,
  1068. icon: 'none'
  1069. })
  1070. }
  1071. console.log('生成数字人返回值:', res);
  1072. },
  1073. filter() {
  1074. this.show2 = false
  1075. },
  1076. handleFilter() {
  1077. // this.show1 = false
  1078. this.show2 = true
  1079. },
  1080. handleAudioClose() {
  1081. this.show1 = false
  1082. if (this.music) {
  1083. this.music.destroy()
  1084. }
  1085. },
  1086. handleBtnConfirm1() {
  1087. this.show1 = false
  1088. if (this.music) {
  1089. this.music.destroy()
  1090. }
  1091. },
  1092. handleBtnConfirm2() {
  1093. this.show3 = false
  1094. },
  1095. handleBtnConfirm3() {
  1096. this.show4 = false
  1097. },
  1098. handleSetBox(item) {
  1099. if (item.name == '全局语速') {
  1100. if (this.curBobaoIndex == 1) {
  1101. return uni.showToast({
  1102. title: '上传音频不支持全局语速',
  1103. icon: 'none'
  1104. })
  1105. }
  1106. this.show = true
  1107. } else if (item.name == '声音') {
  1108. if (this.curBobaoIndex == 1) {
  1109. return uni.showToast({
  1110. title: '上传音频不支持声音选择',
  1111. icon: 'none'
  1112. })
  1113. }
  1114. this.music = uni.createInnerAudioContext(); //创建播放器对象
  1115. this.music.autoplay = true;
  1116. this.show1 = true
  1117. } else if (item.name == '角色') {
  1118. this.show3 = true
  1119. } else if (item.name == '背景') {
  1120. this.show4 = true
  1121. }
  1122. },
  1123. handleChange(e) {
  1124. console.log(e);
  1125. this.roundRate = e.toFixed(1)
  1126. },
  1127. handleBtnConfirm() {
  1128. this.show = false
  1129. },
  1130. handleCreatePro() {
  1131. uni.navigateTo({
  1132. url: ''
  1133. })
  1134. },
  1135. handleShowMoreMenu() {
  1136. this.showMoreMenu = true
  1137. },
  1138. handleConfirm(e) {
  1139. this.showMoreMenu = false
  1140. },
  1141. open() {
  1142. // console.log('open() ');
  1143. }
  1144. }
  1145. };
  1146. </script>
  1147. <style lang="scss" scoped>
  1148. @import './index.scss';
  1149. </style>