viewMask.vue 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  1. <template src="./viewMask.html">
  2. </template>
  3. <script>
  4. const util = require('@/utils/util.js').default;
  5. import router from "@/router";
  6. import { MessageBox } from 'mint-ui';
  7. import spaceTypes from '@/static/spaceTypesIE.js';
  8. // const config = require('@/services/url$config.js');
  9. import touchHandle from '@/mixins/touchHandle.js';
  10. import {
  11. setStorage,
  12. getStorage,
  13. } from '@/utils/localStorage';
  14. // import requestConfig from '@/static/lib/requestConfig';
  15. // const app = getApp(); //获取应用实例
  16. export default {
  17. mixins: [touchHandle],
  18. data: function() {
  19. return {
  20. currentIndex:0, //当前看到的图片序号
  21. showAIImage: false,//是否显示当前AI结果集合 默认不显示,因为没有
  22. aiImagesList:[
  23. ],//AI生成的图片列表
  24. styleList: [], //风格列表数据
  25. curStyleIndex: 0, //当前选中的风格序号
  26. aiFlag:false,
  27. aiImage: "",
  28. inputBase64Url: "",
  29. aiPicId: "", // 图生图任务ID
  30. randomTimer:null,
  31. timer: null,
  32. outTimer: null,
  33. imageWidth: 750,
  34. imageHeight: 448,
  35. showAIFlag:false,//继续生成状态切换标志
  36. checked:false,
  37. shottingImg:'',
  38. count:0,
  39. random:1,
  40. // disableAble:false,
  41. myloading:false,
  42. loadingMsg:'',
  43. screenWidth:0,
  44. screenHeight:0,
  45. modelType:2, //当前模型类型,1指创意设计 2指精准设计 默认2
  46. themeIndex:0,
  47. themeList:[
  48. {
  49. id:1,
  50. text:'默认',
  51. prot:'',
  52. },
  53. {
  54. id:2,
  55. leftColor:'#F4EBDE',
  56. rightColor:'#C1C9B4',
  57. text:'莫兰素雅',
  58. prot:'Soft grays, warm earth tones, subtle blues, soft pinks,',
  59. },
  60. {
  61. id:3,
  62. leftColor:'#1F1F1F',
  63. rightColor:'#FFFFFF',
  64. text:'经典黑白',
  65. prot:'Classic black and pure white,',
  66. },
  67. {
  68. id:4,
  69. leftColor:'#6FA5BE',
  70. rightColor:'#E2CCC5',
  71. text:'海岸珊瑚',
  72. prot:'Deep ocean blue paired with vibrant coral red,',
  73. },
  74. {
  75. id:5,
  76. leftColor:'#849059',
  77. rightColor:'#E6CEB4',
  78. text:'森林璀璨',
  79. prot:'Deep forest green paired with luxurious gold,'
  80. },
  81. {
  82. id:6,
  83. leftColor:'#A1BACB',
  84. rightColor:'#E6DFD8',
  85. text:'梦幻静谧',
  86. prot:'Dreamy powder blue paired with neutral gray,'
  87. },
  88. {
  89. id:7,
  90. leftColor:'#303B2B',
  91. rightColor:'#D8C8A6',
  92. text:'自然和谐',
  93. prot:'Natural olive green paired with warm beige,'
  94. },
  95. {
  96. id:8,
  97. leftColor:'#652C30',
  98. rightColor:'#D5C3B0',
  99. text:'醇酒乳香',
  100. prot:'Rich burgundy paired with soft cream,'
  101. },
  102. {
  103. id:9,
  104. leftColor:'#E3C7C5',
  105. rightColor:'#EDE4DB',
  106. text:'雅致浪漫',
  107. prot:'Understated taupe paired with romantic pink,'
  108. },
  109. {
  110. id:10,
  111. leftColor:'#2C3C6E',
  112. rightColor:'#F0DBBD',
  113. text:'夜空璀璨',
  114. prot:'Elegant navy blue paired with glamorous gold,'
  115. },
  116. {
  117. id:11,
  118. leftColor:'#ACC9A1',
  119. rightColor:'#E6DCC6',
  120. text:'复古翠绿',
  121. prot:'Vintage tan paired with vibrant green,'
  122. },
  123. {
  124. id:12,
  125. leftColor:'#AAA8A7',
  126. rightColor:'#D8A176',
  127. text:'暖阳灰影',
  128. prot:'Warm orange paired with cool gray,'
  129. },
  130. {
  131. id:13,
  132. leftColor:'#413D41',
  133. rightColor:'#D1B687',
  134. text:'耀眼黑金',
  135. prot:'black and gold,'
  136. },
  137. ],
  138. timeOut:20000, //超时时间
  139. subType:0,
  140. currentImg:null,
  141. reqList:[
  142. {
  143. model:'batouresearch/sdxl-controlnet-lora',
  144. level:'5',
  145. aiPicId:'',
  146. resultImg:'',
  147. }
  148. ],
  149. reqListReset:[
  150. {
  151. model:'deployments/elabgroup/elab-sdxl-controlnet-lora',
  152. level:'3',
  153. aiPicId:'',
  154. resultImg:'',
  155. },{
  156. model:'batouresearch/sdxl-controlnet-lora',
  157. level:'5',
  158. aiPicId:'',
  159. resultImg:'',
  160. }
  161. ],
  162. // dialogVisible: false,
  163. // dialogAIVisible: false,
  164. datalist:[],
  165. curSpaceId:'',
  166. }
  167. },
  168. props:{
  169. spaceObj: {
  170. type: Object,
  171. default: null,
  172. },
  173. spaceList: {
  174. type: [Array ,Object],
  175. default: [],
  176. },
  177. layoutList:{
  178. type: [Array ,Object],
  179. default: [],
  180. }
  181. },
  182. watch: {
  183. spaceObj(newVal, oldVal) {
  184. if (newVal == null) {
  185. return;
  186. }
  187. console.log("当前空间数据view-mark-watch:", newVal,newVal.layoutSpaceName,newVal.layoutSpaceType);
  188. this.getAiBeautyFamily();
  189. // this.curSpaceArea = parseFloat(
  190. // (newVal.spaceWidth * newVal.spaceHeight) / 10000
  191. // ).toFixed(2);
  192. // this.getOverallArrangementDetailsList();
  193. },
  194. spaceList(newVal, oldVal) {
  195. if (newVal == null) {
  196. return;
  197. }
  198. console.log("当前空间数据spaceList-watch:", newVal);
  199. if(newVal && newVal.length>0){
  200. this.datalist = [];
  201. newVal.forEach(it=>{
  202. if(it.spaceName && !it.isSizeLock){
  203. this.datalist.push(it);
  204. }
  205. })
  206. }
  207. },
  208. layoutList(newVal, oldVal) {
  209. if (newVal == null) {
  210. return;
  211. }
  212. this.updataLable();
  213. },
  214. },
  215. filters:{
  216. // spaceTypeFilter(type){
  217. // let name = spaceTypes[type - 1];
  218. // return name || '-'
  219. // },
  220. },
  221. mounted() {//组件挂载时事件
  222. // console.warn("***mounted-nav***",this.seedItem)
  223. // if(this.seedItem){
  224. // this.title = this.seedItem.seedText;
  225. // }
  226. // wx.checkJsApi({
  227. // jsApiList: ['previewImage'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
  228. // success: function(res) {
  229. // // 以键值对的形式返回,可用的api值true,不可用为false
  230. // // 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
  231. // console.warn("checkJsApi",res)
  232. // // alert('su'+ JSON.stringify(res))
  233. // },
  234. // fail:(err)=>{
  235. // console.warn("checkJsApi-err",err)
  236. // // alert('err'+ JSON.stringify(err) )
  237. // }
  238. // })
  239. this.screenWidth = window.screen.width;
  240. this.screenHeight = window.screen.height;
  241. if(window.innerWidth && window.screen.width){
  242. this.screenWidth = Math.min(window.innerWidth,window.screen.width)
  243. }
  244. if(window.innerHeight && window.screen.height){
  245. this.screenHeight = Math.min(window.innerHeight,window.screen.height)
  246. }
  247. },
  248. beforeDestroy:function(){
  249. console.warn("***beforeDestroy***");//更新到页面上的数据
  250. this.stopInterval();
  251. },
  252. computed: {
  253. aiData() {
  254. return this.$store.state.aiData;
  255. },
  256. curHouseObj() {
  257. return this.$store.state.curHouseObj;
  258. },
  259. userId() {
  260. return this.$store.state.userId;
  261. },
  262. },
  263. methods:{
  264. //更改空间显示名称 X空间 类型 根据布局所属类型来显示
  265. updataLable(){
  266. let list = this.layoutList;
  267. this.datalist.forEach(lable=>{
  268. if(lable.spaceType==15){
  269. let layoutId = lable.layoutId;
  270. let layout = list.find(it=>it.id == layoutId);
  271. if(layout){
  272. let name = spaceTypes[layout.type - 1];
  273. lable.text = name;
  274. }
  275. }else{
  276. let name = spaceTypes[lable.spaceType - 1];
  277. lable.text = name;
  278. }
  279. })
  280. this.$forceUpdate()
  281. console.warn("***updataLable***",this.datalist)
  282. },
  283. swiperChangeImg(e){
  284. this.currentIndex = e.detail?e.detail.current:e;
  285. this.checked = this.aiImagesList[this.currentIndex].checked;
  286. console.warn("***swiperChangeImg***",this.checked);//更新到页面上的数据
  287. },
  288. //切换空间
  289. changeSpace(item){
  290. this.$parent.changeSpace(item.spaceId);
  291. let param = {
  292. type: 'CLK', //埋点类型
  293. clkId: 'clk_2cmina_23080417', //点击ID
  294. clkName: 'changeangle_clk', //点击前往的页面名称
  295. clkParams: {
  296. locusName: "空间切换",
  297. locusValue:item.text,
  298. spaceId:item.spaceId,
  299. type:item.text,
  300. }
  301. };
  302. util.trackRequest(param);
  303. },
  304. //视角切换
  305. switchActor(){
  306. // this.$parent.clearHandle()
  307. this.$emit('switchActor');
  308. this.showAIImage = false;//隐藏AI结果集合-执行切换视角
  309. let index = this.$parent.currentActor.userIndex;//当前视角的序号
  310. let nextIndex = (index + 1) % this.$parent.actors.length;
  311. let param = {
  312. type: 'CLK', //埋点类型
  313. clkId: 'clk_2cmina_23080417', //点击ID
  314. clkName: 'changeangle_clk', //点击前往的页面名称
  315. clkParams: {
  316. locusName: "视角切换",
  317. type:this.$parent.actors[nextIndex].actorEum
  318. }
  319. };
  320. util.trackRequest(param);
  321. },
  322. showOrHideWebGl(){
  323. // this.$parent.clearHandle()
  324. this.showAIImage = !this.showAIImage;
  325. let param = {
  326. type: 'CLK', //埋点类型
  327. clkId: 'clk_2cmina_23080415', //点击ID
  328. clkName: 'contrast_clk', //点击前往的页面名称
  329. clkParams: {
  330. locusName: "对比",
  331. }
  332. };
  333. util.trackRequest(param);
  334. },
  335. //空间或者风格切换
  336. selectAction(selItem,type,index) {
  337. console.log('点击动作111:', selItem,type,index)
  338. var self = this;
  339. if(this.themeIndex == index){
  340. return false
  341. }
  342. this.themeIndex = index;
  343. let param = {
  344. type: 'CLK', //埋点类型
  345. clkId: 'clk_2cmina_23112701', //点击ID
  346. clkName: 'AIstyle_theme_clk', //点击前往的页面名称
  347. clkParams: {
  348. locusName: "AI 主题",
  349. type:this.themeList[this.themeIndex].text
  350. }
  351. };
  352. util.trackRequest(param);
  353. },
  354. //切换模式
  355. changeModel(){
  356. this.modelType = (this.modelType + 1) >2 ? 1 : 2;
  357. },
  358. //保存到相册
  359. save() {
  360. //表示canvas正在绘制,不能进行保存
  361. if (!this.aiImagesList || this.aiImagesList.length==0) {
  362. return false;
  363. }
  364. var _resultImg = this.aiImagesList[this.currentIndex].image;
  365. //正在选择照片,不能生效
  366. if (!_resultImg || _resultImg.length==0) {
  367. this.showToast("请选中图片后再试!");
  368. return false;
  369. }
  370. var para = {
  371. type: 'CLK', //埋点类型
  372. clkId: 'clk_2cmina_56', //点击ID,固定
  373. clkName: "share-savepic", //点击名称
  374. expand: {
  375. "resultImg": (_resultImg || ""),
  376. },
  377. }
  378. util.trackRequest(para);
  379. if(navigator.userAgent.toLocaleLowerCase().includes('micromessenger')){
  380. this.$message("请长按图片保存!");
  381. }else{
  382. this.saveImageHandle(_resultImg);
  383. }
  384. },
  385. downloadIamge(imgsrc) { //下载图片地址和图片名
  386. var fileName = "4DImage" + util.formatDate(new Date(), "yyyyMMddhhmmss") + '.jpg';
  387. const image = new Image();
  388. // 解决跨域 Canvas 污染问题
  389. image.setAttribute("crossOrigin", "anonymous");
  390. image.onload = ()=> {
  391. // let canvas = document.createElement("canvas");
  392. // canvas.width = image.width;
  393. // canvas.height = image.height;
  394. // const context = canvas.getContext("2d");
  395. // context.drawImage(image, 0, 0, image.width, image.height);
  396. // const url = canvas.toDataURL("image/jpg"); //得到图片的base64编码数据
  397. const a = document.createElement("a"); // 生成一个a元素
  398. const event = new MouseEvent("click"); // 创建一个单击事件
  399. a.download = fileName || "photo"; // 设置图片名称
  400. a.href = imgsrc; // 将生成的URL设置为a.href属性
  401. a.dispatchEvent(event); // 触发a的单击事件
  402. this.showToast("保存成功!");
  403. };
  404. image.src = imgsrc;
  405. },
  406. saveImageHandle(_resultImg){
  407. let param = {
  408. type: 'CLK', //埋点类型
  409. clkId: 'clk_2cmina_23080414', //点击ID
  410. clkName: 'download_clk', //点击前往的页面名称
  411. clkParams: {
  412. locusName: "下载",
  413. img:_resultImg
  414. }
  415. };
  416. util.trackRequest(param);
  417. this.downloadIamge(_resultImg);
  418. },
  419. //点赞喜欢
  420. changeAIImg() {
  421. // let lastPage = getCurrentPages()[getCurrentPages().length - 2] ? getCurrentPages()[getCurrentPages().length - 2].$vm : null;
  422. this.checked = !this.checked;//变更选项
  423. this.aiImagesList[this.currentIndex].checked = this.checked;
  424. console.warn("***changeAIImg***",this.checked,this.aiData)
  425. if(this.aiData){//给上一个页面回传生成的数据
  426. let space = this.aiData.find(it=>{
  427. return it.spaceId == this.spaceObj.spaceId
  428. })
  429. if(space){
  430. let cind = space.aiImagesList.find(it=>it.image == this.aiImagesList[this.currentIndex].image)
  431. if(cind){
  432. cind.checked = this.checked;
  433. }
  434. }
  435. }
  436. if(this.checked){
  437. let param = {
  438. type: 'CLK', //埋点类型
  439. clkId: 'clk_2cmina_23080418', //点击ID
  440. clkName: 'chooseprogramme_clk', //点击前往的页面名称
  441. clkParams: {
  442. locusName: "选定风格/视角",
  443. style:this.styleList[this.curStyleIndex].styleName,
  444. img:this.aiImagesList[this.currentIndex].image,
  445. }
  446. };
  447. util.trackRequest(param);
  448. }
  449. },
  450. rightScroll(){//右滑
  451. if(this.currentIndex <= (this.aiImagesList.length - 1) && this.currentIndex > 0){
  452. // this.currentIndex --;
  453. this.$refs.carousel.prev();
  454. }
  455. },
  456. leftScroll(){//继续生成
  457. if(this.currentIndex != this.aiImagesList.length - 1){
  458. if(this.currentIndex<this.aiImagesList.length - 1){
  459. // this.currentIndex ++;
  460. this.$refs.carousel.next();
  461. }
  462. return false;
  463. }
  464. console.log("***leftScroll***",this.currentIndex,this.aiImagesList.length)
  465. this.aiSubmit(2);//继续生成下一张
  466. },
  467. //预览图片-使用微信自带的预览功能,即H5中不可用
  468. previewAction() {
  469. if(wx && typeof(wx.previewImage)=='function'){
  470. let imglist = this.aiImagesList.map(it=>it.image);
  471. wx.previewImage({
  472. current: this.currentIndex,
  473. urls: imglist,
  474. success: (res) => {
  475. console.log('图片预览:', res);
  476. },
  477. fail:(err)=>{
  478. console.warn('图片预览-err:', res);
  479. }
  480. })
  481. }
  482. },
  483. mynavigateFuc(e) {
  484. if (e) {
  485. // this.$parent.clearHandle();
  486. let param = {
  487. type: 'CLK', //埋点类型
  488. clkId: 'clk_2cmina_23080408', //点击ID
  489. clkName: 'WeCom_clk', //点击前往的页面名称
  490. clkParams: {
  491. locusName: "联系定制",
  492. }
  493. };
  494. util.trackRequest(param);
  495. if(window.__wxjs_environment === 'miniprogram'){
  496. wx.miniProgram.navigateTo({url: '/pages/transfer/transfer?event=openCustomerServiceChat&houseId='+this.$store.state.houseId})
  497. }else{
  498. this.$message.warning("敬请期待");
  499. }
  500. }
  501. },
  502. catchTapEvent:function(){
  503. return false;
  504. },
  505. //获取AI风格列表
  506. async getAiBeautyFamily() {
  507. // const spaceName = this.spaceTypes[this.spaceObj.spaceType - 1].title;
  508. let res = await requestConfig("getHardboundEffects", {
  509. "houseId": this.$route.query.houseId || this.$store.state.houseId,
  510. "spaceType": this.spaceObj.layoutSpaceType || this.spaceObj.spaceType,
  511. "spaceName": this.spaceObj.layoutSpaceName || this.spaceObj.spaceName,
  512. });
  513. this.styleList = [];
  514. // alert("***getAiBeautyFamily-res***"+JSON.stringify(res))
  515. if (res.success) {
  516. let list = res.list;
  517. this.styleList = list;
  518. }
  519. },
  520. //风格选择
  521. selectStyle(idx){
  522. if(this.curStyleIndex == idx){
  523. return false
  524. }
  525. this.curStyleIndex = idx;
  526. let param = {
  527. type: 'CLK', //埋点类型
  528. clkId: 'clk_2cmina_23080416', //点击ID
  529. clkName: 'AIstyle_ret_clk', //点击前往的页面名称
  530. clkParams: {
  531. locusName: "AI 风格",
  532. type:this.styleList[this.curStyleIndex].styleName
  533. }
  534. };
  535. util.trackRequest(param);
  536. },
  537. // AI渲染
  538. async aiSubmit(type) {
  539. if(!this.styleList || this.styleList.length==0 || this.curStyleIndex==-1
  540. || !this.styleList[this.curStyleIndex].prompt || !this.styleList[this.curStyleIndex].negativePrompt){
  541. return false;
  542. }
  543. // 防止连续点击处理
  544. if (this.aiFlag) {
  545. return
  546. }
  547. this.aiFlag = true;
  548. this.aiImage = "";//清空AI结果图
  549. this.stopInterval();
  550. // if(!this.showAIImage){
  551. this.myloading = true;
  552. this.loadingMsg = "启动中";
  553. // }
  554. // this.inputBase64Url = await this.shottingAction(2);//开始截图-返回的是base64的数据
  555. // this.startServer();
  556. // let base64 = await this.$parent.shottingAction(2);//开始截图-返回的是base64
  557. let shottingImg = await this.$parent.shottingAction();//开始截图-返回的是图片地址
  558. if(!shottingImg){
  559. this.showToast("渲染失败,请重试");
  560. return false;
  561. }
  562. // ?x-oss-process=image/auto-orient,1/quality,Q_46/format,jpg //阿里OSS
  563. // "?imageMogr2/auto-orient/format/webp/blur/1x0/quality/75";//七牛云压缩图片
  564. shottingImg += "?x-oss-process=image/auto-orient,1/quality,Q_46/format,jpg";//压缩图片
  565. this.shottingImg = shottingImg;
  566. this.changeImg2Base64(this.shottingImg, false);
  567. console.warn("***shottingImg***",this.shottingImg)
  568. if(type==1){
  569. let param = {
  570. type: 'CLK', //埋点类型
  571. clkId: 'clk_2cmina_23080413', //点击ID
  572. clkName: 'AIcreate_clk', //点击前往的页面名称
  573. clkParams: {
  574. locusName: "AI生成",
  575. userparamter:{
  576. shottingImg:this.shottingImg,
  577. style:this.styleList[this.curStyleIndex].styleName
  578. }
  579. }
  580. };
  581. util.trackRequest(param);
  582. }else{
  583. let param = {
  584. type: 'CLK', //埋点类型
  585. clkId: 'clk_2cmina_23080419', //点击ID
  586. clkName: 'continueAIcreate_clk', //点击前往的页面名称
  587. clkParams: {
  588. locusName: "继续生成",
  589. userparamter:{
  590. shottingImg:this.shottingImg,
  591. style:this.styleList[this.curStyleIndex].styleName
  592. }
  593. }
  594. };
  595. util.trackRequest(param);
  596. }
  597. },
  598. changeImg2Base64(url, isRepeat) {
  599. var self = this;
  600. if(isRepeat && self.inputBase64Url){//重复使用
  601. self.startServer();
  602. }else{
  603. self.startServer();
  604. }
  605. },
  606. //前置逻辑
  607. async prevHandle(parmas){
  608. //不是首次请求,则无需前置判断 用户上传的也不需要前置处理
  609. if(this.subType!=0){
  610. return '';
  611. }
  612. return new Promise(async (resolve, reject) => {
  613. let _data = JSON.parse(JSON.stringify(parmas))
  614. delete _data.webhook;
  615. let res = await requestConfig("img2img_local", _data);
  616. if (res.success) {
  617. if (res.success && res.single) {
  618. let resultImg = res.single;
  619. resolve(resultImg);
  620. }else{
  621. resolve('');
  622. }
  623. }else{
  624. resolve('');
  625. }
  626. })
  627. },
  628. //开始图生图流程
  629. async startServer() {
  630. if(!this.styleList || this.curStyleIndex < 0 || !this.styleList[this.curStyleIndex].imgUrl){
  631. return false
  632. }
  633. if(this.$parent.pvCurPageName!="room_show"){//说明用户切换页面了
  634. console.warn("***用户已经退出页面***")
  635. return false;
  636. }
  637. let imgUrl = this.styleList[this.curStyleIndex].imgUrl;
  638. let subType = this.subType;
  639. let session_hash = Date.now();
  640. let theme = this.themeList[this.themeIndex];//主题数据
  641. let prompt = this.styleList[this.curStyleIndex].prompt + theme.prot;
  642. let noPromot = this.styleList[this.curStyleIndex].negativePrompt;
  643. let unit = 768 / this.screenWidth;
  644. this.imageWidth = parseInt((this.screenWidth * unit).toFixed());
  645. this.imageHeight = parseInt((this.$parent.canvasHeight * unit).toFixed());
  646. this.timeOut = this.modelType==1? 20000: 50000;
  647. var parmas = {
  648. negativePrompt: noPromot,
  649. prompt: prompt,
  650. "batchSize": 1,
  651. brandId: $config.brandId,
  652. height: this.imageHeight,
  653. width: this.imageWidth,
  654. "moduleType": "AI_Biography",
  655. "steps":20,
  656. "sampler":"DDIM",
  657. "controlNetSessionHash":session_hash,
  658. "cfgScale":12,
  659. "denoising":0.9,
  660. image:this.shottingImg,
  661. styleImage:imgUrl,
  662. keyword: "elabSd",
  663. model: this.modelType==1? "lucataco/ssd-1b" : 'catio-apps/controlnet-interior-design',
  664. };
  665. if(this.modelType==2){//精准设计
  666. if(subType == 0){//首次
  667. parmas.model = this.reqList[0].model;
  668. }else{//重试
  669. parmas.model = this.reqListReset[0].model;
  670. }
  671. }else{//创意设计
  672. if(subType == 0){//首次
  673. parmas.model = "lucataco/ssd-1b";
  674. }else{//重试
  675. parmas.model = "deployments/elabgroup/elab-ssd-1b";
  676. }
  677. }
  678. this.curSpaceId = this.spaceObj.spaceId;//生成时的空间id
  679. let result = await this.prevHandle(parmas);
  680. console.warn("***prevHandle***",result)
  681. if(result && result.length>0){
  682. this.randomHandle(result)
  683. return false;
  684. }else{
  685. if(this.modelType==2){//精准设计
  686. this.otherHandle(parmas);//发送其他AI请求
  687. }
  688. let res = await requestConfig("generateTaskImgToImgForAliyun", parmas);
  689. console.log("图生图结果:", res);
  690. let that = this;
  691. if (res.success && res.single) {
  692. this.aiPicId = res.single;
  693. if(this.modelType==2){//精准设计
  694. if(subType == 0){//首次
  695. this.reqList[0].aiPicId = this.aiPicId;
  696. }else{//重试
  697. this.reqListReset[0].aiPicId = this.aiPicId;
  698. }
  699. }
  700. if (this.aiPicId) {
  701. this.startInterval();//开始轮询AI生成图的结果
  702. }else{
  703. this.stopInterval()
  704. }
  705. }else{
  706. this.stopInterval()
  707. this.showToast("渲染失败,请重试")
  708. }
  709. }
  710. },
  711. stopInterval() {
  712. if (this.randomTimer) {
  713. clearInterval(this.randomTimer);
  714. this.randomTimer = null;
  715. }
  716. if (this.timer) {
  717. // clearInterval(this.timer);
  718. this.timer = null;
  719. }
  720. if (this.outTimer) {
  721. clearTimeout(this.outTimer)
  722. this.outTimer = null
  723. }
  724. this.subType = 0;
  725. this.reqList.forEach(it=>{
  726. it.aiPicId = '';
  727. it.resultImg = '';
  728. })
  729. this.reqListReset.forEach(it=>{
  730. it.aiPicId = '';
  731. it.resultImg = '';
  732. })
  733. // this.random = 1;
  734. this.myloading = false;
  735. this.aiFlag = false;
  736. },
  737. //随机处理
  738. randomHandle(resultImg){
  739. if(this.timer || !resultImg){
  740. return false;
  741. }
  742. let self = this;
  743. var count = 1;
  744. var process = 0;//进度
  745. var randomNum = Math.floor(Math.random() * 4 + 5);//5-8随机数
  746. this.randomTimer = setInterval(function() {
  747. process = parseInt(count * 100/(randomNum));
  748. if(process>=100){
  749. process = 99;
  750. }
  751. if (count < randomNum) {//没有到上限
  752. // if(!self.showAIImage){
  753. self.myloading = true;
  754. self.loadingMsg = '生成中…' + process + '%';
  755. // }
  756. }else{
  757. self.myloading = false;
  758. self.resultHandle(resultImg);
  759. }
  760. count = count + 1;
  761. }, 1000);
  762. },
  763. otherHandle(parmas){
  764. let reqList = [];
  765. if(this.subType == 0){//首次
  766. reqList = this.reqList;
  767. }else{//重试
  768. reqList = this.reqListReset;
  769. }
  770. reqList.forEach(async (it,index)=>{
  771. let _data = JSON.parse(JSON.stringify(parmas));
  772. if(index>0){
  773. _data.model = it.model;
  774. let res = await requestConfig("generateTaskImgToImgForAliyun", _data);
  775. if (res.success) {
  776. console.log('生成结果123:', res);
  777. it.aiPicId = res.single || '';
  778. }
  779. }
  780. })
  781. },
  782. //开始生成AI图的轮询,每隔1s轮询一次
  783. startInterval() {
  784. if(this.timer){
  785. return false;
  786. }
  787. let self = this;
  788. this.count = 1;//轮询次数
  789. var random = 0;
  790. this.currentImg = false;//当次生成图还没有结果
  791. this.timer = 1;
  792. this.getOutPicture();//不在轮询,而是等结果
  793. this.setOutTimer();//设置超时逻辑
  794. },
  795. //设置一个超时逻辑,到底指定时间后停止轮询,当前是90s
  796. setOutTimer() {
  797. if (this.outTimer) {
  798. clearTimeout(this.outTimer)
  799. this.outTimer = null
  800. }
  801. var self = this;
  802. this.outTimer = setTimeout(function() {
  803. if (self.timer) {
  804. let hasResult = false;
  805. if(self.modelType==2){//精准设计
  806. let reqList = [];
  807. if(self.subType == 0){//首次
  808. reqList = self.reqList;
  809. }else{//重试
  810. reqList = self.reqListReset;
  811. }
  812. reqList.some((item,index) => {
  813. if(item.resultImg){
  814. hasResult = true;
  815. self.resultHandle(item.resultImg)
  816. }
  817. });
  818. }
  819. console.warn("***hasResult***",hasResult)
  820. if(!hasResult){//没有结果
  821. self.stopInterval();//停止轮询
  822. // self.$message.warning("AI开了个小差,请稍后再试");
  823. // self.dialogVisible = true;//弹出超时提示
  824. MessageBox.confirm('',{
  825. title: '提示',
  826. message: '当前AI使用火爆,请继续尝试?',
  827. showCancelButton: true,
  828. confirmButtonText:'继续尝试',
  829. cancelButtonText:'取消等待',
  830. }).then(action => {
  831. console.warn("***MessageBox-action***",action)
  832. if(action == 'confirm'){
  833. self.confirmHandle(1);
  834. }
  835. }).catch(err=>{
  836. console.warn("***MessageBox-err***",err)
  837. if(err == 'cancel'){
  838. self.cancelHandle();
  839. }
  840. });
  841. // MessageBox.confirm('确定执行此操作?')
  842. }
  843. }
  844. clearTimeout(self.outTimer);
  845. self.outTimer = null
  846. }, this.timeOut);
  847. },
  848. confirmHandle(type){
  849. console.log('用户点击确定')
  850. this.subType = type || 0;
  851. this.startServer();
  852. },
  853. cancelHandle(){
  854. console.log('用户点击取消')
  855. this.subType = 0;
  856. },
  857. //获取生成图结果
  858. getOutPicture() {
  859. if(this.timer==null){
  860. console.warn("***当前轮询已经结束了1***")
  861. return false;
  862. }
  863. if(this.modelType==2){//精准设计
  864. let reqList = [];
  865. if(this.subType == 0){//首次
  866. reqList = this.reqList;
  867. }else{//重试
  868. reqList = this.reqListReset;
  869. }
  870. reqList.forEach((item,index) => {
  871. this.singleHandle(item)
  872. });
  873. }
  874. else{
  875. this.singleHandle({aiPicId:this.aiPicId})
  876. }
  877. },
  878. //发出获取结果请求获取AI生成结果
  879. async singleHandle(model){
  880. if(!model || !model.aiPicId){
  881. return false;
  882. }
  883. var parmas = {
  884. id: model.aiPicId,
  885. };
  886. let res = await requestConfig("getPredictions", parmas);
  887. if (res.success && res.single) {
  888. if(this.currentImg){//当前已经有生成图了
  889. console.warn("***当前已经有最高级生成图了***")
  890. return false;
  891. }
  892. if(this.timer==null){
  893. console.warn("***当前轮询已经结束了***")
  894. return false;
  895. }
  896. if (res.single.status == 'succeeded' && res.single.output) {
  897. if(this.modelType==2){//精准设计
  898. model.resultImg = res.single.output;
  899. if(model.level=='5'){//最高级了
  900. this.currentImg = true;
  901. setTimeout(()=>{
  902. this.resultHandle(res.single.output)
  903. },1500)
  904. }
  905. }else{
  906. this.currentImg = true;
  907. setTimeout(()=>{
  908. this.resultHandle(res.single.output)
  909. },1500)
  910. }
  911. console.warn("***有生成图了***",model)
  912. }
  913. if(this.modelType==2){//最高优先级返回没有图片,则处理进度条事宜
  914. if(model.level=='5'){
  915. this.processHandle(res.single);
  916. }
  917. }else{//普通设计
  918. this.processHandle(res.single);
  919. }
  920. } else if (!res.success) {
  921. this.stopInterval();//停止轮询
  922. this.showToast("渲染失败,请重试")
  923. }
  924. },
  925. //进度处理
  926. processHandle(single){
  927. console.warn("***single***",single.status,single.progress,this.count,single);
  928. let self = this;
  929. if(single.status=='starting'){//启动中的逻辑
  930. if(this.count>=20){
  931. this.stopInterval();//停止轮询
  932. // this.dialogAIVisible = true;
  933. MessageBox.confirm('',{
  934. title: '提示',
  935. message: 'AI开了小差,是否重新生成?',
  936. showCancelButton: true,
  937. confirmButtonText:'继续生成',
  938. cancelButtonText:'放弃生成',
  939. }).then(action => {
  940. console.warn("***MessageBox-action***",action)
  941. if(action == 'confirm'){
  942. this.confirmHandle(0);
  943. }
  944. }).catch(err=>{
  945. if(err == 'cancel'){
  946. this.cancelHandle();
  947. }
  948. });
  949. }else{
  950. this.myloading = true;
  951. this.loadingMsg = '启动中';
  952. }
  953. this.count = this.count + 1;
  954. // this.getOutPicture();
  955. setTimeout(()=>{
  956. this.getOutPicture();
  957. },1000)
  958. }else if(single.status=='processing'){
  959. let random = single.progress || 0;
  960. if(random >= 100){
  961. random = 99;
  962. }
  963. this.myloading = true;
  964. this.loadingMsg = '生成中…' + parseInt(random) + '%';
  965. // this.getOutPicture();
  966. setTimeout(()=>{
  967. this.getOutPicture();
  968. },1000)
  969. }else if(single.status=='succeeded'){
  970. this.myloading = true;
  971. this.loadingMsg = '生成中…100%';
  972. }
  973. },
  974. //返回结果处理
  975. resultHandle(resultImg){
  976. this.currentImg = true;
  977. // this.random = 100;
  978. this.aiImage = resultImg;
  979. this.showAIFlag = true;
  980. let newImage = resultImg;
  981. let aiStyleName = this.styleList[this.curStyleIndex].styleName;
  982. let _data = {
  983. image:newImage,
  984. checked:false,
  985. list:[newImage],
  986. spaceId:this.curSpaceId,//记录下当前生成的AI图是哪个空间的,因为会切换空间
  987. aiStyleName:aiStyleName,
  988. }
  989. this.aiImagesList.push(_data);
  990. this.showAIImage = true;//显示AI结果集合-因为生成了AI图片
  991. if(this.$parent && typeof(this.$parent.clearHandle)=="function" ){
  992. this.$parent.clearHandle();
  993. }
  994. let cpAiData = JSON.parse(JSON.stringify(this.aiData)) || []
  995. if(cpAiData && this.curHouseObj && this.curHouseObj.houseFloor){//给上一个页面回传生成的数据
  996. let space = cpAiData.find(it=>{
  997. return it.houseFloor == this.curHouseObj.houseFloor && it.spaceId == this.spaceObj.spaceId
  998. })
  999. if(space){
  1000. let data ={
  1001. aiStyleName:aiStyleName,
  1002. image:newImage,
  1003. checked:false,
  1004. }
  1005. space.aiImagesList.push(data);
  1006. }else{//不存在则构建数据
  1007. let data = {
  1008. houseFloor:this.curHouseObj.houseFloor,//当前的楼层
  1009. spaceId:this.spaceObj.spaceId,
  1010. aiImagesList:[
  1011. {
  1012. aiStyleName:aiStyleName,
  1013. image:newImage,
  1014. checked:false,
  1015. }
  1016. ]
  1017. }
  1018. cpAiData.push(data)
  1019. }
  1020. this.$store.dispatch('setAiData', cpAiData)
  1021. }
  1022. this.stopInterval();
  1023. if(this.aiImagesList.length>1){
  1024. setTimeout(()=>{
  1025. this.$refs.carousel.setActiveItem(this.aiImagesList.length-1);//切换到最后一张
  1026. }, 1000);
  1027. }
  1028. },
  1029. //空间数据整理
  1030. spaceAIHandle(){
  1031. let curHouseObj = this.$parent.curHouseObj;//当前户型数据对象
  1032. let aiImagesList = this.aiImagesList;//AI生成图数据对象
  1033. let wallList = this.$parent.wallList;//当前户型墙体数据列表对象
  1034. let spaceList = JSON.parse(curHouseObj.houseJson);
  1035. //遍历当前户型下的每一个空间
  1036. spaceList.forEach((item)=>{
  1037. let space = item;
  1038. let list = aiImagesList.filter(it=>it.spaceId==space.spaceId);//找到AI生成图中的当前空间
  1039. if(list && list.length>0){
  1040. list = list.filter(it=>it.checked==true);//过滤选中的
  1041. list = list.map(it=>{
  1042. return it.image
  1043. })
  1044. space.hardboundEffect = list;
  1045. console.warn("submitHouse: ", list,space);
  1046. }
  1047. let wall = wallList.find(it=>it.id==space.wallId);
  1048. if(wall){//找到当前空间的墙体数据
  1049. space.wallList = JSON.stringify(wall);
  1050. }
  1051. })
  1052. setStorage('spaceList', spaceList);//把空间选择的数据存入本地缓存里面,方便后续使用
  1053. console.warn("**spaceList**",spaceList)
  1054. },
  1055. async submitHouse(){
  1056. const loading = this.$loading({
  1057. lock: true,
  1058. text: '提交中...',
  1059. spinner: 'el-icon-loading',
  1060. background: 'rgba(0, 0, 0, 0.7)'
  1061. });
  1062. let shottingImg = getStorage('shottingImg');//把空间选择的数据存入本地缓存里面,方便后续使用
  1063. console.warn("***shottingImg***",shottingImg);
  1064. let userId = this.userId ? this.userId : '';
  1065. let curLayoutStruct = JSON.parse(getStorage('curLayoutStruct')) ;//获取楼层的数据-户型数组
  1066. let curHouseObj = this.$parent.curHouseObj;//当前户型数据对象
  1067. let curHouseType = setStorage('curHouseType');//把楼层的数据存入缓存中
  1068. let curHouseName = setStorage('curHouseName');//把楼层的数据存入缓存中
  1069. let param = {
  1070. "brandId": $config.brandId,
  1071. "houseId": curHouseObj.houseId,
  1072. "userId": userId,
  1073. "floot": curHouseObj.houseFloor,
  1074. "spaceName": curHouseName,
  1075. "spaceStructure": curHouseType,
  1076. "curFloor":curHouseObj.houseFloor,
  1077. layoutStruct:[],
  1078. }
  1079. let wallList = this.$parent.wallList;//当前户型墙体数据列表对象
  1080. //处理每一个楼层
  1081. curLayoutStruct.forEach((layoutStruct,index)=>{
  1082. let houseData = {
  1083. "layoutId": layoutStruct.id,
  1084. "layoutName": layoutStruct.name,
  1085. "layoutArea": layoutStruct.houseArea,
  1086. "floor": layoutStruct.houseFloor,
  1087. "layoutImgCustomized": shottingImg,
  1088. "style": "",
  1089. "houseJson": []
  1090. }
  1091. let spaceList = JSON.parse(layoutStruct.houseJson);
  1092. let styleList = [];
  1093. //遍历当前户型下的每一个空间
  1094. spaceList.forEach((item)=>{
  1095. let space = JSON.parse(JSON.stringify(item));
  1096. //找到当前空间对象对应的AI数据对象
  1097. let AISpace = null;
  1098. AISpace = this.aiData && this.aiData.find(it=>{
  1099. return it.houseFloor == layoutStruct.houseFloor && it.spaceId == space.spaceId
  1100. });
  1101. if(AISpace){
  1102. let list = AISpace.aiImagesList.filter(it=>it.checked==true);//过滤选中的
  1103. list.forEach(it=>{
  1104. styleList.push(it.aiStyleName);
  1105. })
  1106. list = list.map(it=>{
  1107. return it.image
  1108. })
  1109. space.hardboundEffect = list;
  1110. console.warn("submitHouse: ", list,space);
  1111. }
  1112. let wall = wallList.find(it=>it.id==space.wallId);
  1113. if(wall){//找到当前空间的墙体数据
  1114. space.wallList = JSON.stringify(wall);
  1115. }
  1116. houseData.houseJson.push(space)
  1117. })
  1118. //寻找styleList里面出现最多次数的风格
  1119. if(styleList && styleList.length>0){
  1120. let maxEle = styleList[0];
  1121. let maxNum = 1;
  1122. styleList.reduce((p,k)=>{
  1123. p[k] ? p[k]++ : p[k]=1;
  1124. if(p[k] > maxNum){
  1125. maxEle = k;
  1126. maxNum ++
  1127. }
  1128. return p;
  1129. },{});
  1130. houseData.style = maxEle;
  1131. }
  1132. param.layoutStruct.push(houseData)
  1133. })
  1134. param.expand = getStorage('expand') || ''
  1135. console.warn("submitHouse-param: ", param);
  1136. let trackparam = {
  1137. type: 'CLK', //埋点类型
  1138. clkId: 'clk_2cmina_23080409', //点击ID
  1139. clkName: 'submit_clk', //点击前往的页面名称
  1140. clkParams: {
  1141. locusName: "数据提交",
  1142. postAIData:this.aiData,
  1143. }
  1144. };
  1145. util.trackRequest(trackparam);
  1146. let res = await requestConfig("saveCustomizedRecord", param);
  1147. loading.close();
  1148. if(res && res.success && res.single){//提交成功
  1149. let data = {
  1150. houseId:this.$route.query.houseId || this.$store.state.houseId,
  1151. id:res.single,
  1152. }
  1153. router.push({
  1154. name: "webgl_rxdz_customize",
  1155. query:data
  1156. });
  1157. }
  1158. },
  1159. //进入下一步
  1160. gonext(){
  1161. this.spaceAIHandle()
  1162. router.push({
  1163. name: "webgl_rxdz_test_env",
  1164. query:{
  1165. houseId:this.$route.query.houseId || this.$store.state.houseId,
  1166. }
  1167. });
  1168. },
  1169. showToast(title,time=3000){
  1170. this.myloading = false;
  1171. this.$store.state.loading = true;
  1172. this.$store.state.loadingMsg = title || "";
  1173. setTimeout(()=>{
  1174. this.$store.state.loading = false;
  1175. }, time);
  1176. }
  1177. }
  1178. }
  1179. </script>
  1180. <style lang="scss" scoped>
  1181. @import "./viewMask.scss";
  1182. </style>
  1183. <style lang="css" scoped>
  1184. /* @import "@/common/css/common.css"; */
  1185. </style>