draw.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. <template>
  2. <view>
  3. <view style="color: #fff;">
  4. <tn-nav-bar backgroundColor="#26B3A0" :bottomShadow="false">绘画记录</tn-nav-bar>
  5. </view>
  6. <z-paging ref="paging" refresher-complete-delay="200" v-model="drawList" @query="queryList">
  7. <view slot="top" class="z_tabs" :style="{ marginTop: tobheight + 'px' }"></view>
  8. <view class="u-flex flex-wrap">
  9. <block v-for="(item,index) in drawList" :key="index">
  10. <view class="draw_view">
  11. <view v-if="item.imgs_file.length>1" class="sheets">
  12. {{item.imgs_file.length}}张
  13. </view>
  14. <view v-if="item.done == 1&&item.status == 1" class="draw_image u-flex align-center">
  15. <image @click="preview(index)" :src="item.imgs_file[item.steps]?item.imgs_file[item.steps]:item.origin_url" mode="widthFix"></image>
  16. <view v-if="item.imgs_file.length>1" class="imgs_arrow u-flex align-center justify-between">
  17. <view @click.stop="item.steps==0?'':item.steps--" class="arrow"><u-icon name="arrow-left" color="#fff" size="28"></u-icon></view>
  18. <view @click.stop="item.steps==item.imgs_file.length - 1?'':item.steps++" class="arrow"><u-icon name="arrow-right" color="#fff" size="28"></u-icon></view>
  19. </view>
  20. </view>
  21. <view v-else class="draw_done u-flex align-center justify-center">
  22. <block v-if="item.done == 1">
  23. {{item.status == 0?'图片正在审核中...':item.status == 2?'图片审核不通过':'图片审核通过'}}
  24. </block>
  25. <block v-else>
  26. {{item.done == 0?'图片正在生成中...':item.done == 2?'图片生成失败':'图片生成成功'}}
  27. </block>
  28. </view>
  29. <view class="prompt"><u-parse :content="item.prompt" :selectable="true"></u-parse></view>
  30. <view class="create_time">AI绘画:{{item.engine == 'sd'?'StableDiffusion绘图':'MidJourney绘图'}}</view>
  31. <view class="create_time">创建时间:{{item.create_time}}</view>
  32. <!-- <view v-if="item.done == 1&&item.status == 1" @click="createPoster(index)" hover-class="hoversubmit" class="onekey">生成海报</view> -->
  33. <block v-if="item.engine == 'sd'">
  34. <view v-if="item.done == 1&&item.status == 1" class="tn-flex justify-between operate">
  35. <view @click="tnproduct(item.id,item.engine)" hover-class="hoversubmit" class="onekey">绘画详情</view>
  36. <view @click="createPoster(index,item.steps)" hover-class="hoversubmit" class="onekey" style="background: #FFC107;">生成海报</view>
  37. </view>
  38. </block>
  39. <block v-else>
  40. <view v-if="item.done == 1&&item.status == 1" class="tn-flex justify-between operate">
  41. <view @click="createPoster(index,item.steps)" hover-class="hoversubmit" class="onekey" style="background: #FFC107;width: 100%;">生成海报</view>
  42. </view>
  43. </block>
  44. <view v-if="item.done > 0&&item.status > 0" class="circle" @click.stop="gallerydel(index)">
  45. <u-icon name="close-circle-fill" color="#e83a30" size="24"></u-icon>
  46. </view>
  47. </view>
  48. </block>
  49. </view>
  50. </z-paging>
  51. <wike-loading-page :isLoading="isLoading"></wike-loading-page>
  52. <u-popup :show="showPoster" mode="bottom" @close="showPoster = false">
  53. <scroll-view scroll-y="true" :style="{maxHeight: (posterheight) +'px'}">
  54. <wike-painter :board="posterObj" @done="posterSuccess" ref="painter"></wike-painter>
  55. <view style="height: 78px;"></view>
  56. <view class="dygbhg" >
  57. <view class="whole" @click="showPoster = false">取消</view>
  58. <view class="distinguish" @click="toSave">保存/分享</view>
  59. </view>
  60. </scroll-view>
  61. </u-popup>
  62. </view>
  63. </template>
  64. <script>
  65. import { mapMutations, mapActions, mapState, mapGetters } from 'vuex';
  66. export default {
  67. data() {
  68. return {
  69. tobheight: 45,
  70. platform: this.$platform.get(),
  71. isLoading: true,
  72. drawList:[],
  73. showPoster:false,
  74. posterheight:'',
  75. qrcode:'',
  76. posterObj:{},
  77. subsectionlist: ['第1张图片', '第2张图片', '第3张图片'],
  78. current:0
  79. }
  80. },
  81. computed: {
  82. ...mapGetters(['appInfo', 'userInfo', 'isLogin'])
  83. },
  84. onLoad() {
  85. const that = this;
  86. if (this.platform == 'wxMiniProgram') {
  87. var menumtop = uni.getMenuButtonBoundingClientRect().top - uni.getSystemInfoSync().statusBarHeight;
  88. var paddingtop = uni.getSystemInfoSync().statusBarHeight + menumtop;
  89. this.tobheight = menumtop + paddingtop + uni.getMenuButtonBoundingClientRect().height;
  90. }
  91. this.posterheight = uni.$u.sys().windowHeight-this.tobheight
  92. this.commonqrcodePath();
  93. },
  94. methods: {
  95. queryList(pageNo, pageSize) {
  96. //这里的pageNo和pageSize会自动计算好,直接传给服务器即可
  97. const params = {
  98. page: pageNo,
  99. limit: pageSize
  100. };
  101. this.$http('gallery.list', params).then(res => {
  102. if (res.code == 0) {
  103. uni.setNavigationBarTitle({
  104. title: this.appInfo.site_name
  105. });
  106. this.$refs.paging.complete(res.data.data);
  107. this.isLoading = false;
  108. }
  109. });
  110. },
  111. commonqrcodePath() {
  112. let spm = this.userInfo.id+'.1.0.'+this.spmplatform+'.1';
  113. this.$http('common.qrcodePath',{spm:spm}).then(res => {
  114. if (res.code == 0) {
  115. this.qrcode = res.data;
  116. }
  117. });
  118. },
  119. getdownload(e,type){
  120. return new Promise((resolve, reject) => {
  121. // uni.getImageInfo({
  122. // src: e,
  123. // success: res => {
  124. // uni.downloadFile({
  125. // url: e,
  126. // success: (res) => {
  127. // if (res.statusCode === 200) {
  128. // resolve(res.tempFilePath);
  129. // }
  130. // if(res.statusCode === 404){
  131. // let head = '/static/images/head.jpg',open = '/static/images/open.png';
  132. // if(type == 1){
  133. // resolve(head);
  134. // }else{
  135. // resolve(open);
  136. // }
  137. // }
  138. // }
  139. // });
  140. // },
  141. // fail: err => {
  142. // let head = '/static/images/head.jpg',open = '/static/images/open.png';
  143. // if(type == 1){
  144. // resolve(head);
  145. // }else{
  146. // resolve(open);
  147. // }
  148. // }
  149. // })
  150. uni.request({
  151. url: e,
  152. method:'GET',
  153. responseType:'arraybuffer',
  154. success: ress => {
  155. let base64 = wx.arrayBufferToBase64(ress.data);
  156. base64 = 'data:image/jpeg;base64,' + base64
  157. resolve(base64);
  158. },
  159. fail: (e) => {
  160. let head = '/static/images/head.jpg',open = '/static/images/open.png';
  161. if(type == 1){
  162. resolve(head);
  163. }else{
  164. resolve(open);
  165. }
  166. }
  167. })
  168. });
  169. },
  170. toSave() {
  171. uni.showLoading({
  172. title: '海报生成中'
  173. });
  174. this.$refs.painter.canvasToTempFilePathSync({
  175. // 在nvue里是jpeg
  176. fileType: 'jpg',
  177. quality: 1,
  178. success: res => {
  179. // this.path = res.tempFilePath;
  180. // this.$refs.posterImg.open();
  181. // this.show_poster = true;
  182. // console.log(res.tempFilePath);
  183. // 非H5 保存到相册
  184. // H5 提示用户长按图另存
  185. // #ifdef MP-WEIXIN
  186. // uni.saveImageToPhotosAlbum({
  187. // filePath: res.tempFilePath,
  188. // success: function() {
  189. // uni.showToast({
  190. // title: '保存成功'
  191. // });
  192. // that.showPoster = false;
  193. // }
  194. // });
  195. wx.showShareImageMenu({
  196. path: res.tempFilePath
  197. })
  198. this.showPoster = false;
  199. uni.hideLoading();
  200. // #endif
  201. // #ifdef H5
  202. this.showPoster = false;
  203. uni.hideLoading();
  204. uni.showModal({
  205. confirmColor: '#26B3A0',
  206. confirmText: '查看图片',
  207. title: '提示',
  208. content: '查看图片后长按图片即可保存或分享',
  209. success(src) {
  210. if (src.confirm) {
  211. uni.previewImage({
  212. urls: [res.tempFilePath]
  213. });
  214. } else if (src.cancel) {
  215. this.showPoster = true;
  216. }
  217. }
  218. });
  219. // #endif
  220. }
  221. });
  222. },
  223. posterSuccess(){
  224. uni.hideLoading();
  225. },
  226. tnproduct(id,engine){
  227. uni.navigateTo({
  228. url:engine=='sd'?'/pages/painting/details?urls='+id:'/pages/painting/generate?urls='+id
  229. })
  230. },
  231. async createPoster(e,steps) {
  232. let that = this;
  233. let stays = '';
  234. let site_logo = '';
  235. uni.showLoading({
  236. title: '海报渲染中'
  237. });
  238. let mode = that.drawList[e].engine == 'sd'?'StableDiffusion绘图':'MidJourney绘图';
  239. let avatar_logo = that.userInfo.avatar ? await this.getdownload(that.userInfo.avatar,1):'/static/images/head.jpg';
  240. if(that.appInfo.site_logo_path.indexOf("https") < 0){
  241. site_logo = that.appInfo.site_logo_path ? await that.getdownload(that.appInfo.site_logo_path.replace("http:", "https:"),2):'/static/images/open.png';
  242. }else{
  243. site_logo = that.appInfo.site_logo_path ? await that.getdownload(that.appInfo.site_logo_path,2):'/static/images/open.png';
  244. }
  245. // console.log(that.drawList[e].imgs_file[steps]);
  246. if(that.drawList[e].imgs_file){
  247. if(that.drawList[e].imgs_file[steps].indexOf("https") < 0){
  248. stays = await that.getdownload(that.drawList[e].imgs_file[steps].replace("http:", "https:"),2);
  249. }else{
  250. stays = await that.getdownload(that.drawList[e].imgs_file[steps],2);
  251. }
  252. }else{
  253. if(that.drawList[e].origin_url.indexOf("https") < 0){
  254. stays = await that.getdownload(that.drawList[e].origin_url.replace("http:", "https:"),2);
  255. }else{
  256. stays = await that.getdownload(that.drawList[e].origin_url,2);
  257. }
  258. }
  259. if(stays == '/static/images/open.png'){
  260. uni.hideLoading();
  261. uni.showToast({
  262. title:'生成失败',
  263. icon:'none'
  264. })
  265. return;
  266. }
  267. (that.posterObj = {
  268. width: uni.$u.sys().windowWidth+ 'px',
  269. background: 'linear-gradient(to right, #00ca88 0%, #00BCD4 100%)',
  270. css: {
  271. // 根节点若无尺寸,自动获取父级节点
  272. width: uni.$u.sys().windowWidth+ 'px'
  273. },
  274. views: [
  275. {
  276. type: 'view',
  277. css: {
  278. marginTop: '20rpx',
  279. paddingLeft: '10rpx',
  280. display: 'flex'
  281. },
  282. views: [
  283. {
  284. type: 'image',
  285. src: avatar_logo,
  286. css: {
  287. marginTop: '10rpx',
  288. marginLeft: '20rpx',
  289. borderRadius: '16rpx',
  290. width: '80rpx',
  291. height: '80rpx',
  292. border: '2rpx solid #fff',
  293. objectFit: 'cover'
  294. }
  295. },
  296. {
  297. type: 'view',
  298. css: {
  299. marginTop: '10rpx',
  300. marginLeft: '20rpx'
  301. },
  302. views: [
  303. {
  304. type: 'view',
  305. views: [
  306. {
  307. type: 'text',
  308. text: this.userInfo.nickname?this.userInfo.nickname:'提问者',
  309. css: {
  310. marginTop: '10rpx',
  311. fontSize: '28rpx',
  312. fontWeight: 'bold',
  313. color: '#32324A',
  314. lineHeight: '28rpx'
  315. }
  316. }
  317. ]
  318. },
  319. {
  320. type: 'view',
  321. views: [
  322. {
  323. type: 'text',
  324. text: '绘图描述词📝',
  325. css: {
  326. marginTop: '15rpx',
  327. fontSize: '20rpx',
  328. color: '#fff',
  329. lineHeight: '25rpx',
  330. }
  331. }
  332. ]
  333. }
  334. ]
  335. }
  336. ]
  337. },
  338. {
  339. type: 'view',
  340. css: {
  341. marginTop: '20rpx',
  342. width: (uni.$u.sys().windowWidth - 48) + 'px',
  343. padding: '15rpx',
  344. background: '#fff',
  345. borderRadius: '16rpx',
  346. marginLeft: '30rpx',
  347. },
  348. views: [
  349. {
  350. type: 'text',
  351. text: that.drawList[e].prompt,
  352. css: {
  353. fontSize: '28rpx',
  354. color: '#000',
  355. // lineHeight: '45rpx',
  356. // lineClamp: 2,
  357. width: (uni.$u.sys().windowWidth - 48) + 'px'
  358. }
  359. }
  360. ]
  361. },
  362. {
  363. type: 'view',
  364. css: {
  365. marginTop: '20rpx',
  366. paddingLeft: '10rpx',
  367. display: 'flex'
  368. },
  369. views: [
  370. {
  371. type: 'image',
  372. src: site_logo,
  373. css: {
  374. marginTop: '10rpx',
  375. marginLeft: '20rpx',
  376. borderRadius: '16rpx',
  377. width: '80rpx',
  378. height: '80rpx',
  379. border: '2rpx solid #fff',
  380. objectFit: 'cover'
  381. }
  382. },
  383. {
  384. type: 'view',
  385. css: {
  386. marginTop: '10rpx',
  387. marginLeft: '20rpx'
  388. },
  389. views: [
  390. {
  391. type: 'view',
  392. views: [
  393. {
  394. type: 'text',
  395. text: this.appInfo.site_name?this.appInfo.site_name:'AI智能问答机器人',
  396. css: {
  397. marginTop: '10rpx',
  398. fontSize: '28rpx',
  399. fontWeight: 'bold',
  400. color: '#32324A',
  401. lineHeight: '28rpx'
  402. }
  403. }
  404. ]
  405. },
  406. {
  407. type: 'view',
  408. views: [
  409. {
  410. type: 'text',
  411. text: mode+'结果📝',
  412. css: {
  413. marginTop: '15rpx',
  414. fontSize: '20rpx',
  415. color: '#fff',
  416. lineHeight: '25rpx',
  417. }
  418. }
  419. ]
  420. }
  421. ]
  422. }
  423. ]
  424. },
  425. {
  426. type: 'image',
  427. src: stays,
  428. css: {
  429. marginTop: '20rpx',
  430. width: (uni.$u.sys().windowWidth - 32) + 'px',
  431. objectFit: 'contain',
  432. borderRadius: '16rpx',
  433. marginLeft: '30rpx',
  434. }
  435. },
  436. {
  437. type: 'view',
  438. css: {
  439. marginTop: '30rpx',
  440. width: '100%',
  441. textAlign: 'center',
  442. },
  443. // #ifdef H5
  444. views: [
  445. {
  446. type: 'qrcode',
  447. text: this.qrcode,
  448. css: {
  449. width: '200rpx',
  450. height: '200rpx',
  451. borderRadius: '16rpx',
  452. }
  453. }
  454. ],
  455. // #endif
  456. // #ifdef MP-WEIXIN
  457. views: [
  458. {
  459. type: 'image',
  460. src: this.qrcode,
  461. css: {
  462. width: '200rpx',
  463. height: '200rpx',
  464. borderRadius: '16rpx',
  465. }
  466. }
  467. ]
  468. // #endif
  469. },
  470. {
  471. type: 'text',
  472. text: '———— ' + '长按识别 | 欢迎使用' + ' ————',
  473. css: {
  474. marginTop: '20rpx',
  475. marginBottom: '20rpx',
  476. width: '100%',
  477. textAlign: 'center',
  478. fontSize: '24rpx',
  479. color: '#fff',
  480. lineHeight: '33rpx'
  481. }
  482. }
  483. ]
  484. }),
  485. (this.showPoster = true);
  486. },
  487. preview(e){
  488. if(this.drawList[e].done == 1&&this.drawList[e].status == 1){
  489. uni.previewImage({
  490. urls: this.drawList[e].imgs_file?this.drawList[e].imgs_file:[this.drawList[e].origin_url],
  491. current:0
  492. });
  493. }
  494. },
  495. gallerydel(e){
  496. var that = this;
  497. uni.showModal({
  498. confirmText: '删除',
  499. content: '是否删除此绘画记录',
  500. title: '提示',
  501. confirmColor: '#26B3A0',
  502. success(res) {
  503. // console.log(res);
  504. if (res.confirm) {
  505. that.$http('gallery.del', {id:that.drawList[e].id}).then(res => {
  506. if (res.code == 0) {
  507. uni.showToast({
  508. title:'删除成功'
  509. })
  510. // that.drawList = []
  511. that.$refs.paging.reload(true);
  512. }else{
  513. uni.showToast({
  514. title:'删除失败',
  515. icon:'none'
  516. })
  517. }
  518. });
  519. }
  520. }
  521. })
  522. }
  523. }
  524. }
  525. </script>
  526. <style lang="scss">
  527. page {
  528. background: #f6f7fb;
  529. }
  530. .draw_view{
  531. margin: 30rpx;
  532. width: 100%;
  533. background: #fff;
  534. border-radius: 20rpx;
  535. // padding: 30rpx;
  536. position: relative;
  537. .draw_image{
  538. position: relative;
  539. image{
  540. width: 100%;
  541. height: 280rpx;
  542. border-radius: 20rpx 20rpx 0 0;
  543. }
  544. }
  545. .sheets{
  546. position: absolute;
  547. z-index: 9;
  548. padding: 4px 12px;
  549. background: #0000007d;
  550. color: #fff;
  551. top: 15px;
  552. left: 15px;
  553. border-radius: 48px;
  554. font-size: 13px;
  555. }
  556. .draw_done{
  557. height: 280rpx;
  558. font-size: 30px;
  559. border-radius: 11px 11px 0 0;
  560. background: #000;
  561. color: #fff;
  562. }
  563. .prompt{
  564. padding: 20rpx 30rpx 30rpx;
  565. }
  566. .create_time{
  567. font-size: 26rpx;
  568. color: #9e9e9e;
  569. padding: 0rpx 30rpx 30rpx;
  570. }
  571. // .onekey {
  572. // background: linear-gradient(to right, #00ca88, #00BCD4);
  573. // color: #fff;
  574. // padding: 15rpx 0;
  575. // text-align: center;
  576. // font-size: 24rpx;
  577. // border-radius: 0 0 22rpx 22rpx;
  578. // }
  579. .operate{
  580. padding: 0px 16px 16px;
  581. }
  582. .onekey {
  583. background: linear-gradient(to right, #00ca88, #00BCD4);
  584. color: #fff;
  585. padding: 15rpx;
  586. // font-weight: bold;
  587. border-radius: 10rpx;
  588. text-align: center;
  589. font-size: 24rpx;
  590. width: 48%;
  591. }
  592. .hoversubmit {
  593. background: #f7f7f7;
  594. color: #acacb3;
  595. }
  596. .circle{
  597. position: absolute;
  598. right: -14rpx;
  599. top: -14rpx;
  600. background: #fff;
  601. border-radius: 50%;
  602. }
  603. .imgs_arrow{
  604. position: absolute;
  605. // top: 300rpx;
  606. width: 92%;
  607. margin: 0 30rpx;
  608. .arrow{
  609. background: #0000007d;
  610. border-radius: 50%;
  611. padding: 10rpx;
  612. }
  613. }
  614. }
  615. .dygbhg {
  616. background: #ffffff;
  617. border-radius: 15rpx 15rpx 0 0;
  618. position: fixed;
  619. bottom: 0;
  620. left: 0;
  621. width: 100%;
  622. box-shadow: 0px 0px 10px #00000024;
  623. display: flex;
  624. align-items: center;
  625. justify-content: space-evenly;
  626. }
  627. .whole{
  628. width: 45%;
  629. height: 88rpx;
  630. display: flex;
  631. color: #ffffff;
  632. align-items: center;
  633. justify-content: center;
  634. background: #f3f3f3;
  635. font-weight: bold;
  636. border-radius: 60rpx;
  637. color: #3d7eff;
  638. }
  639. .distinguish {
  640. width: 45%;
  641. height: 88rpx;
  642. display: flex;
  643. color: #ffffff;
  644. align-items: center;
  645. justify-content: center;
  646. background: #3d7eff;
  647. font-weight: bold;
  648. border-radius: 60rpx;
  649. margin: 38rpx 0;
  650. margin-left: 4%;
  651. }
  652. /* 全屏轮播 start*/
  653. .card-swiper {
  654. height: 100vh !important;
  655. }
  656. .card-swiper swiper-item {
  657. width: 750rpx !important;
  658. left: 0rpx;
  659. box-sizing: border-box;
  660. overflow: initial;
  661. background: #000;
  662. }
  663. .card-swiper swiper-item .swiper-item {
  664. display: flex;
  665. align-items: center;
  666. justify-content: center;
  667. height: 100%;
  668. background: #000;
  669. }
  670. .card-swiper swiper-item.cur .swiper-item {
  671. transform: scale(1);
  672. transition: all 0.2s ease-in 0s;
  673. will-change: transform;
  674. }
  675. </style>