viewMask.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. <template src="./viewMask.html">
  2. </template>
  3. <script>
  4. const util = require('@/utils/util.js').default;
  5. // const config = require('@/services/url$config.js');
  6. import touchHandle from '@/mixins/touchHandle.js';
  7. // import requestConfig from '@/static/lib/requestConfig';
  8. // const app = getApp(); //获取应用实例
  9. export default {
  10. mixins: [touchHandle],
  11. data: function() {
  12. return {
  13. currentIndex:0, //当前看到的图片序号
  14. showAIImage: false,//是否显示当前AI结果集合 默认不显示,因为没有
  15. aiImagesList:[
  16. ],//AI生成的图片列表
  17. styleList: [], //风格列表数据
  18. curStyleIndex: 0, //当前选中的风格序号
  19. aiFlag:false,
  20. aiImage: "",
  21. inputBase64Url: "",
  22. taskId: "", // 图生图任务ID
  23. img2imgTimer: null,
  24. imageWidth: 750,
  25. imageHeight: 448,
  26. showAIFlag:false,//继续生成状态切换标志
  27. checked:false,
  28. shottingImg:'',
  29. count:0,
  30. random:1,
  31. disableAble:false,
  32. spaceTypes: [{
  33. icon: "",
  34. title: "卧室",
  35. subtitle: "0个布局",
  36. englishRemark: "bedroom",
  37. },
  38. {
  39. icon: "",
  40. title: "客厅",
  41. subtitle: "0个布局",
  42. englishRemark: "living room",
  43. },
  44. {
  45. icon: "",
  46. title: "餐厅",
  47. subtitle: "0个布局",
  48. englishRemark: "dinning room",
  49. },
  50. {
  51. icon: "",
  52. title: "厨房",
  53. subtitle: "0个个布局",
  54. englishRemark: "kitchen",
  55. },
  56. {
  57. icon: "",
  58. title: "玄关",
  59. subtitle: "0个布局",
  60. englishRemark: "hallway",
  61. },
  62. {
  63. icon: "",
  64. title: "卫生间",
  65. subtitle: "0个布局",
  66. englishRemark: "bathroom",
  67. },
  68. {
  69. icon: "",
  70. title: "衣帽间",
  71. subtitle: "0个布局",
  72. englishRemark: "walkin closet",
  73. },
  74. {
  75. icon: "",
  76. title: "收纳",
  77. subtitle: "0个布局",
  78. englishRemark: "storage room",
  79. },
  80. {
  81. icon: "",
  82. title: "阳台",
  83. subtitle: "0个布局",
  84. englishRemark: "balcony",
  85. },
  86. {
  87. icon: "",
  88. title: "飘窗",
  89. subtitle: "0个布局",
  90. englishRemark: "bay window",
  91. },
  92. {
  93. icon: "",
  94. title: "链接空间",
  95. subtitle: "0个布局",
  96. englishRemark: "connecting space between two rooms",
  97. },
  98. {
  99. icon: "",
  100. title: "自定义",
  101. subtitle: "0个布局",
  102. englishRemark: "room",
  103. },
  104. ],
  105. myloading:false,
  106. loadingMsg:'',
  107. }
  108. },
  109. props:{
  110. spaceObj: {
  111. type: Object,
  112. default: null,
  113. },
  114. },
  115. watch: {
  116. spaceObj(newVal, oldVal) {
  117. if (newVal == null) {
  118. return;
  119. }
  120. console.log("当前空间数据view-mark-watch:", newVal);
  121. this.getAiBeautyFamily();
  122. // this.curSpaceArea = parseFloat(
  123. // (newVal.spaceWidth * newVal.spaceHeight) / 10000
  124. // ).toFixed(2);
  125. // this.getOverallArrangementDetailsList();
  126. },
  127. },
  128. mounted() {//组件挂载时事件
  129. // console.warn("***mounted-nav***",this.seedItem)
  130. // if(this.seedItem){
  131. // this.title = this.seedItem.seedText;
  132. // }
  133. },
  134. // 页面被展示时执行
  135. onPageShow: function() {
  136. },
  137. //页面被隐藏时执行
  138. onPageHide: function() {
  139. },
  140. beforeDestroy:function(){
  141. console.warn("***beforeDestroy***");//更新到页面上的数据
  142. this.clearInterval();
  143. },
  144. computed: {
  145. aiData() {
  146. return this.$store.state.aiData;
  147. },
  148. curHouseObj() {
  149. return this.$store.state.curHouseObj;
  150. },
  151. },
  152. methods:{
  153. swiperChangeImg(e){
  154. this.currentIndex = e.detail?e.detail.current:e;
  155. this.checked = this.aiImagesList[this.currentIndex].checked;
  156. console.warn("***swiperChangeImg***",this.checked);//更新到页面上的数据
  157. },
  158. //视角切换
  159. switchActor(){
  160. // this.$parent.clearHandle()
  161. this.$emit('switchActor');
  162. this.showAIImage = false;//隐藏AI结果集合-执行切换视角
  163. let index = this.$parent.currentActor.userIndex;//当前视角的序号
  164. let nextIndex = (index + 1) % this.$parent.actors.length;
  165. let param = {
  166. type: 'CLK', //埋点类型
  167. clkId: 'clk_2cmina_23080417', //点击ID
  168. clkName: 'changeangle_clk', //点击前往的页面名称
  169. clkParams: {
  170. locusName: "视角切换",
  171. type:this.$parent.actors[nextIndex].actorEum
  172. }
  173. };
  174. util.trackRequest(param);
  175. },
  176. showOrHideWebGl(){
  177. // this.$parent.clearHandle()
  178. this.showAIImage = !this.showAIImage;
  179. let param = {
  180. type: 'CLK', //埋点类型
  181. clkId: 'clk_2cmina_23080415', //点击ID
  182. clkName: 'contrast_clk', //点击前往的页面名称
  183. clkParams: {
  184. locusName: "对比",
  185. }
  186. };
  187. util.trackRequest(param);
  188. // setTimeout(()=> {
  189. // if(this.showAIImage==true){
  190. // this.$parent.clearHandle()
  191. // }else{
  192. // this.$parent.attendEvent()
  193. // }
  194. // }, 100);
  195. },
  196. //保存到相册
  197. save() {
  198. //表示canvas正在绘制,不能进行保存
  199. if (!this.aiImagesList || this.aiImagesList.length==0) {
  200. return false;
  201. }
  202. var _resultImg = this.aiImagesList[this.currentIndex].image;
  203. //正在选择照片,不能生效
  204. if (!_resultImg || _resultImg.length==0) {
  205. this.showToast("请选中图片后再试!");
  206. return false;
  207. }
  208. var para = {
  209. type: 'CLK', //埋点类型
  210. clkId: 'clk_2cmina_56', //点击ID,固定
  211. clkName: "share-savepic", //点击名称
  212. expand: {
  213. "resultImg": (_resultImg || ""),
  214. },
  215. }
  216. util.trackRequest(para);
  217. if(navigator.userAgent.toLocaleLowerCase().includes('micromessenger')){
  218. this.$message("请长按图片保存!");
  219. }else{
  220. this.saveImageHandle(_resultImg);
  221. }
  222. },
  223. downloadIamge(imgsrc) { //下载图片地址和图片名
  224. var fileName = "4DImage" + util.formatDate(new Date(), "yyyyMMddhhmmss") + '.jpg';
  225. const image = new Image();
  226. // 解决跨域 Canvas 污染问题
  227. image.setAttribute("crossOrigin", "anonymous");
  228. image.onload = ()=> {
  229. // let canvas = document.createElement("canvas");
  230. // canvas.width = image.width;
  231. // canvas.height = image.height;
  232. // const context = canvas.getContext("2d");
  233. // context.drawImage(image, 0, 0, image.width, image.height);
  234. // const url = canvas.toDataURL("image/jpg"); //得到图片的base64编码数据
  235. const a = document.createElement("a"); // 生成一个a元素
  236. const event = new MouseEvent("click"); // 创建一个单击事件
  237. a.download = fileName || "photo"; // 设置图片名称
  238. a.href = imgsrc; // 将生成的URL设置为a.href属性
  239. a.dispatchEvent(event); // 触发a的单击事件
  240. this.showToast("保存成功!");
  241. };
  242. image.src = imgsrc;
  243. },
  244. saveImageHandle(_resultImg){
  245. let param = {
  246. type: 'CLK', //埋点类型
  247. clkId: 'clk_2cmina_23080414', //点击ID
  248. clkName: 'download_clk', //点击前往的页面名称
  249. clkParams: {
  250. locusName: "下载",
  251. img:_resultImg
  252. }
  253. };
  254. util.trackRequest(param);
  255. this.downloadIamge(_resultImg);
  256. },
  257. //选项变更
  258. changeAIImg() {
  259. // let lastPage = getCurrentPages()[getCurrentPages().length - 2] ? getCurrentPages()[getCurrentPages().length - 2].$vm : null;
  260. this.checked = !this.checked;//变更选项
  261. this.aiImagesList[this.currentIndex].checked = this.checked;
  262. console.warn("***changeAIImg***",this.checked,this.aiData)
  263. if(this.aiData){//给上一个页面回传生成的数据
  264. let space = this.aiData.find(it=>{
  265. return it.spaceId == this.spaceObj.spaceId
  266. })
  267. if(space){
  268. space.aiImagesList[this.currentIndex].checked = this.checked;
  269. }
  270. }
  271. if(this.checked){
  272. let param = {
  273. type: 'CLK', //埋点类型
  274. clkId: 'clk_2cmina_23080418', //点击ID
  275. clkName: 'chooseprogramme_clk', //点击前往的页面名称
  276. clkParams: {
  277. locusName: "选定风格/视角",
  278. style:this.styleList[this.curStyleIndex].styleName,
  279. img:this.aiImagesList[this.currentIndex].image,
  280. }
  281. };
  282. util.trackRequest(param);
  283. }
  284. },
  285. rightScroll(){//右滑
  286. if(this.currentIndex <= (this.aiImagesList.length - 1) && this.currentIndex > 0){
  287. // this.currentIndex --;
  288. this.$refs.carousel.prev();
  289. }
  290. },
  291. leftScroll(){//继续生成
  292. if(this.currentIndex != this.aiImagesList.length - 1){
  293. if(this.currentIndex<this.aiImagesList.length - 1){
  294. // this.currentIndex ++;
  295. this.$refs.carousel.next();
  296. }
  297. return false;
  298. }
  299. console.log("***leftScroll***",this.currentIndex,this.aiImagesList.length)
  300. this.aiSubmit(2);//继续生成下一张
  301. },
  302. //返回上一页
  303. goback(){
  304. this.$router.go(-1);
  305. },
  306. mynavigateFuc(e) {
  307. if (e) {
  308. // this.$parent.clearHandle();
  309. let param = {
  310. type: 'CLK', //埋点类型
  311. clkId: 'clk_2cmina_23080408', //点击ID
  312. clkName: 'WeCom_clk', //点击前往的页面名称
  313. clkParams: {
  314. locusName: "联系定制",
  315. }
  316. };
  317. util.trackRequest(param);
  318. if(window.__wxjs_environment === 'miniprogram'){
  319. wx.miniProgram.navigateTo({url: '/pages/transfer/transfer?event=openCustomerServiceChat&houseId='+this.$store.state.houseId})
  320. }else{
  321. this.$message.warning("敬请期待");
  322. }
  323. // setTimeout(()=> {
  324. // if(this.showAIImage==true){
  325. // this.$parent.clearHandle()
  326. // }else{
  327. // this.$parent.attendEvent()
  328. // }
  329. // }, 100);
  330. }
  331. },
  332. catchTapEvent:function(){
  333. return false;
  334. },
  335. //获取AI风格列表
  336. async getAiBeautyFamily() {
  337. // const spaceName = this.spaceTypes[this.spaceObj.spaceType - 1].title;
  338. let res = await requestConfig("getHardboundEffects", {
  339. "houseId": this.$route.query.houseId,
  340. "spaceType": this.spaceObj.spaceType,
  341. "spaceName": this.spaceObj.spaceName,
  342. });
  343. this.styleList = [];
  344. if (res.success) {
  345. let list = res.list;
  346. this.styleList = list;
  347. }
  348. if(!this.styleList || this.styleList.length==0){
  349. this.disableAble = true;//不能点击-没有风格
  350. let unit = window.screen.width / 750;//单位rpm 对应 px 的值
  351. this.$parent.canvasHeight = window.screen.height - (208 * unit);
  352. this.$parent.camera.aspect = window.screen.width / this.$parent.canvasHeight;
  353. this.$parent.camera.updateProjectionMatrix();
  354. this.$parent.renderer.setSize(window.screen.width, this.$parent.canvasHeight);
  355. }else{
  356. this.disableAble = false;//可以点击
  357. }
  358. },
  359. clearInterval() {
  360. if (this.img2imgTimer) {
  361. clearInterval(this.img2imgTimer);
  362. this.img2imgTimer = null;
  363. }
  364. this.random = 1;
  365. this.myloading = false;
  366. },
  367. //风格选择
  368. selectStyle(idx){
  369. if(this.curStyleIndex == idx){
  370. return false
  371. }
  372. this.curStyleIndex = idx;
  373. let param = {
  374. type: 'CLK', //埋点类型
  375. clkId: 'clk_2cmina_23080416', //点击ID
  376. clkName: 'AIstyle_ret_clk', //点击前往的页面名称
  377. clkParams: {
  378. locusName: "AI 风格",
  379. type:this.styleList[this.curStyleIndex].styleName
  380. }
  381. };
  382. util.trackRequest(param);
  383. },
  384. // AI渲染
  385. async aiSubmit(type) {
  386. if(!this.styleList || this.styleList.length==0 || this.curStyleIndex==-1
  387. || !this.styleList[this.curStyleIndex].prompt || !this.styleList[this.curStyleIndex].negativePrompt){
  388. return false;
  389. }
  390. // 防止连续点击处理
  391. if (this.aiFlag) {
  392. return
  393. }
  394. this.aiFlag = true;
  395. if (this.aiImage == "" || !this.aiImage) {
  396. this.aiImage = ""; // https://dm.static.elab-plus.com/CE4/backImg.png
  397. }
  398. this.aiImage = "";
  399. this.clearInterval();
  400. if(!this.showAIImage){
  401. this.myloading = true;
  402. this.loadingMsg = "设计中...";
  403. // this.$store.state.loading = true;
  404. // this.$store.state.loadingMsg="设计中...";
  405. }
  406. // this.inputBase64Url = await this.shottingAction(2);//开始截图-返回的是base64的数据
  407. // this.startServer();
  408. // let base64 = await this.$parent.shottingAction(2);//开始截图-返回的是base64
  409. let shottingImg = await this.$parent.shottingAction();//开始截图-返回的是图片地址
  410. if(!shottingImg){
  411. this.showToast("渲染失败,请重试");
  412. return false;
  413. }
  414. // ?x-oss-process=image/auto-orient,1/quality,Q_46/format,jpg //阿里OSS
  415. // "?imageMogr2/auto-orient/format/webp/blur/1x0/quality/75";//七牛云压缩图片
  416. shottingImg += "?x-oss-process=image/auto-orient,1/quality,Q_46/format,jpg";//压缩图片
  417. this.shottingImg = shottingImg;
  418. this.changeImg2Base64(this.shottingImg, false);
  419. console.warn("***shottingImg***",this.shottingImg)
  420. if(type==1){
  421. let param = {
  422. type: 'CLK', //埋点类型
  423. clkId: 'clk_2cmina_23080413', //点击ID
  424. clkName: 'AIcreate_clk', //点击前往的页面名称
  425. clkParams: {
  426. locusName: "AI生成",
  427. userparamter:{
  428. shottingImg:this.shottingImg,
  429. style:this.styleList[this.curStyleIndex].styleName
  430. }
  431. }
  432. };
  433. util.trackRequest(param);
  434. }else{
  435. let param = {
  436. type: 'CLK', //埋点类型
  437. clkId: 'clk_2cmina_23080419', //点击ID
  438. clkName: 'continueAIcreate_clk', //点击前往的页面名称
  439. clkParams: {
  440. locusName: "继续生成",
  441. userparamter:{
  442. shottingImg:this.shottingImg,
  443. style:this.styleList[this.curStyleIndex].styleName
  444. }
  445. }
  446. };
  447. util.trackRequest(param);
  448. }
  449. },
  450. image2Base64(imgUrl) {//导入的图片路径
  451. var toBase64= new Promise(function(resolve, reject){
  452. window.URL = window.URL || window.webkitURL;
  453. var xhr = new XMLHttpRequest();
  454. xhr.open("get", imgUrl, true);
  455. // 至关重要
  456. xhr.responseType = "blob";//文件流
  457. xhr.onload = function (res) {
  458. if (res.currentTarget.status == 200) {
  459. //得到一个blob对象
  460. var blob = res.currentTarget.response;
  461. // 至关重要
  462. let oFileReader = new FileReader();
  463. oFileReader.onloadend = function (e) {
  464. let base64 = e.target.result;//base64
  465. resolve(base64)
  466. };
  467. oFileReader.readAsDataURL(blob);
  468. }
  469. }
  470. xhr.send();
  471. });
  472. return toBase64;
  473. },
  474. changeImg2Base64(url, isRepeat) {
  475. var self = this;
  476. if(isRepeat && self.inputBase64Url){//重复使用
  477. self.startServer();
  478. }else{
  479. // self.inputBase64Url = Base64Url;
  480. // console.log("生成inputBase64Url");
  481. this.image2Base64(url).then(base64 => {
  482. self.inputBase64Url = base64;
  483. self.startServer();
  484. })
  485. // uni.request({
  486. // url: url,
  487. // method: "GET",
  488. // responseType: "arraybuffer",
  489. // success: async (res) => {
  490. // let base64 = wx.arrayBufferToBase64(res.data);
  491. // let Base64Url = "data:image/jpeg;base64," + base64;
  492. // // console.log('base64:', Base64Url);
  493. // self.inputBase64Url = Base64Url;
  494. // console.log("生成inputBase64Url");
  495. // self.startServer();
  496. // },
  497. // });
  498. }
  499. },
  500. //开始图生图流程
  501. async startServer() {
  502. if(!this.styleList || this.curStyleIndex < 0 || !this.styleList[this.curStyleIndex].imgUrl){
  503. return false
  504. }
  505. let imgUrl = this.styleList[this.curStyleIndex].imgUrl;
  506. // let base64Url = await this.image2Base64(imgUrl);
  507. let data = {
  508. "configType": "AI_Biography",
  509. "keyvalue": "ControlNet_IpAdapter",
  510. "model": "ip-adapter_xl [4209e9f7]",
  511. "cpu": "ip-adapter_clip_sdxl",
  512. "session_hash": Date.now(),
  513. "weight": 1.5,
  514. "number1": -1,
  515. "number2": -1,
  516. "number3": 0,
  517. "number4": 1,
  518. // "imageBase64": base64Url,
  519. "imageUrl":imgUrl,
  520. }
  521. let res1 = await requestConfig("AIuploadImgControlNet", data);
  522. if(!res1 || !res1.single){
  523. this.showToast("渲染失败,请重试");
  524. this.aiFlag = false;
  525. this.aiImage = "";
  526. return false;
  527. }
  528. let session_hash = data.session_hash;
  529. data.model = "sai_xl_canny_256lora [566f20af]";
  530. data.keyvalue = "ControlNet_Canny";
  531. data.cpu = "canny";
  532. data.weight = 0.8;
  533. data.number1 = 100;
  534. data.number2 = 200;
  535. data.number3 = 0;
  536. data.number4 = 1;
  537. data.imageBase64 = this.inputBase64Url;
  538. let res2 = await requestConfig("AIuploadImgControlNet", data);
  539. if(!res2 || !res2.success){
  540. this.showToast("渲染失败,请重试");
  541. this.aiFlag = false;
  542. this.aiImage = "";
  543. return false;
  544. }
  545. data.model = "t2iadapter_seg_sd14v1 [6387afb5]";
  546. data.keyvalue = "ControlNet_Seg";
  547. data.cpu = "seg_ofade20k";
  548. data.weight = 0.8;
  549. data.number1 = -1;
  550. data.number2 = -1;
  551. data.number3 = 0;
  552. data.number4 = 1;
  553. data.imageBase64 = this.inputBase64Url;
  554. let res3 = await requestConfig("AIuploadImgControlNet", data);
  555. if(!res3 || !res3.success){
  556. this.showToast("渲染失败,请重试");
  557. this.aiFlag = false;
  558. this.aiImage = "";
  559. return false;
  560. }
  561. const prompt = this.styleList[this.curStyleIndex].prompt;
  562. const noPromot = this.styleList[this.curStyleIndex].negativePrompt;
  563. let unit = 768 / window.screen.width;
  564. this.imageWidth = parseInt((window.screen.width * unit).toFixed());
  565. this.imageHeight = parseInt((this.$parent.canvasHeight * unit).toFixed());
  566. // this.$parent.canvasHeight = window.screen.height - (208 * unit);
  567. var parmas = {
  568. negativePrompt: noPromot,
  569. prompt: prompt,
  570. "batchSize": 1,
  571. brandId: $config.brandId,
  572. height: this.imageHeight,
  573. width: this.imageWidth,
  574. "moduleType": "AI_Biography",
  575. "keyword":"img_2_img",
  576. "steps":20,
  577. "sampler":"DDIM",
  578. "controlNetSessionHash":session_hash,
  579. "cfgScale":12,
  580. "denoising":0.9
  581. };
  582. let res = await requestConfig("generateTaskImgToImgForAliyun", parmas);
  583. console.log("图生图结果:", res);
  584. if(this.$parent.pvCurPageName!="room_show"){//说明用户切换页面了
  585. console.warn("***用户已经退出页面***")
  586. return false;
  587. }
  588. let that = this;
  589. if (res.success && res.single) {
  590. if(typeof(res.single)=="object"){
  591. let cot = res.single.queueCount || 1;
  592. this.showToast("正有"+cot+"人排队,预计等待"+cot*25+"秒");
  593. this.aiImage = "";
  594. this.aiFlag = false;
  595. this.clearInterval();
  596. return false;
  597. }
  598. this.taskId = res.single;
  599. if (!this.img2imgTimer) {
  600. this.count = 0;
  601. this.random = 1;
  602. this.img2imgTimer = setInterval(() => {
  603. this.count ++;
  604. this.getResultForImgToImg();
  605. }, 1000);
  606. }
  607. }else{
  608. this.aiFlag = false;
  609. this.aiImage = "";
  610. this.showToast("渲染失败,请重试")
  611. }
  612. },
  613. // 轮询获取图片结果
  614. async getResultForImgToImg() {
  615. var parmas = {
  616. id: this.taskId,
  617. };
  618. let res = await requestConfig("generateProcess", parmas);
  619. // let lastPage = getCurrentPages()[getCurrentPages().length - 2] ? getCurrentPages()[getCurrentPages().length - 2].$vm : null;
  620. // console.warn("图生图轮询结果:", res);
  621. if (res.success && res.single) {
  622. if (res.single.inQueue == false) {
  623. if (res.single.urls) {
  624. // uni.hideLoading();
  625. this.aiFlag = false;
  626. this.random = 100;
  627. console.warn("图生图轮询结束: ", res);
  628. this.aiImage = res.single.urls[0];
  629. this.showAIFlag = true;
  630. let newImage = this.aiImage;
  631. let aiStyleName = this.styleList[this.curStyleIndex].styleName;
  632. let _data = {
  633. image:newImage,
  634. checked:false,
  635. list:[newImage],
  636. }
  637. this.aiImagesList.push(_data);
  638. this.showAIImage = true;//显示AI结果集合-因为生成了AI图片
  639. if(this.$parent && typeof(this.$parent.clearHandle)=="function" ){
  640. this.$parent.clearHandle();
  641. }
  642. let cpAiData = JSON.parse(JSON.stringify(this.aiData)) || []
  643. if(cpAiData){//给上一个页面回传生成的数据
  644. let space = cpAiData.find(it=>{
  645. return it.houseFloor == this.curHouseObj.houseFloor && it.spaceId == this.spaceObj.spaceId
  646. })
  647. if(space){
  648. let data ={
  649. aiStyleName:aiStyleName,
  650. image:newImage,
  651. checked:false,
  652. }
  653. space.aiImagesList.push(data);
  654. }else{//不存在则构建数据
  655. let data = {
  656. houseFloor:this.curHouseObj.houseFloor,//当前的楼层
  657. spaceId:this.spaceObj.spaceId,
  658. aiImagesList:[
  659. {
  660. aiStyleName:aiStyleName,
  661. image:newImage,
  662. checked:false,
  663. }
  664. ]
  665. }
  666. cpAiData.push(data)
  667. }
  668. this.$store.dispatch('setAiData', cpAiData)
  669. }
  670. this.clearInterval();
  671. if(this.aiImagesList.length>1){
  672. setTimeout(()=>{
  673. this.$refs.carousel.next();
  674. }, 1000);
  675. }
  676. } else {
  677. if (!res.success) {
  678. this.showToast("渲染失败,请重试")
  679. this.aiFlag = false;
  680. this.aiImage = "";
  681. this.clearInterval();
  682. }else {
  683. this.random = parseInt(this.count * 2);
  684. if(this.random>=100){
  685. this.random = 99;
  686. }
  687. if(!this.showAIImage){
  688. // this.$store.state.loadingMsg='生成中…' + this.random + '%';
  689. this.loadingMsg = '生成中…' + this.random + '%';
  690. }else{
  691. }
  692. }
  693. }
  694. } else {
  695. let cot = res.single.queueCount || 1;
  696. this.showToast("正有"+cot+"人排队,预计等待"+cot*25+"秒");
  697. this.aiImage = "";
  698. this.aiFlag = false;
  699. this.clearInterval();
  700. }
  701. }
  702. },
  703. showToast(title){
  704. this.$store.state.loading = true;
  705. this.$store.state.loadingMsg = title || "";
  706. setTimeout(()=>{
  707. this.$store.state.loading = false;
  708. }, 3000);
  709. }
  710. }
  711. }
  712. </script>
  713. <style lang="scss" scoped>
  714. @import "./viewMask.scss";
  715. </style>
  716. <style lang="css" scoped>
  717. /* @import "@/common/css/common.css"; */
  718. </style>