ys.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. <template>
  2. <view class="template-details">
  3. <block v-if="showdrawing">
  4. <u-notice-bar v-if="drawingtitle=='正在努力绘制中...'||drawingtitle=='图片正在渲染中...'" :text="noticebar" step
  5. bgColor="#000"></u-notice-bar>
  6. <view class="lazy-loading tn-flex justify-center align-center flex-wrap">
  7. <view class="preloader_1">
  8. <view></view>
  9. <view></view>
  10. <view></view>
  11. <view></view>
  12. <view></view>
  13. </view>
  14. <view class="drawing">
  15. {{drawingtitle}}
  16. </view>
  17. <view v-if="showprogress" class="progress">
  18. <u-line-progress :percentage="percentage" activeColor="#9b59b6" height="18"></u-line-progress>
  19. </view>
  20. </view>
  21. </block>
  22. <swiper class="card-swiper" :circular="false" :autoplay="true" duration="500" interval="12000"
  23. @change="cardSwiper">
  24. <swiper-item v-for="(item,index) in swiperList" :key="index" :class="cardCur==index?'cur':''">
  25. <view class="lazy-load" :style="{height: windowHeight+'px'}">
  26. <u--image @load="previewload" @error="previewerror" width="100%" height="100%" :src="item"
  27. mode="widthFix">
  28. <view slot="error" style="font-size: 32rpx;text-align: center;">
  29. 图片加载失败
  30. </view>
  31. </u--image>
  32. </view>
  33. </swiper-item>
  34. </swiper>
  35. <view class="tabbar footerfixed dd-glass tn-color-white" style="border-radius: 100rpx;">
  36. <view class="action" @click="getisback">
  37. <view class="bar-icon">
  38. <view class="tn-icon-left-circle">
  39. </view>
  40. <!-- <image class="" src='https://tnuiimage.tnkjapp.com/tabbar/a1.png'></image> -->
  41. </view>
  42. <view class="">立即返回</view>
  43. </view>
  44. <view class="action" @click="getdownload(cardCur)">
  45. <view class="bar-icon">
  46. <view class="tn-icon-download">
  47. </view>
  48. <!-- <image class="" src='https://tnuiimage.tnkjapp.com/tabbar/k2.png'></image> -->
  49. </view>
  50. <view class="">下载/分享</view>
  51. </view>
  52. <!-- <view class="action" @click="parameters">
  53. <view class="bar-icon">
  54. <view class="tn-icon-creative">
  55. </view>
  56. </view>
  57. <view class="">绘画参数</view>
  58. </view> -->
  59. <view class="action" @click="preViewImg(1)" v-if="true">
  60. <view class="bar-icon">
  61. <view class="tn-icon-image">
  62. </view>
  63. </view>
  64. <view class="">上传模板图</view>
  65. </view>
  66. <view class="action" @click="preViewImg(2)" v-if="true
  67. ">
  68. <view class="bar-icon">
  69. <view class="tn-icon-image">
  70. </view>
  71. </view>
  72. <view class="">上传照片</view>
  73. </view>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. import {
  79. mapMutations,
  80. mapActions,
  81. mapState,
  82. mapGetters
  83. } from 'vuex';
  84. import {
  85. apiurl
  86. } from '@/common/request/request';
  87. let rewardedVideoAd = null;
  88. export default {
  89. mixins: [],
  90. components: {},
  91. data() {
  92. return {
  93. showdrawing: true,
  94. drawingtitle: '正在努力绘制中...',
  95. showprogress: false,
  96. percentage: 0,
  97. noticebar: ['精美图片需要时间打磨,预计20-30秒左右出图',
  98. '图片生成中请不要退出此页面,否则可能会无法生成'
  99. // '长时间未出图?可稍后在 我的-绘画记录 里查看'
  100. ],
  101. tobheight: 45,
  102. parmas: null,
  103. show1: false,
  104. show2: true,
  105. cardCur: 0,
  106. swiperList: [],
  107. form: {},
  108. parameter: {},
  109. parameterid: 0,
  110. showopen: false,
  111. failnum: 0,
  112. windowHeight: 0,
  113. engin: '',
  114. progress: 0,
  115. isDowload: false,
  116. show: false,
  117. sd_keywords: '',
  118. }
  119. },
  120. async onLoad(o) {
  121. // this.parmas = JSON.parse(o.ysParmas)
  122. this.parmas = getApp().ysParmas
  123. var that = this;
  124. this.windowHeight = uni.$u.sys().windowHeight - 60
  125. // this.parmas = {
  126. // templateUrl: "https://zhengda.oss-accelerate.aliyuncs.com/new_fanyun/0d47db66-1faf-42df-a732-22cf18697a65.jpg",
  127. // userUrl: "https://oaigc.oss-cn-chengdu.aliyuncs.com/20240205/d4f3699caf01faecdf37fc8d3573975b.jpg"
  128. // }
  129. console.log('接收的生成参数', this.parmas);
  130. // return
  131. let res = await this.$http('ys.addFaceTask', this.parmas)
  132. console.log('提交艺术照任务返回值---', res);
  133. if (res.code == 0) {
  134. // this.showdrawing = false
  135. this.swiperList = [res.msg.image_url]
  136. console.log('this.swiperList--------------', this.swiperList);
  137. }
  138. },
  139. onUnload() {
  140. clearTimeout(timingr);
  141. clearTimeout(asynchronous);
  142. },
  143. methods: {
  144. preViewImg(type) {
  145. if (type == 1) {
  146. uni.previewImage({
  147. urls: [this.parmas.templateUrl],
  148. longPressActions: {
  149. itemList: ['发送给朋友', '保存图片', '收藏'],
  150. success: function(data) {},
  151. fail: function(err) {
  152. console.log(err.errMsg);
  153. }
  154. }
  155. });
  156. } else {
  157. uni.previewImage({
  158. urls: [this.parmas.userUrl],
  159. longPressActions: {
  160. itemList: ['发送给朋友', '保存图片', '收藏'],
  161. success: function(data) {},
  162. fail: function(err) {
  163. console.log(err.errMsg);
  164. }
  165. }
  166. });
  167. }
  168. },
  169. parameters() {
  170. var that = this;
  171. // if(that.showdrawing){
  172. // uni.showToast({
  173. // title:'图片生成中',
  174. // icon:'none'
  175. // })
  176. // return;
  177. // }
  178. that.show1 = true
  179. },
  180. setOpen() {
  181. var that = this;
  182. if (that.showdrawing) {
  183. uni.showToast({
  184. title: '图片生成中',
  185. icon: 'none'
  186. })
  187. return;
  188. }
  189. if (that.showopen) {
  190. uni.showToast({
  191. title: '图片已公开',
  192. icon: 'none'
  193. })
  194. return;
  195. }
  196. uni.showModal({
  197. confirmColor: '#207CF7',
  198. confirmText: '确认公开',
  199. title: '提示',
  200. content: '是否确认公开此绘画作品',
  201. success(src) {
  202. if (src.confirm) {
  203. that.$http('gallery.setOpen', {
  204. id: that.parameterid
  205. }).then(res => {
  206. if (res.code == 0) {
  207. uni.showToast({
  208. title: '提交成功,等待审核'
  209. })
  210. that.showopen = true
  211. }
  212. });
  213. }
  214. }
  215. });
  216. },
  217. gallerydetail(id) {
  218. let that = this;
  219. this.$http('gallery.detail', {
  220. id: id
  221. }).then(res => {
  222. if (res.code == 0) {
  223. console.log('获取到的图片详情返回值:', res);
  224. // this.showdrawing = false
  225. this.parameter = res.data
  226. //this.parameter.prompt =
  227. //'https://mjcdn.iduomi.cc/attachments/1124768570157564029/1129053571321712670/erinramirez_In_a_Chinese_ancient_garden_a_lady_is_playing_the_t_cff28ad6-6f7e-44f0-a7bb-2a8724e573f2.png 关键词测试测'
  228. // this.parameter.prompt = '123'
  229. if (this.parameter.prompt.includes('http') && this.parameter.prompt.includes('.png')) {
  230. this.parameter.refImg = this.parameter.prompt.split('.png')[0] + '.png'
  231. // 创作相似去参考图提示词
  232. let tempKeyWord = ''
  233. this.parameter.prompt.split('.png').forEach((item, index) => {
  234. if (!item.includes('http')) {
  235. tempKeyWord += item
  236. }
  237. })
  238. this.parameter.promptSame = tempKeyWord
  239. this.parameter.prompt = tempKeyWord
  240. } else if (this.parameter.prompt.includes('http') && this.parameter.prompt.includes(
  241. '.jpeg')) {
  242. this.parameter.refImg = this.parameter.prompt.split('.jpeg')[0] + '.jpeg'
  243. // 创作相似去参考图提示词
  244. let tempKeyWord = ''
  245. this.parameter.prompt.split('.jpeg').forEach((item, index) => {
  246. if (!item.includes('http')) {
  247. tempKeyWord += item
  248. }
  249. })
  250. this.parameter.promptSame = tempKeyWord
  251. this.parameter.prompt = tempKeyWord
  252. } else if (this.parameter.prompt.includes('http') && this.parameter.prompt.includes(
  253. '.jpg')) {
  254. this.parameter.refImg = this.parameter.prompt.split('.jpg')[0] + '.jpg'
  255. // 创作相似去参考图提示词
  256. let tempKeyWord = ''
  257. this.parameter.prompt.split('.jpg').forEach((item, index) => {
  258. if (!item.includes('http')) {
  259. tempKeyWord += item
  260. }
  261. })
  262. this.parameter.promptSame = tempKeyWord
  263. this.parameter.prompt = tempKeyWord
  264. } else {
  265. this.parameter.promptSame = this.parameter.prompt
  266. }
  267. console.log('创作相似prompt', this.parameter.promptSame);
  268. if (this.engin == 'sd') {
  269. for (var i = 0; i < res.data.imgs_file.length; i++) {
  270. var url = {
  271. id: i,
  272. type: 'image',
  273. url: res.data.imgs_file[i],
  274. }
  275. that.swiperList.push(url)
  276. }
  277. this.done = true
  278. } else {
  279. var url = {
  280. id: 0,
  281. type: 'image',
  282. url: res.data.origin_url,
  283. }
  284. that.swiperList.push(url)
  285. this.done = true
  286. }
  287. } else {
  288. }
  289. });
  290. },
  291. aiPlay() {
  292. let that = this;
  293. this.showdrawing = true
  294. if (that.failnum == 0) {
  295. this.progressbar()
  296. }
  297. this.$http('gallery.create', this.form).then(res => {
  298. if (res.code == 0) {
  299. this.showTask(res.data.id)
  300. } else {
  301. uni.hideToast()
  302. uni.showModal({
  303. confirmText: '退出',
  304. showCancel: false,
  305. confirmColor: '#207CF7',
  306. title: '提示',
  307. content: res.msg,
  308. success(tit) {
  309. if (tit.confirm) {
  310. uni.navigateBack()
  311. }
  312. }
  313. })
  314. }
  315. });
  316. },
  317. progressbar() {
  318. var that = this;
  319. if (that.percentage < 99) {
  320. timingr = setTimeout(() => {
  321. that.percentage = uni.$u.range(0, 99, that.percentage + 1)
  322. that.progressbar()
  323. }, 300);
  324. } else {
  325. clearTimeout(timingr);
  326. }
  327. },
  328. showTask(id) {
  329. let that = this;
  330. this.$http('gallery.getOpensdDetail', {
  331. id: id,
  332. }).then(res => {
  333. if (res.code == 0) {
  334. if (res.data.state == "success") {
  335. this.percentage = 99
  336. this.drawingtitle = '图片正在渲染中,请不要退出此页面'
  337. this.parameterid = res.data.id
  338. this.done = true
  339. clearTimeout(asynchronous);
  340. var url = {
  341. id: 0,
  342. type: 'image',
  343. url: res.data.gen_img,
  344. }
  345. that.swiperList.push(url)
  346. } else if (res.data.state == "in_create") {
  347. asynchronous = setTimeout(() => {
  348. that.showTask(id)
  349. }, 1000);
  350. return;
  351. } else if (res.data.state == "in_wait") {
  352. asynchronous = setTimeout(() => {
  353. that.showTask(id)
  354. }, 1000);
  355. return;
  356. } else {
  357. uni.showModal({
  358. confirmText: '退出',
  359. showCancel: false,
  360. confirmColor: '#207CF7',
  361. title: '提示',
  362. content: res.msg,
  363. success(tit) {
  364. if (tit.confirm) {
  365. uni.navigateBack()
  366. }
  367. }
  368. })
  369. }
  370. } else {
  371. uni.showModal({
  372. confirmText: '退出',
  373. showCancel: false,
  374. confirmColor: '#207CF7',
  375. title: '提示',
  376. content: res.msg,
  377. success(tit) {
  378. if (tit.confirm) {
  379. uni.navigateBack()
  380. }
  381. }
  382. })
  383. }
  384. })
  385. },
  386. previewload() {
  387. // console.log('ch');
  388. this.showdrawing = false
  389. this.percentage = 0
  390. },
  391. previewerror() {
  392. this.showdrawing = false
  393. this.percentage = 0
  394. },
  395. preview(e) {
  396. uni.previewImage({
  397. urls: [e]
  398. })
  399. },
  400. is_weixin() {
  401. var ua = window.navigator.userAgent.toLowerCase();
  402. if (ua.match(/MicroMessenger/i) == 'micromessenger') {
  403. console.log('微信浏览器');
  404. return true;
  405. } else {
  406. console.log("不是微信浏览器");
  407. return false;
  408. }
  409. },
  410. //下载分享
  411. getdownload(index) {
  412. if (this.showdrawing) {
  413. uni.showToast({
  414. title: '图片生成中',
  415. icon: 'none'
  416. })
  417. return;
  418. }
  419. uni.showModal({
  420. showCancel: false,
  421. title: '提示',
  422. content: '请在微信内置浏览器打开,长按图片下载/分享',
  423. confirmColor: '#207CF7'
  424. })
  425. return
  426. console.log('要下载的图片地址:', this.swiperList[0]);
  427. let url = this.swiperList[0]
  428. // return
  429. const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i
  430. .test(
  431. navigator.userAgent) ? false : true;
  432. if (this.is_weixin()) {
  433. uni.showModal({
  434. showCancel: false,
  435. title: '提示',
  436. content: '请在微信内置浏览器打开,长按图片下载/分享',
  437. confirmColor: '#207CF7'
  438. })
  439. } else {
  440. if (detectDeviceType()) {
  441. let _this = this
  442. // if (_this.isDowload) {
  443. // uni.showToast({
  444. // icon: 'none',
  445. // title: '请等待上一个视频下载完成后,再下载',
  446. // });
  447. // }
  448. // PC端
  449. // this.delItem.url = 'http://www.liwantao.top/test.mp4'
  450. const downloadTask = uni.downloadFile({
  451. url, //文件链接
  452. timeout: 99999999,
  453. success: (res) => {
  454. if (res.statusCode === 200) {
  455. var oA = document.createElement("a");
  456. // oA.download = _this.delItem.name; // 设置下载的文件名,默认是'下载'
  457. oA.href = res.tempFilePath; //临时路径再保存到本地
  458. document.body.appendChild(oA);
  459. oA.click();
  460. oA.remove(); // 下载之后把创建的元素删除
  461. }
  462. },
  463. fail: (err) => {
  464. _this.show = false;
  465. _this.isDowload = false
  466. _this.progress = 0
  467. // console.log(_this.show, _this.isDowload, _this.progress, err);
  468. uni.showToast({
  469. icon: 'none',
  470. mask: true,
  471. title: '失败请重新下载',
  472. });
  473. },
  474. })
  475. downloadTask.onProgressUpdate((res) => {
  476. if (res.progress > 0) {
  477. _this.show = true;
  478. _this.isDowload = true
  479. }
  480. _this.progress = res.progress;
  481. if (res.progress == 100) {
  482. _this.show = false;
  483. _this.isDowload = false
  484. _this.progress = 0
  485. uni.showToast({
  486. icon: 'success',
  487. title: '图片下载成功!',
  488. });
  489. }
  490. })
  491. } else {
  492. uni.showModal({
  493. showCancel: false,
  494. title: '提示',
  495. content: '请在微信内置浏览器打开,长按图片下载/分享',
  496. confirmColor: '#207CF7'
  497. })
  498. return
  499. // 其他移动端浏览器
  500. // window.open(this.delItem.url)
  501. let _this = this
  502. // this.delItem.url = 'http://www.liwantao.top/test.mp4'
  503. var oA = document.createElement("a");
  504. // oA.download = _this.delItem.name;
  505. oA.href = url;
  506. document.body.appendChild(oA);
  507. oA.click();
  508. oA.remove();
  509. }
  510. }
  511. },
  512. getisback() {
  513. uni.navigateBack()
  514. },
  515. // 跳转
  516. tn(e) {
  517. // console.log(e);
  518. uni.navigateTo({
  519. url: e,
  520. });
  521. },
  522. // cardSwiper
  523. cardSwiper(e) {
  524. // console.log(e.detail);
  525. this.cardCur = e.detail.current
  526. },
  527. // 弹出压屏窗
  528. showLandscape() {
  529. this.openLandscape()
  530. },
  531. // 打开压屏窗
  532. openLandscape() {
  533. this.show1 = true
  534. },
  535. // 关闭压屏窗
  536. closeLandscape() {
  537. this.show1 = false
  538. },
  539. }
  540. }
  541. </script>
  542. <style lang="scss" scoped>
  543. @import './ys.scss';
  544. </style>