viewAI.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. <template src="./viewAI.html">
  2. </template>
  3. <script>
  4. const util = require('@/utils/util.js').default;
  5. import {
  6. MessageBox
  7. } from 'mint-ui';
  8. import {
  9. Indicator
  10. } from 'mint-ui';
  11. import {
  12. Toast
  13. } from 'mint-ui';
  14. import lottie from "lottie-web"; //lottie
  15. // const { createWorker } = require('@ffmpeg/ffmpeg');
  16. import { FFmpeg } from "@ffmpeg/ffmpeg";
  17. import { fetchFile, toBlobURL } from '@ffmpeg/util';
  18. var qiniu = require('qiniu-js');
  19. const baseURL = '.'
  20. let ffmpeg = null;
  21. // import { createFFmpeg, fetchFile } from '@/assets/ffmpeg.min.js';
  22. // import commonMethod from '@/common/commonMethod.js';
  23. // import touchHandle from '@/mixins/touchHandle.js';
  24. // import requestConfig from '@/static/lib/requestConfig';
  25. export default {
  26. data: function() {
  27. return {
  28. leftList: [],
  29. rightList: [],
  30. musicList: [], //音乐列表
  31. dataList: [],
  32. tabIndex: 0, //当前选中的tab序号
  33. selectIndex: -1,
  34. peopleIndex: -1,
  35. petIndex: -1,
  36. musicIndex: -1,
  37. specialIndex: 1,
  38. specialList:[
  39. {
  40. id:1,
  41. url:'https://dm.static.elab-plus.com/miniProgram/lottieJson/gold.json',
  42. title:'金光闪闪',
  43. },
  44. {
  45. id:2,
  46. url:'https://dm.static.elab-plus.com/miniProgram/lottieJson/fireworks.json',
  47. title:'烟花',
  48. },
  49. {
  50. id:3,
  51. url:'https://dm.static.elab-plus.com/miniProgram/lottieJson/coloreRibbon.json',
  52. title:'彩带',
  53. },
  54. ],
  55. hasRedBox:false, //是否添加了红包
  56. limit:50,
  57. videoId:'', //上传视频的id
  58. videoUrl:'', //处理好的视频地址
  59. progress:0, //进度条
  60. ktProgress:0, //抠图进度条
  61. cProgress:0, //压缩进度条
  62. showPersonView:false, //是否显示个人形象提示弹窗
  63. showPopView:false, //是否显示确认取消框
  64. uploadStatus:0, //视频处理的状态 -1 压缩中 0 未开始,1 上传中,2绿幕抠图中-服务端处理中,3处理成功 4 处理失败
  65. count:0, //结果请求次数
  66. timeOut:90000, //超时时间
  67. outTimer:null, //延时处理对象
  68. timer:null, //轮询对象
  69. widthHeight:'', //用户上传视频尺寸
  70. stopFlag:false, //停止上传动作
  71. cancelTokenSource:null, //取消上传的操作对象
  72. repeartFlag:false, //防止重复点击
  73. videoSrc:'',
  74. }
  75. },
  76. props: {
  77. relationId: {
  78. type: String,
  79. default: '',
  80. },
  81. amount: {
  82. type: String,
  83. default: '',
  84. },
  85. },
  86. watch: {
  87. relationId(newVal, oldVal) {
  88. if (newVal == null) {
  89. return;
  90. }
  91. console.log("当前空间数据relationId:", newVal);
  92. this.tabIndex = 2;//有红包时默认切换为红包
  93. if(!this.hasRedBox){
  94. setTimeout(()=>{
  95. this.addRedBox();//添加红包
  96. },500)
  97. this.$nextTick(() => {
  98. // 播放lottie动画
  99. lottie.destroy("markLoading");
  100. var element = document.getElementById("special-img");
  101. this.anim = lottie.loadAnimation({
  102. container: element,
  103. name: "markLoading",
  104. renderer: "svg",
  105. loop: true,
  106. autoplay: true,
  107. path: this.specialList[this.specialIndex].url, //动画json
  108. });
  109. });
  110. }
  111. // this.curSpaceArea = parseFloat(
  112. // (newVal.spaceWidth * newVal.spaceHeight) / 10000
  113. // ).toFixed(2);
  114. // this.getOverallArrangementDetailsList();
  115. },
  116. },
  117. // mixins: [touchHandle],
  118. async mounted() {
  119. // await this.getCityHouseList();
  120. console.warn("***viewAI***")
  121. // Indicator.open('加载中...');
  122. this.getDatalist(0);
  123. this.getDatalist(1);
  124. this.getDatalist(3);
  125. // this.getRelationInfo();//获取场景信息
  126. },
  127. computed: {
  128. userId() {
  129. return this.$store.state.userId;
  130. },
  131. },
  132. // 页面被展示时执行
  133. onPageShow: function() {
  134. },
  135. //页面被隐藏时执行
  136. onPageHide: function() {
  137. // console.warn("***detached-hide***")
  138. },
  139. methods: {
  140. format(percentage) {
  141. let text = "上传中";
  142. if(this.uploadStatus==1){
  143. text = "上传中";
  144. }else if(this.uploadStatus==2){
  145. text = "抠图中";
  146. }else if(this.uploadStatus==-1){
  147. text = "压缩中";
  148. }
  149. return `${text}\n${percentage}%`;
  150. },
  151. resolveIndex(index) {
  152. this.selectIndex = index || 0;
  153. },
  154. catchTapEvent:function(){
  155. return false;
  156. },
  157. specialChange(index) {
  158. if (this.specialIndex == index) {
  159. return false;
  160. }
  161. this.specialIndex = index;
  162. this.$nextTick(() => {
  163. // 播放lottie动画
  164. lottie.destroy("markLoading");
  165. var element = document.getElementById("special-img");
  166. this.anim = lottie.loadAnimation({
  167. container: element,
  168. name: "markLoading",
  169. renderer: "svg",
  170. loop: true,
  171. autoplay: true,
  172. path: this.specialList[this.specialIndex].url, //动画json
  173. });
  174. });
  175. },
  176. tabChange(index) {
  177. if (this.tabIndex == index) {
  178. return false;
  179. }
  180. if (this.$parent.repeatFlag == true) {
  181. Toast({
  182. message: '加载中...请稍后再试',
  183. });
  184. return false
  185. }
  186. this.tabIndex = index;
  187. this.$emit("tabChange", this.tabIndex); //通知页面,户型大类发生了变更
  188. if(this.tabIndex==2 && this.specialIndex>-1){
  189. if(!this.hasRedBox){
  190. this.addRedBox();//添加红包
  191. }
  192. this.$nextTick(() => {
  193. // 播放lottie动画
  194. lottie.destroy("markLoading");
  195. var element = document.getElementById("special-img");
  196. this.anim = lottie.loadAnimation({
  197. container: element,
  198. name: "markLoading",
  199. renderer: "svg",
  200. loop: true,
  201. autoplay: true,
  202. path: this.specialList[this.specialIndex].url, //动画json
  203. });
  204. });
  205. }
  206. },
  207. initStatus(){
  208. this.progress = 0;
  209. this.ktProgress = 0;
  210. this.count = 0;
  211. this.videoUrl = '';
  212. this.widthHeight = '';
  213. this.leftList[0].icon = '';
  214. this.leftList[0].url = '';
  215. this.uploadStatus = 0;//处理完毕
  216. },
  217. async transcode(file,ffmpeg){
  218. // if(!crossOriginIsolated) {
  219. // SharedArrayBuffer = ArrayBuffer;
  220. // }
  221. const { name } = file;
  222. console.warn('正在加载 ffmpeg-core.js')
  223. await ffmpeg.load();
  224. console.warn('开始压缩');
  225. ffmpeg.FS('writeFile', name, await fetchFile(file));
  226. // '-b','2000000' 值越小 压缩率越大
  227. await ffmpeg.run('-i', name,'-b','2000000','output.mp4');
  228. console.warn('压缩完成');
  229. var data = ffmpeg.FS('readFile', 'output.mp4');
  230. var newfile = new File([data.buffer], name, { type: "video/mp4" });
  231. var video = document.getElementById('output-video');
  232. video.src = URL.createObjectURL(new Blob([data.buffer], {
  233. type: 'video/mp4'
  234. }));
  235. // this.uploadMaterielFile(newfile)
  236. },
  237. async transcodeNew(file,form){
  238. if (ffmpeg === null) {
  239. ffmpeg = new FFmpeg();
  240. }
  241. ffmpeg.on("log", ({ message }) => {
  242. console.warn(message);
  243. })
  244. ffmpeg.on("progress", ({ progress }) => {
  245. let pro = `${progress * 100} %`;
  246. console.warn("***progress***",pro)
  247. this.cProgress = parseInt(progress * 100);
  248. });
  249. await ffmpeg.load({
  250. // coreURL: "/packages/core/dist/esm/ffmpeg-core.js",
  251. coreURL: await toBlobURL(`${baseURL}/ffmpeg-core.js`, 'text/javascript'),
  252. wasmURL: await toBlobURL(`${baseURL}/ffmpeg-core.wasm`, 'application/wasm'),
  253. workerURL: await toBlobURL(`${baseURL}/ffmpeg-core.worker.js`, 'text/javascript')
  254. });
  255. const {name} = file;
  256. console.warn('开始压缩');
  257. this.uploadStatus = -1;
  258. let d0 = Date.now();
  259. await ffmpeg.writeFile(name, await fetchFile(file));
  260. await ffmpeg.exec(['-i', name, 'output.mp4']);
  261. this.uploadStatus = 1;
  262. let d1 = Date.now();
  263. console.warn("***time1**", d0, d1,d1 - d0)
  264. console.warn('压缩完成');
  265. const data = await ffmpeg.readFile('output.mp4');
  266. // const video = document.getElementById('output-video');
  267. // video.src = URL.createObjectURL(new Blob([data.buffer], { type: 'video/mp4' }));
  268. var newfile = new File([data.buffer], name, { type: "video/mp4" });
  269. this.uploadMaterielFile({file:newfile},form)
  270. },
  271. //上传到七牛云中
  272. async uploadVideolFile(file,form){
  273. var self = this;
  274. let tokenObj = await requestConfig('getUploadToken', {});//获取上传token
  275. var token = tokenObj.single.token;
  276. var resultUrl = tokenObj.single.resultUrl; //上传图片的访问前缀this.resultUrl =
  277. var tp = file.name.substring(file.name.lastIndexOf('.'));
  278. var putExtra = {
  279. fname: "",
  280. params: {},
  281. mimeType: null
  282. };
  283. var config = {
  284. useCdnDomain: true,
  285. disableStatisticsReport: false,
  286. retryCount: 6,
  287. region: qiniu.region.z0
  288. };
  289. self.uploadStatus = 1;//上传中
  290. self.showPersonView = false;
  291. self.addSilhouette();//添加剪影视频
  292. var fileName = decodeURIComponent(encodeURIComponent(Date.now() + '/video' + Math.floor(Math.random()*1000))) + tp;
  293. var observable = qiniu.upload(file, fileName, token, putExtra, config);
  294. var subscription = observable.subscribe(self.next, self.error, async function(res){
  295. self.uploading=false;
  296. let VideoUrl = resultUrl + fileName;
  297. console.warn("视频上传七牛成功",VideoUrl);
  298. // self.$message.success('视频上传成功');
  299. // alert("***uploadMaterielFile***"+$config.brandId+this.userId);
  300. let data = {
  301. "url":VideoUrl,
  302. "brandId": $config.brandId,
  303. "userId":self.userId
  304. }
  305. let res1 = await requestConfig('robust_videoV2', data, true, false)
  306. if (res1 && res1.success && res1.single) {
  307. self.videoId = res1.single;//根据Id查询结果
  308. self.startInterval();//开始轮询获取结果
  309. }else{
  310. self.initStatus();//还原初始状态
  311. }
  312. let videoForm = document.getElementById(form); //获取表单对象
  313. videoForm && videoForm.reset(); // 重置表单
  314. });
  315. },
  316. next(res){
  317. this.progress = Math.round(res.total.percent);//loaded已经加载的
  318. },
  319. // 上传七牛云发生错误
  320. error(res){
  321. this.$message.error('视频上传失败'+res.message);
  322. },
  323. async uploadImgObj(e,form,type=1){
  324. this.stopFlag = false;//上传开始时,开启上传
  325. if(type==2){
  326. this.initStatus();//重置上传状态到初始值
  327. }
  328. //上传图片
  329. var file = e.target.files[0];
  330. // this.transcodeNew(file,form);
  331. var fileSize = file.size / 1024 / 1024;
  332. // alert('**文件**' + e.target.value + "-fileName=" + file.name+ "-fileSize="+fileSize);
  333. if (!/\.(MP4|mp4|MOV|mov)$/.test(e.target.value)) {
  334. this.$message.warning('文件类型必须是mp4或者mov');
  335. var videoForm = document.getElementById(form); //获取表单对象
  336. videoForm && videoForm.reset(); // 重置表单
  337. return false
  338. }
  339. if (fileSize > this.limit) {
  340. this.$message.warning('您的上传的视频过大,请低于' + this.limit + 'MB');
  341. var videoForm = document.getElementById(form); //获取表单对象
  342. videoForm && videoForm.reset(); // 重置表单
  343. return false
  344. }
  345. if (file.name.length > 100) {
  346. this.$message.warning('文件名过长,请不要超过100个字符');
  347. var videoForm = document.getElementById(form); //获取表单对象
  348. videoForm && videoForm.reset(); // 重置表单
  349. return false;
  350. }
  351. if(this.$parent.isIOS){//IOS则直接上传
  352. if(!this.stopFlag){
  353. var item = {};
  354. item.file = file;
  355. console.warn("***uploadImgObj***",file)
  356. if(fileSize>20){//七牛云上传-服务端压缩
  357. this.uploadVideolFile(file,form);
  358. }else{
  359. this.uploadMaterielFile(item, form); //正常上传图片
  360. }
  361. }
  362. }else{//安卓
  363. let reader = new FileReader();
  364. reader.onload = (event) => {
  365. let video = document.createElement('video');
  366. video.onloadedmetadata = (event) => {
  367. let duration = video.duration;
  368. let width = video.videoWidth;
  369. let height = video.videoHeight;
  370. // this.videoWidth = width;
  371. // this.videoHeight = height;
  372. console.warn('视频时长:', duration,this.stopFlag);
  373. console.warn('视频尺寸:x:', width, 'y:', height);
  374. if (duration > 20) {
  375. this.$message.warning('您的上传的视频过长,请低于20s');
  376. var videoForm = document.getElementById(form); //获取表单对象
  377. videoForm && videoForm.reset(); // 重置表单
  378. return false
  379. }else{
  380. if(!this.stopFlag){
  381. var item = {};
  382. item.file = file;
  383. console.warn("***uploadImgObj***",file)
  384. if(fileSize>20){//七牛云上传-服务端压缩
  385. this.uploadVideolFile(file,form);
  386. }else{
  387. this.uploadMaterielFile(item, form); //正常上传图片
  388. }
  389. }
  390. }
  391. };
  392. video.src = event.target.result;
  393. };
  394. reader.readAsDataURL(file);
  395. }
  396. },
  397. //视频上传进度处理
  398. uploadProgress(e){
  399. this.progress = Math.round((e.loaded / e.total) * 100);//loaded已经加载的
  400. console.warn("***uploadProgress***",this.progress)
  401. },
  402. //显示弹窗提示框
  403. showPopViewHandle(){
  404. this.showPopView = true;//弹出确认框;
  405. },
  406. //取消上传
  407. cancel(cancelTokenSource){
  408. this.cancelTokenSource = cancelTokenSource;
  409. console.warn("***取消上传函数定义***")
  410. },
  411. //停止上传
  412. stopUpload(){
  413. this.showPopView = false;//弹出确认框;
  414. this.stopFlag = true;//停止上传标志打开
  415. if(this.uploadStatus == 1){
  416. this.cancelTokenSource.cancel('上传已取消');//通知取消上传
  417. Toast({
  418. message: '上传已取消',
  419. });
  420. }
  421. else if(this.uploadStatus==2 || this.uploadStatus==3){//绿幕抠图中 或者已经完成
  422. let data = {
  423. userId:this.userId,
  424. brandId: $config.brandId,
  425. processStatus:'canceled',
  426. virtualNo:this.videoId,
  427. }
  428. requestConfig('addUserVirtural', data);//停止该绿幕视频的使用
  429. this.initStatus();//还原初始状态
  430. }
  431. let data = {
  432. url:'https://dm.static.elab-plus.com/miniProgram/silhouette1.mp4',
  433. value:'个人形象',
  434. width:'',
  435. height:'',
  436. }
  437. this.aiPeopleChange(data, 'canel')
  438. this.peopleIndex = -1;
  439. },
  440. //获取用户上传的个人形象
  441. async getUserVirtural() {
  442. let data = {
  443. userId:this.userId,
  444. brandId: $config.brandId,
  445. processStatus:'completed',
  446. }
  447. let res = await requestConfig('getUserVirtural', data);//停止该绿幕视频的使用
  448. if (res.success && res.list && res.list[0]) {
  449. let data = res.list[res.list.length - 1];//获取最新的一个用户的个人形象数据
  450. this.leftList[0].icon = data.virtualBg;
  451. this.leftList[0].url = data.virtualUrl;
  452. this.videoUrl = data.virtualUrl;
  453. if(data.widthHeight){
  454. this.leftList[0].width = data.widthHeight.split('x')[0];
  455. this.leftList[0].height = data.widthHeight.split('x')[1];
  456. }
  457. }
  458. },
  459. async uploadMaterielFile(item, form) {
  460. this.uploadStatus = 0;
  461. this.peopleIndex = 0; //选中第一个
  462. if(this.stopFlag){
  463. return false;
  464. }
  465. var self = this;
  466. let formData = new FormData();
  467. formData.append('file', item.file);
  468. formData.append('brandId', $config.brandId);
  469. formData.append('userId', this.userId);
  470. console.warn("****uploadMaterielFile**",$config.brandId,this.userId)
  471. // alert("***uploadMaterielFile***"+$config.brandId+this.userId);
  472. this.uploadStatus = 1;//上传中
  473. this.showPersonView = false;
  474. this.addSilhouette();//添加剪影视频
  475. let res = await requestConfig('robust_video', formData, true, false,'post',this.uploadProgress,this.cancel)
  476. // alert("***uploadMaterielFile1***"+JSON.stringify(res));
  477. if (axios.isCancel(res)) {//取消上传处理
  478. this.initStatus();//还原初始状态
  479. }else if (res && res.success && res.single) {
  480. this.videoId = res.single;//根据Id查询结果
  481. this.startInterval();//开始轮询获取结果
  482. }else{
  483. this.initStatus();//还原初始状态
  484. }
  485. var videoForm = document.getElementById(form); //获取表单对象
  486. videoForm && videoForm.reset(); // 重置表单
  487. },
  488. async getVideoUrl() {
  489. if(this.stopFlag){
  490. this.stopInterval();
  491. }
  492. if(!this.videoId){
  493. Toast({
  494. message: '请先上传视频',
  495. });
  496. return false;
  497. }
  498. this.count = this.count + 1;
  499. let res = await requestConfig('get_result', {id:this.videoId,userId:this.userId}, true, false,'get')
  500. if(this.stopFlag){
  501. this.stopInterval();
  502. }
  503. if (res.success && res.single) {
  504. this.resultHandle(res.single)
  505. }else{
  506. this.videoUrl = "https://test.static.elab-plus.com/digital_human/f4c16cffae9711ee9853845cf3fb2826.mp4";//视频地址
  507. this.leftList[0].icon = this.videoUrl + "?vframe/jpg/offset/0";
  508. this.leftList[0].url = this.videoUrl;
  509. this.uploadStatus = 4;//处理失败
  510. }
  511. },
  512. //添加剪影视频
  513. addSilhouette(){
  514. let data = {
  515. url:'https://dm.static.elab-plus.com/miniProgram/silhouette1.mp4',
  516. value:'个人形象',
  517. width:'',
  518. height:'',
  519. }
  520. this.aiPeopleChange(data, 'add')
  521. },
  522. //添加用户绿幕视频
  523. addRealVideo(){
  524. let data = {
  525. url:this.videoUrl,
  526. value:'个人形象',
  527. width:this.widthHeight.split('x')[0],
  528. height:this.widthHeight.split('x')[1],
  529. }
  530. this.aiPeopleChange(data, 'add')
  531. },
  532. //上传结果处理
  533. resultHandle(single){
  534. if(!single){
  535. return false;
  536. }
  537. if(single.status=='completed' && single.output){//有结果
  538. this.ktProgress = 100;//抠图进度100%
  539. this.videoUrl = single.output;//视频地址
  540. // this.leftList[0].icon = this.videoUrl + "?vframe/jpg/offset/5";
  541. this.widthHeight = single.widthHeight; //"856x480"
  542. this.leftList[0].icon = single.virtualBg;
  543. this.leftList[0].url = this.videoUrl;
  544. this.leftList[0].width = single.widthHeight.split('x')[0],
  545. this.leftList[0].height = single.widthHeight.split('x')[1],
  546. this.uploadStatus = 3;//处理完毕
  547. // alert("***virtualBg***"+single.virtualBg);
  548. this.stopInterval();//停止轮询
  549. if(this.peopleIndex==0 && this.tabIndex==0){//如果当前在个人形象上,则替换视频
  550. this.addRealVideo();
  551. }
  552. }else{//没有结果
  553. let progress = single.progress;
  554. progress = progress.replace(this.videoId + ':','');
  555. let index = progress.indexOf("|");
  556. progress = progress.substr(0,index);
  557. let numbers = progress.match(/\d+/g)
  558. console.warn("***抠图进度条***",progress);
  559. this.ktProgress = parseFloat(numbers);//提取出来的进度条
  560. if(this.ktProgress>99){
  561. this.ktProgress = 99;
  562. }
  563. }
  564. },
  565. //开始生成AI图的轮询,每隔1s轮询一次
  566. startInterval() {
  567. if(this.timer){
  568. return false;
  569. }
  570. let self = this;
  571. this.count = 0;//轮询次数
  572. this.uploadStatus = 2;//绿幕抠图中
  573. this.getVideoUrl();//获取结果
  574. this.timer = setInterval(()=>{
  575. this.getVideoUrl();//获取结果
  576. },1000);//1秒轮询一次
  577. this.setOutTimer();//设置超时逻辑
  578. },
  579. //设置一个超时逻辑,到底指定时间后停止轮询,当前是90s
  580. setOutTimer() {
  581. var self = this;
  582. if (this.outTimer) {
  583. clearTimeout(this.outTimer)
  584. this.outTimer = null
  585. }
  586. this.outTimer = setTimeout(function() {
  587. if(!self.videoUrl){//没有结果
  588. MessageBox.confirm('',{
  589. title: '提示',
  590. message: '当前AI使用火爆,请继续尝试?',
  591. showCancelButton: true,
  592. confirmButtonText:'继续尝试',
  593. cancelButtonText:'取消等待',
  594. }).then(action => {
  595. console.warn("***MessageBox-action***",action)
  596. if(action == 'confirm'){
  597. // self.confirmHandle(1);
  598. }
  599. }).catch(err=>{
  600. console.warn("***MessageBox-err***",err)
  601. if(err == 'cancel'){
  602. // self.cancelHandle();
  603. }
  604. });
  605. // MessageBox.confirm('确定执行此操作?')
  606. }
  607. self.stopInterval();//停止轮询
  608. }, this.timeOut);
  609. },
  610. //停止轮询
  611. stopInterval() {
  612. if (this.timer) {
  613. clearInterval(this.timer);
  614. this.timer = null;
  615. }
  616. if (this.outTimer) {
  617. clearTimeout(this.outTimer)
  618. this.outTimer = null
  619. }
  620. // this.uploadStatus = 0;//回到初始上传状态
  621. },
  622. showMask(){
  623. //上传过程中,不允许再次上传
  624. if(this.uploadStatus==1 || this.uploadStatus == 2){
  625. return false;
  626. }
  627. this.showPersonView = true;
  628. console.warn("***showMask***",this.showPersonView)
  629. },
  630. //AI数字人切换
  631. selectAction(selItem, index) {
  632. console.log('点击动作111:', selItem, index,this.leftList)
  633. if (this.tabIndex == 0) {
  634. if(!this.leftList[index].url){
  635. return false
  636. }
  637. if (this.peopleIndex == index) { //取消选中
  638. this.aiPeopleChange(this.leftList[this.peopleIndex], 'canel')
  639. this.peopleIndex = -1;
  640. return false
  641. }
  642. } else if (this.tabIndex == 1) {
  643. if (this.petIndex == index) { //取消选中
  644. this.aiPeopleChange(this.rightList[this.petIndex], 'canel')
  645. this.petIndex = -1;
  646. return false
  647. }
  648. } else if (this.tabIndex == 3) {
  649. if (this.musicIndex == index) { //取消选中
  650. this.aiPeopleChange(this.musicList[this.musicIndex], 'canel')
  651. this.musicIndex = -1;
  652. return false
  653. }
  654. }
  655. if (this.$parent.repeatFlag == true) {
  656. Toast({
  657. message: '加载中...请稍后再试',
  658. });
  659. return false
  660. }
  661. if (this.tabIndex == 0) {
  662. this.peopleIndex = index;
  663. this.aiPeopleChange(this.leftList[this.peopleIndex], 'add')
  664. } else if (this.tabIndex == 1) {
  665. this.petIndex = index;
  666. this.aiPeopleChange(this.rightList[this.petIndex], 'add')
  667. } else if (this.tabIndex == 3) {
  668. this.musicIndex = index;
  669. this.aiPeopleChange(this.musicList[this.musicIndex], 'add')
  670. }
  671. },
  672. // // 获取场景信息
  673. // async getRelationInfo() {
  674. // if(!this.$parent.relationId){
  675. // return false;
  676. // }
  677. // var parmas = {
  678. // "relationId": this.$parent.relationId,
  679. // "brandId": $config.brandId,
  680. // }
  681. // let res = await requestConfig('getRelationInfo', parmas)
  682. // this.selectIndex = 0;
  683. // if (res && res.success) {
  684. // this.count = res.single.count;
  685. // }
  686. // },
  687. // 获取瀑布流数据
  688. async getDatalist(type) {
  689. let typeName = "Virtual_Human";
  690. if (type == 0) {
  691. typeName = "Virtual_Human";
  692. } else if (type == 1) {
  693. typeName = "Virtual_Pet";
  694. } else if (type == 3) {
  695. typeName = "Virtual_Music";
  696. // Indicator.close();
  697. }
  698. var parmas = {
  699. "type": typeName,
  700. // "brandId": $config.brandId,
  701. }
  702. let res = await requestConfig('queryEnumList', parmas)
  703. this.selectIndex = 0;
  704. if (res && res.success && res.list) {
  705. let list = res.list;
  706. if (type == 0) {
  707. this.leftList.push({
  708. icon:'',
  709. userUpload:true,
  710. value:'',
  711. url:'',
  712. width:'',
  713. height:'',
  714. })
  715. this.leftList = this.leftList.concat(list);
  716. this.getUserVirtural();
  717. } else if (type == 1) {
  718. this.rightList = list;
  719. } else if (type == 3) {
  720. this.musicList = list;
  721. }
  722. }
  723. },
  724. catchTouchMove: function() {
  725. return false;
  726. },
  727. addRedBox(){//添加红包
  728. console.warn("***添加红包***")
  729. this.$emit("redBox",'add');
  730. this.hasRedBox = true;
  731. },
  732. removeRedBox(){//去除红包
  733. this.$emit("redBox",'canel');
  734. this.hasRedBox = false;
  735. },
  736. setRedBox(){
  737. this.$emit("setRedBox");
  738. },
  739. //AI数字人切换
  740. aiPeopleChange(item, type) {
  741. this.$emit("aiPeopleChange", item, type, this.tabIndex); //通知页面,AI数字人切换了
  742. },
  743. //发布全景
  744. mynavigateFuc(e) {
  745. if (e) {
  746. // if(this.hasRedBox){
  747. // if(!this.$parent.redBoxData.count){
  748. // Toast({
  749. // message: '请输入红包个数!',
  750. // });
  751. // return false;
  752. // }
  753. // if(!this.$parent.redBoxData.money){
  754. // Toast({
  755. // message: '请输入充值金额!',
  756. // });
  757. // return false;
  758. // }
  759. // }
  760. if(this.peopleIndex==0 && (this.uploadStatus ==1 || this.uploadStatus ==2)){
  761. Toast({
  762. message: '请在个人形象上传完成后发布!',
  763. });
  764. return false;
  765. }
  766. if(this.repeartFlag){
  767. return false;
  768. }
  769. this.repeartFlag = true;
  770. let param = {
  771. type: 'CLK', //埋点类型
  772. clkId: 'clk_2cmina_23121301', //点击ID
  773. clkName: 'webgl_public_clk', //点击前往的页面名称
  774. clkParams: {
  775. locusName: "720发布",
  776. }
  777. };
  778. util.trackRequest(param);
  779. let _ps = this.$parent.getPosition();
  780. if (window.__wxjs_environment === 'miniprogram') {
  781. let url = '/extraPackage/pages/aiPublishPage/aiPublishPage?houseId=' + (this.$route.query.houseId || '')
  782. url += '&bgUrl=' + encodeURIComponent(this.$parent.bgUrl)
  783. if(this.peopleIndex>-1){
  784. let people = {
  785. url:this.leftList[this.peopleIndex].url,
  786. ath:_ps.peopleAth,
  787. atv:_ps.peopleAtv,
  788. width:this.leftList[this.peopleIndex].width || '',
  789. height:this.leftList[this.peopleIndex].height || '',
  790. scale:this.$parent.peopleScale,
  791. userUpload:this.peopleIndex==0?true:false,//是否使用了个人形象
  792. }
  793. url += '&AIPeople=' + encodeURIComponent(JSON.stringify(people))
  794. }
  795. if(this.petIndex>-1){
  796. let pet = {
  797. url:this.rightList[this.petIndex].url,
  798. ath:_ps.petAth,
  799. atv:_ps.petAtv,
  800. scale:this.$parent.petScale,
  801. }
  802. url += '&AIPet=' + encodeURIComponent(JSON.stringify(pet))
  803. }
  804. if(this.musicIndex>-1){
  805. let music = {
  806. url:this.musicList[this.musicIndex].url,
  807. title:this.musicList[this.musicIndex].value
  808. };
  809. url += '&bgMusic=' + encodeURIComponent(JSON.stringify(music))
  810. }
  811. if(this.hasRedBox){
  812. let redBox = {
  813. url:'https://dm.static.elab-plus.com/miniProgram/redbox.mp4',
  814. ath:_ps.redBoxAth,
  815. atv:_ps.redBoxAtv,
  816. scale:1,
  817. lottieIndex:this.specialIndex,
  818. // count:this.$parent.redBoxData.count,
  819. // money:this.$parent.redBoxData.money,
  820. // message:this.$parent.redBoxData.message,
  821. }
  822. url += '&redBox=' + encodeURIComponent(JSON.stringify(redBox))
  823. }
  824. console.warn("data:", _ps, url);
  825. wx.miniProgram.navigateTo({
  826. url: url,
  827. complete:(e)=>{
  828. this.repeartFlag = false;
  829. }
  830. })
  831. } else {
  832. console.warn("data:", _ps)
  833. Toast({
  834. message: '敬请期待',
  835. });
  836. }
  837. }
  838. },
  839. }
  840. }
  841. </script>
  842. <style lang="scss" scoped>
  843. @import "./viewAI.scss";
  844. /* @import "@/common/css/common.css"; */
  845. </style>