viewMask.vue 22 KB

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