123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632 |
- <template src="./viewAI.html">
- </template>
- <script>
- const util = require('@/utils/util.js').default;
- import {
- MessageBox
- } from 'mint-ui';
- import {
- Indicator
- } from 'mint-ui';
- import {
- Toast
- } from 'mint-ui';
- import lottie from "lottie-web"; //lottie
- // import commonMethod from '@/common/commonMethod.js';
- // import touchHandle from '@/mixins/touchHandle.js';
- // import requestConfig from '@/static/lib/requestConfig';
- export default {
- data: function() {
- return {
- leftList: [],
- rightList: [],
- musicList: [], //音乐列表
- dataList: [],
- tabIndex: 0, //当前选中的tab序号
- selectIndex: -1,
- peopleIndex: -1,
- petIndex: -1,
- musicIndex: -1,
- specialIndex: 0,
- specialList:[
- {
- id:1,
- url:'https://dm.static.elab-plus.com/miniProgram/lottieJson/gold.json',
- title:'金光闪闪',
- },
- {
- id:2,
- url:'https://dm.static.elab-plus.com/miniProgram/lottieJson/fireworks.json',
- title:'烟花',
- },
- {
- id:3,
- url:'https://dm.static.elab-plus.com/miniProgram/lottieJson/coloreRibbon.json',
- title:'彩带',
- },
- ],
- hasRedBox:false, //是否添加了红包
- limit:20,
- videoId:'', //上传视频的id
- videoUrl:'', //处理好的视频地址
- progress:0, //进度条
- ktProgress:0, //抠图进度条
- showPersonView:false, //是否显示个人形象提示弹窗
- showPopView:false, //是否显示确认取消框
- uploadStatus:0, //视频处理的状态 0 未开始,1 上传中,2绿幕抠图中-服务端处理中,3处理成功 4 处理失败
- count:0, //结果请求次数
- timeOut:90000, //超时时间
- outTimer:null, //延时处理对象
- timer:null, //轮询对象
- widthHeight:'', //用户上传视频尺寸
- stopFlag:false, //停止上传动作
- cancelTokenSource:null, //取消上传的操作对象
- }
- },
- props: {
- },
- // mixins: [touchHandle],
- async mounted() {
- // await this.getCityHouseList();
- console.warn("***viewAI***")
- Indicator.open('加载中...');
- this.getDatalist(0);
- this.getDatalist(1);
- this.getDatalist(3);
- },
- computed: {
- userId() {
- return this.$store.state.userId;
- },
- },
- // 页面被展示时执行
- onPageShow: function() {
- },
- //页面被隐藏时执行
- onPageHide: function() {
- // console.warn("***detached-hide***")
- },
- methods: {
- format(percentage) {
- let text = "上传中";
- if(this.uploadStatus==1){
- text = "上传中";
- }else if(this.uploadStatus==2){
- text = "抠图中";
- }
- return `${text}\n${percentage}%`;
- },
- resolveIndex(index) {
- this.selectIndex = index || 0;
- },
- specialChange(index) {
- if (this.specialIndex == index) {
- return false;
- }
- this.specialIndex = index;
- this.$nextTick(() => {
- // 播放lottie动画
- lottie.destroy("markLoading");
- var element = document.getElementById("special-img");
- this.anim = lottie.loadAnimation({
- container: element,
- name: "markLoading",
- renderer: "svg",
- loop: true,
- autoplay: true,
- path: this.specialList[this.specialIndex].url, //动画json
- });
- });
- },
- tabChange(index) {
- if (this.tabIndex == index) {
- return false;
- }
- if (this.$parent.repeatFlag == true) {
- Toast({
- message: '加载中...请稍后再试',
- });
- return false
- }
- this.tabIndex = index;
- this.$emit("tabChange", this.tabIndex); //通知页面,户型大类发生了变更
- if(this.tabIndex==2 && this.specialIndex>-1){
- this.$nextTick(() => {
- // 播放lottie动画
- lottie.destroy("markLoading");
- var element = document.getElementById("special-img");
- this.anim = lottie.loadAnimation({
- container: element,
- name: "markLoading",
- renderer: "svg",
- loop: true,
- autoplay: true,
- path: this.specialList[this.specialIndex].url, //动画json
- });
- });
- }
- },
- initStatus(){
- this.progress = 0;
- this.ktProgress = 0;
- this.count = 0;
- this.videoUrl = '';
- this.widthHeight = '';
- this.leftList[0].icon = '';
- this.leftList[0].url = '';
- this.uploadStatus = 0;//处理完毕
- },
- uploadImgObj(e,form,type=1){
- this.stopFlag = false;//上传开始时,开启上传
- if(type==2){
- this.initStatus();//重置上传状态到初始值
- }
- this.uploadStatus = 0;
- this.peopleIndex = 0; //选中第一个
- //上传图片
- var file = e.target.files[0];
- var fileSize = file.size / 1024 / 1024;
- if (!/\.(MP4|mp4)$/.test(e.target.value)) {
- this.$message.warning('文件片类型必须是MP4');
- var videoForm = document.getElementById(form); //获取表单对象
- videoForm && videoForm.reset(); // 重置表单
- return false
- }
- if (fileSize > this.limit) {
- this.$message.warning('您的上传的视频过大,请低于' + this.limit + 'MB');
- var videoForm = document.getElementById(form); //获取表单对象
- videoForm && videoForm.reset(); // 重置表单
- return false
- }
- if (file.name.length > 100) {
- this.$message.warning('文件名过长,请不要超过100个字符');
- var videoForm = document.getElementById(form); //获取表单对象
- videoForm && videoForm.reset(); // 重置表单
- return false;
- }
- let reader = new FileReader();
- reader.onload = (event) => {
- let video = document.createElement('video');
- video.onloadedmetadata = (event) => {
- let duration = video.duration;
- let width = video.videoWidth;
- let height = video.videoHeight;
- // this.videoWidth = width;
- // this.videoHeight = height;
- console.warn('视频时长:', duration,this.stopFlag);
- console.warn('视频尺寸:x:', width, 'y:', height);
- if (duration > 20) {
- this.$message.warning('您的上传的视频过长,请低于20s');
- var videoForm = document.getElementById(form); //获取表单对象
- videoForm && videoForm.reset(); // 重置表单
- return false
- }else{
- if(!this.stopFlag){
- var item = {};
- item.file = file;
- console.warn("***uploadImgObj***",file)
- this.uploadMaterielFile(item, form); //正常上传图片
- }
- }
- };
- video.src = event.target.result;
- };
- reader.readAsDataURL(file);
- },
- //视频上传进度处理
- uploadProgress(e){
- this.progress = Math.round((e.loaded / e.total) * 100);//loaded已经加载的
- console.warn("***uploadProgress***",this.progress)
- },
- //显示弹窗提示框
- showPopViewHandle(){
- this.showPopView = true;//弹出确认框;
- },
- //取消上传
- cancel(cancelTokenSource){
- this.cancelTokenSource = cancelTokenSource;
- console.warn("***取消上传函数定义***")
- },
- //停止上传
- stopUpload(){
- this.showPopView = false;//弹出确认框;
- this.stopFlag = true;//停止上传标志打开
- if(this.uploadStatus == 1){
- this.cancelTokenSource.cancel('上传已取消');//通知取消上传
- }
- else if(this.uploadStatus==2 || this.uploadStatus==3){//绿幕抠图中 或者已经完成
- let data = {
- userId:this.userId,
- brandId: $config.brandId,
- processStatus:'canceled',
- virtualNo:this.videoId,
- }
- requestConfig('addUserVirtural', data);//停止该绿幕视频的使用
- this.initStatus();//还原初始状态
- }
- let data = {
- url:'https://dm.static.elab-plus.com/miniProgram/silhouette1.mp4',
- value:'个人形象',
- width:'',
- height:'',
- }
- this.aiPeopleChange(data, 'canel')
- this.peopleIndex = -1;
- },
- //获取用户上传的个人形象
- async getUserVirtural() {
- let data = {
- userId:this.userId,
- brandId: $config.brandId,
- processStatus:'completed',
- }
- let res = await requestConfig('getUserVirtural', data);//停止该绿幕视频的使用
- if (res.success && res.list && res.list[0]) {
- let data = res.list[res.list.length - 1];//获取最新的一个用户的个人形象数据
- this.leftList[0].icon = data.virtualBg;
- this.leftList[0].url = data.virtualUrl;
- this.videoUrl = data.virtualUrl;
- if(data.widthHeight){
- this.leftList[0].width = data.widthHeight.split('x')[0];
- this.leftList[0].height = data.widthHeight.split('x')[1];
- }
- }
- },
- async uploadMaterielFile(item, form) {
- if(this.stopFlag){
- return false;
- }
- var self = this;
- let formData = new FormData();
- formData.append('file', item.file);
- formData.append('brandId', $config.brandId);
- formData.append('userId', this.userId);
- console.warn("***uploadMaterielFile***");
- this.uploadStatus = 1;//上传中
- this.showPersonView = false;
- this.addSilhouette();//添加剪影视频
- let res = await requestConfig('robust_video', formData, true, false,'post',this.uploadProgress,this.cancel)
- if (axios.isCancel(res)) {//取消上传处理
- this.initStatus();//还原初始状态
- }else if (res.success && res.single) {
- this.videoId = res.single;//根据Id查询结果
- this.startInterval();//开始轮询获取结果
- }
- var videoForm = document.getElementById(form); //获取表单对象
- videoForm && videoForm.reset(); // 重置表单
- },
- async getVideoUrl() {
- if(this.stopFlag){
- this.stopInterval();
- }
- if(!this.videoId){
- Toast({
- message: '请先上传视频',
- });
- return false;
- }
- this.count = this.count + 1;
- let res = await requestConfig('get_result', {id:this.videoId,userId:this.userId}, true, false,'get')
- if(this.stopFlag){
- this.stopInterval();
- }
- if (res.success && res.single) {
- this.resultHandle(res.single)
- }else{
- this.videoUrl = "https://test.static.elab-plus.com/digital_human/f4c16cffae9711ee9853845cf3fb2826.mp4";//视频地址
- this.leftList[0].icon = this.videoUrl + "?vframe/jpg/offset/0";
- this.leftList[0].url = this.videoUrl;
- this.uploadStatus = 4;//处理失败
- }
- },
- //添加剪影视频
- addSilhouette(){
- let data = {
- url:'https://dm.static.elab-plus.com/miniProgram/silhouette1.mp4',
- value:'个人形象',
- width:'',
- height:'',
- }
- this.aiPeopleChange(data, 'add')
- },
- //添加用户绿幕视频
- addRealVideo(){
- let data = {
- url:this.videoUrl,
- value:'个人形象',
- width:this.widthHeight.split('x')[0],
- height:this.widthHeight.split('x')[1],
- }
- this.aiPeopleChange(data, 'add')
- },
- //上传结果处理
- resultHandle(single){
- if(!single){
- return false;
- }
- if(single.status=='completed' && single.output){//有结果
- this.ktProgress = 100;//抠图进度100%
- this.videoUrl = single.output;//视频地址
- // this.leftList[0].icon = this.videoUrl + "?vframe/jpg/offset/5";
- this.widthHeight = single.widthHeight; //"856x480"
- this.leftList[0].icon = single.virtualBg;
- this.leftList[0].url = this.videoUrl;
- this.leftList[0].width = single.widthHeight.split('x')[0],
- this.leftList[0].height = single.widthHeight.split('x')[1],
- this.uploadStatus = 3;//处理完毕
- this.stopInterval();//停止轮询
- this.addRealVideo();
- }else{//没有结果
- let progress = single.progress;
- progress = progress.replace(this.videoId + ':','');
- let index = progress.indexOf("|");
- progress = progress.substr(0,index);
- console.warn("***抠图进度条***",progress);
- this.ktProgress = parseFloat(progress);//提取出来的进度条
- if(this.ktProgress>99){
- this.ktProgress = 99;
- }
- }
- },
- //开始生成AI图的轮询,每隔1s轮询一次
- startInterval() {
- if(this.timer){
- return false;
- }
- let self = this;
- this.count = 0;//轮询次数
- this.uploadStatus = 2;//绿幕抠图中
- this.getVideoUrl();//获取结果
- this.timer = setInterval(()=>{
- this.getVideoUrl();//获取结果
- },1000);//1秒轮询一次
- this.setOutTimer();//设置超时逻辑
- },
- //设置一个超时逻辑,到底指定时间后停止轮询,当前是90s
- setOutTimer() {
- var self = this;
- if (this.outTimer) {
- clearTimeout(this.outTimer)
- this.outTimer = null
- }
- this.outTimer = setTimeout(function() {
- if(!self.videoUrl){//没有结果
- MessageBox.confirm('',{
- title: '提示',
- message: '当前AI使用火爆,请继续尝试?',
- showCancelButton: true,
- confirmButtonText:'继续尝试',
- cancelButtonText:'取消等待',
- }).then(action => {
- console.warn("***MessageBox-action***",action)
- if(action == 'confirm'){
- // self.confirmHandle(1);
- }
- }).catch(err=>{
- console.warn("***MessageBox-err***",err)
- if(err == 'cancel'){
- // self.cancelHandle();
- }
- });
- // MessageBox.confirm('确定执行此操作?')
- }
- self.stopInterval();//停止轮询
- }, this.timeOut);
- },
- //停止轮询
- stopInterval() {
- if (this.timer) {
- clearInterval(this.timer);
- this.timer = null;
- }
- if (this.outTimer) {
- clearTimeout(this.outTimer)
- this.outTimer = null
- }
- // this.uploadStatus = 0;//回到初始上传状态
- },
-
- showMask(){
- this.showPersonView = true;
- console.warn("***showMask***",this.showPersonView)
- },
- //AI数字人切换
- selectAction(selItem, index) {
- console.log('点击动作111:', selItem, index,this.leftList)
- if (this.tabIndex == 0) {
- if(!this.leftList[index].url){
- return false
- }
- if (this.peopleIndex == index) { //取消选中
- this.aiPeopleChange(this.leftList[this.peopleIndex], 'canel')
- this.peopleIndex = -1;
- return false
- }
- } else if (this.tabIndex == 1) {
- if (this.petIndex == index) { //取消选中
- this.aiPeopleChange(this.rightList[this.petIndex], 'canel')
- this.petIndex = -1;
- return false
- }
- } else if (this.tabIndex == 3) {
- if (this.musicIndex == index) { //取消选中
- this.aiPeopleChange(this.musicList[this.musicIndex], 'canel')
- this.musicIndex = -1;
- return false
- }
- }
- if (this.$parent.repeatFlag == true) {
- Toast({
- message: '加载中...请稍后再试',
- });
- return false
- }
- if (this.tabIndex == 0) {
- this.peopleIndex = index;
- this.aiPeopleChange(this.leftList[this.peopleIndex], 'add')
- } else if (this.tabIndex == 1) {
- this.petIndex = index;
- this.aiPeopleChange(this.rightList[this.petIndex], 'add')
- } else if (this.tabIndex == 3) {
- this.musicIndex = index;
- this.aiPeopleChange(this.musicList[this.musicIndex], 'add')
- }
- },
- // 获取瀑布流数据
- async getDatalist(type) {
- let typeName = "Virtual_Human";
- if (type == 0) {
- typeName = "Virtual_Human";
- } else if (type == 1) {
- typeName = "Virtual_Pet";
- } else if (type == 3) {
- typeName = "Virtual_Music";
- Indicator.close();
- }
- var parmas = {
- "type": typeName,
- // "brandId": $config.brandId,
- }
- let res = await requestConfig('queryEnumList', parmas)
- this.selectIndex = 0;
- if (res && res.success && res.list) {
- let list = res.list;
- if (type == 0) {
- this.leftList.push({
- icon:'',
- userUpload:true,
- value:'',
- url:'',
- width:'',
- height:'',
- })
- this.leftList = this.leftList.concat(list);
- this.getUserVirtural();
- } else if (type == 1) {
- this.rightList = list;
- } else if (type == 3) {
- this.musicList = list;
- }
- }
- },
- catchTouchMove: function() {
- return false;
- },
- // hideOrShowActor(type){
- // this.$emit('hideOrShowActor',type);//隐藏所有视角
- // },
- addRedBox(){//添加红包
- this.$emit("redBox",'add');
- this.hasRedBox = true;
- },
- removeRedBox(){//去除红包
- this.$emit("redBox",'canel');
- this.hasRedBox = false;
- },
- setRedBox(){
- this.$emit("setRedBox");
- },
- //AI数字人切换
- aiPeopleChange(item, type) {
- this.$emit("aiPeopleChange", item, type, this.tabIndex); //通知页面,AI数字人切换了
- },
- //发布全景
- mynavigateFuc(e) {
- if (e) {
- if(this.hasRedBox){
- if(!this.$parent.redBoxData.count){
- Toast({
- message: '请输入红包个数!',
- });
- return false;
- }
- if(!this.$parent.redBoxData.money){
- Toast({
- message: '请输入充值金额!',
- });
- return false;
- }
- }
- if(this.peopleIndex==0 && (this.uploadStatus ==1 || this.uploadStatus ==2)){
- Toast({
- message: '请在个人形象上传完成后发布!',
- });
- return false;
- }
- let param = {
- type: 'CLK', //埋点类型
- clkId: 'clk_2cmina_23121301', //点击ID
- clkName: 'webgl_public_clk', //点击前往的页面名称
- clkParams: {
- locusName: "720发布",
- }
- };
- util.trackRequest(param);
- let _ps = this.$parent.getPosition();
- if (window.__wxjs_environment === 'miniprogram') {
- let url = '/extraPackage/pages/aiPublishPage/aiPublishPage?houseId=' + (this.$route.query.houseId || '')
- url += '&bgUrl=' + encodeURIComponent(this.$parent.bgUrl)
- if(this.peopleIndex>-1){
- let people = {
- url:this.leftList[this.peopleIndex].url,
- ath:_ps.peopleAth,
- atv:_ps.peopleAtv,
- width:this.leftList[this.peopleIndex].width || '',
- height:this.leftList[this.peopleIndex].height || '',
- scale:this.$parent.peopleScale,
- userUpload:this.peopleIndex==0?true:false,//是否使用了个人形象
- }
- url += '&AIPeople=' + encodeURIComponent(JSON.stringify(people))
- }
- if(this.petIndex>-1){
- let pet = {
- url:this.rightList[this.petIndex].url,
- ath:_ps.petAth,
- atv:_ps.petAtv,
- scale:this.$parent.petScale,
- }
- url += '&AIPet=' + encodeURIComponent(JSON.stringify(pet))
- }
- if(this.musicIndex>-1){
- let music = {
- url:this.musicList[this.musicIndex].url,
- title:this.musicList[this.musicIndex].value
- };
- url += '&bgMusic=' + encodeURIComponent(JSON.stringify(music))
- }
- if(this.hasRedBox){
- let redBox = {
- url:'https://dm.static.elab-plus.com/miniProgram/redbox.mp4',
- ath:_ps.redBoxAth,
- atv:_ps.redBoxAtv,
- scale:1,
- lottieIndex:this.specialIndex,
- count:this.$parent.redBoxData.count,
- money:this.$parent.redBoxData.money,
- message:this.$parent.redBoxData.message,
- }
- url += '&redBox=' + encodeURIComponent(JSON.stringify(redBox))
- }
- console.warn("data:", _ps, url)
- wx.miniProgram.navigateTo({
- url: url
- })
- } else {
- console.warn("data:", _ps)
- Toast({
- message: '敬请期待',
- });
- }
- }
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- @import "./viewAI.scss";
- /* @import "@/common/css/common.css"; */
- </style>
|