index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. <template>
  2. <view class="container">
  3. <!-- <tn-nav-bar :isBack="false" backgroundColor="#fff" :bottomShadow="false">数字人</tn-nav-bar> -->
  4. <!-- <view class="pos">
  5. </view> -->
  6. <view class="addPd">
  7. <view class="createPro" @click="handleCreatePro">
  8. <view class="centerAdd">
  9. <view class="addIcon">
  10. <image src="/static/add_icon.png" mode=""></image>
  11. <!-- <text class="iconfont icon-chuangjian" style="color: white;"></text> -->
  12. </view>
  13. <view class="addTxt">
  14. 创建项目
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="context">
  20. <view class="" style="padding-left: 30rpx;padding-right: 30rpx;">
  21. <view class="swiperBox" v-if="isLogin">
  22. <view class="draftLabel">
  23. <image src="/static/caogao_icon.png" mode="" class="labelIcon"></image>
  24. 草稿
  25. </view>
  26. <empty v-if="draftList.length==0" tipTxt="暂无草稿" style="margin-top: -50rpx;"></empty>
  27. <view class="swiperCard" v-else>
  28. <view class="itemBox" :style="{backgroundImage:`url(${item.backs.url})`}"
  29. v-for="(item,index) in draftList" @click="toCreateDetail(item)">
  30. <image class="role" :src="item.roles.url" mode=""></image>
  31. <div class="barBox">
  32. <div class="name">
  33. {{item.name}}
  34. </div>
  35. <text @click.stop="delDraft(item,index)" style="color:white;font-size: 28rpx;"
  36. class="iconfont icon-shanchu"></text>
  37. </div>
  38. </view>
  39. </view>
  40. <div class="dotBox" v-if="draftList.length!==0">
  41. <div class="i1"></div>
  42. <div class="i2"></div>
  43. <div class="i3"></div>
  44. <div class="i4"></div>
  45. <div class="i5"></div>
  46. </div>
  47. </view>
  48. </view>
  49. <view class="draft">
  50. <view class="draftLabel" style="padding-left: 30rpx;padding-right: 30rpx;">
  51. <image style="width: 34rpx;height: 34rpx;" src="/static/zuopin_icon.png" mode="" class="labelIcon">
  52. </image>
  53. {{isLogin?'数字人作品':'精选案例'}}
  54. </view>
  55. <view style="padding-left: 15rpx;padding-right: 15rpx;">
  56. <empty v-if="workList.length==0" :tipTxt="isLogin?'暂无作品':'暂无案例'"></empty>
  57. <view class="draftList" v-else>
  58. <view class="itemBox" v-for="(item,index) in workList" @click="goWorkDetail(item)">
  59. <!-- <view class="top" :style="{minHeight:isPc?'184rpx':'184rpx'}"> -->
  60. <view class="top">
  61. <image :src="item.cover" mode="aspectFit" v-if="item.state">
  62. </image>
  63. <view class="tipBox" v-else>
  64. <view class="preloader_1 loadingBox" style="">
  65. <view></view>
  66. <view></view>
  67. <view></view>
  68. <view></view>
  69. <view></view>
  70. </view>
  71. <!-- <view class="progress">
  72. <u-line-progress :percentage="'percentage'+item.id" :showText="true"
  73. activeColor="#9b59b6" height="12"></u-line-progress>
  74. </view> -->
  75. <view class="tip" style="color:#237FED">
  76. 生成中...
  77. </view>
  78. </view>
  79. </view>
  80. <view class="bottom" v-if="isLogin">
  81. <view class="left">
  82. {{item.name}}
  83. </view>
  84. <!-- <view class="left">
  85. {{item.state==1?"已生成":'生成中'}}
  86. </view> -->
  87. <view class="delIcon" @click.stop="handleShowMoreMenu(item,index)">
  88. <!-- <image src="/static/images/head.jpg" mode=""></image> -->
  89. <text class="iconfont icon-gengduo-shuxiang" style="font-size:32rpx;"></text>
  90. </view>
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. <wike-tabbar2 :currTabIndex='3' v-if="appInfo.page_template == 3" :is_aipainting="appInfo.is_aipainting"
  97. :onTabbar="true" :isShowAnimate="true" :appInfos="appInfo.page_template"></wike-tabbar2>
  98. <wike-tabbar :currTabIndex='3' v-else :onTabbar="true" :is_aipainting="appInfo.is_aipainting"
  99. :isShowAnimate="true" :appInfos="appInfo.page_template"></wike-tabbar>
  100. <u-popup :show="show" @close="close" @open="open" mode="center">
  101. <view
  102. style="background: rgba(0, 0, 0, 0);width: 300rpx;height: 300rpx;display: flex;align-items: center;flex-direction: column;justify-content: center;color:#26b3a0;">
  103. <l-circularProgress :isBgShow="true" :lineWidth="10" boxWidth="100" boxHeight="100"
  104. progressColor="##237FED" fontColor="##237FED" gradualColor="##237FED"
  105. :percent="progress"></l-circularProgress>
  106. <view class="">
  107. 视频下载中...
  108. </view>
  109. </view>
  110. </u-popup>
  111. <u-picker ref="picker" defaultIndex='' :closeOnClickOverlay="true" :showIcon="true" :show="showMoreMenu"
  112. :columns="columns" title="更多" confirmColor="" @cancel="showMoreMenu=false" @confirm="handleConfirm"
  113. @close="handleClosePicker"></u-picker>
  114. <!-- <wike-tabbar :onTabbar="true" :isShowAnimate="true"></wike-tabbar> -->
  115. <view class="pos2">
  116. </view>
  117. </view>
  118. </view>
  119. </template>
  120. <script>
  121. import empty from '@/components/empty/empty.vue'
  122. import {
  123. demoList,
  124. workList,
  125. delWork,
  126. draftList
  127. } from '@/api/robot/index.js'
  128. import {
  129. downLoad3
  130. } from '@/utils/download3.js'
  131. import {
  132. mapMutations,
  133. mapActions,
  134. mapState,
  135. mapGetters
  136. } from 'vuex';
  137. export default {
  138. data() {
  139. return {
  140. demoList: [],
  141. show: false,
  142. showMoreMenu: false,
  143. columns: [
  144. ['删除', '下载视频', '复制链接']
  145. ],
  146. draftList: [],
  147. workList: [],
  148. delItem: {},
  149. delIndex: -1,
  150. is_wx: false,
  151. isPc: false,
  152. timer: null,
  153. // percentage: 0,
  154. reqTimes: 0,
  155. progress: 0,
  156. isDowload: false
  157. };
  158. },
  159. computed: {
  160. ...mapGetters(['appInfo', 'userInfo', 'userData', 'isLogin']),
  161. isLogin() {
  162. if (uni.getStorageSync('token')) {
  163. return true
  164. } else {
  165. return false
  166. }
  167. }
  168. },
  169. onReady() {
  170. },
  171. onUnload() {
  172. },
  173. onLoad(o) {
  174. // console.log('digitalMen.workList----onLoad(o)------------');
  175. // this.$http('digitalMen.workList', {}).then(res => {
  176. // if (res.code == 0) {
  177. // console.log('测试数字人接口是否通畅------------------2');
  178. // }
  179. // });
  180. },
  181. beforeDestroy() {
  182. console.log('beforeDestroy()---------------------');
  183. clearInterval(this.timer)
  184. },
  185. onHide() {
  186. console.log('onHide()---------------------');
  187. // 清除定时器
  188. clearInterval(this.timer)
  189. },
  190. onShow() {
  191. if (this.timer) {
  192. this.timer = null
  193. }
  194. // console.log('当前时间戳:', Date.now() + 180000);
  195. let _this = this
  196. // if (getApp().from == 'create') {
  197. // }
  198. this.getWorkList()
  199. this.getIndexData()
  200. const userAgent = navigator.userAgent.toLowerCase();
  201. if (/ipad|iphone|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/.test(userAgent)) {
  202. // 移动端
  203. console.log('移动端')
  204. this.isPc = false
  205. } else {
  206. // pc端
  207. this.isPc = true
  208. console.log('PC端')
  209. }
  210. // console.log('1213', download);
  211. this.is_wx = this.is_weixin()
  212. console.log('this.is_wx', this.is_wx);
  213. },
  214. onShareAppMessage: function(res) {
  215. },
  216. // async onPullDownRefresh() {
  217. // this.getIndexData()
  218. // },
  219. methods: {
  220. open() {
  221. // console.log('open');
  222. },
  223. close() {
  224. this.show = false
  225. // console.log('close');
  226. },
  227. handleClosePicker() {
  228. this.showMoreMenu = false
  229. // this.columns = [
  230. // ['删除', '下载视频', '复制链接']
  231. // ]
  232. },
  233. toCreateDetail(item) {
  234. getApp().draftDetail = item
  235. uni.navigateTo({
  236. url: '/pages/digitalMen/generate/index'
  237. })
  238. },
  239. delDraft(item, index) {
  240. let _this = this
  241. uni.showModal({
  242. title: '提示',
  243. confirmColor: '#207CF7',
  244. content: '是否确认删除:' + item.name + '?',
  245. success: async (res1) => {
  246. if (res1.confirm) {
  247. // let res = await delWork({
  248. // id: item.id
  249. // })
  250. let res = await this.$http('digitalMen.delWork', {
  251. id: item.id
  252. })
  253. if (res.code == 0) {
  254. _this.draftList.splice(index, 1)
  255. console.log('删除数字人草稿返回值:', res);
  256. uni.showToast({
  257. title: '数字人:' + item.name + '草稿删除成功!',
  258. icon: 'success'
  259. })
  260. } else {
  261. uni.showToast({
  262. title: res.msg,
  263. icon: 'none'
  264. })
  265. }
  266. } else if (res1.cancel) {
  267. }
  268. }
  269. });
  270. },
  271. downLoad(url) {
  272. uni.downloadFile({
  273. url: url,
  274. header: {
  275. // 'Authorization':this.$utils.localData.getToken(),
  276. },
  277. success: (res) => {
  278. if (res.statusCode === 200) {
  279. console.log('res.tempFilePath', res.tempFilePath);
  280. return
  281. //res.tempFilePath; //此参数为本地的缓存地址
  282. var link = document.createElement('a');
  283. link.href = url; //url 为获取的本地缓存地址或者直接是url地址
  284. link.download = name + '.file'; //name为自定义的文件名称 .file为文件后缀名
  285. document.body.appendChild(link)
  286. link.click()
  287. //移除
  288. setTimeout(() => document.body.removeChild(link), 1000)
  289. }
  290. },
  291. fail: (e) => {
  292. uni.showToast({
  293. title: '数据处理错误,请刷新重试',
  294. icon: 'none',
  295. duration: 2000
  296. });
  297. }
  298. })
  299. },
  300. downLoad2(url) {
  301. var link = document.createElement('a');
  302. link.href = url; //url 为获取的本地缓存地址或者直接是url地址
  303. link.download = '数字人视频' + '.mp4'; //name为自定义的文件名称 .file为文件后缀名
  304. document.body.appendChild(link)
  305. link.click()
  306. //移除
  307. setTimeout(() => document.body.removeChild(link), 1000)
  308. },
  309. // 判断是否是微信浏览器
  310. is_weixin() {
  311. var ua = window.navigator.userAgent.toLowerCase();
  312. if (ua.match(/MicroMessenger/i) == 'micromessenger') {
  313. console.log('微信浏览器');
  314. return true;
  315. } else {
  316. console.log("不是微信浏览器");
  317. return false;
  318. }
  319. },
  320. async getWorkList() {
  321. let _this = this
  322. let res = await this.$http('digitalMen.workList', {})
  323. if (res.code == 0) {
  324. // uni.stopPullDownRefresh()
  325. this.workList = res.data
  326. let allSuc = res.data.every((item, index) => {
  327. return item.state == 1
  328. })
  329. if (allSuc || res.data.length == 0) {
  330. clearInterval(_this.timer)
  331. return
  332. }
  333. console.log('onshow------------------_this.timer', _this.timer);
  334. if (_this.timer) {
  335. return
  336. }
  337. _this.timer = setInterval(() => {
  338. _this.getWorkList()
  339. }, 5000)
  340. console.log('数字人作品列表返回值:', res);
  341. } else {
  342. uni.showToast({
  343. title: res.msg,
  344. icon: 'none'
  345. })
  346. }
  347. },
  348. async getIndexData() {
  349. if (!uni.getStorageSync('token')) {
  350. return
  351. }
  352. let res1 = await this.$http('digitalMen.draftList', {})
  353. if (res1.code == 0) {
  354. // uni.stopPullDownRefresh()
  355. this.draftList = res1.data
  356. console.log('数字人草稿列表返回值:', res1);
  357. } else {
  358. uni.showToast({
  359. title: res1.msg,
  360. icon: 'none'
  361. })
  362. }
  363. if (res1.code == 0 && res.code == 0) {
  364. uni.stopPullDownRefresh()
  365. }
  366. },
  367. goWorkDetail(item) {
  368. if (item.state == 0) {
  369. uni.showToast({
  370. title: '数字人正在生成中,请稍后查看',
  371. icon: 'none'
  372. })
  373. return
  374. }
  375. getApp().url = item.url
  376. uni.navigateTo({
  377. url: '/pages/digitalMen/workDetail/index'
  378. })
  379. },
  380. handleCreatePro() {
  381. if (!uni.getStorageSync('token')) {
  382. uni.showToast({
  383. title: '请登录后创建项目',
  384. icon: 'none'
  385. })
  386. setTimeout(() => {
  387. uni.navigateTo({
  388. url: '/pages/user/signin'
  389. })
  390. }, 1500)
  391. return
  392. } else {
  393. uni.navigateTo({
  394. url: '/pages/digitalMen/generate/index?type=create'
  395. })
  396. }
  397. },
  398. handleShowMoreMenu(item, index) {
  399. this.$refs.picker.setIndexs([0])
  400. this.delIndex = index
  401. this.delItem = item
  402. this.showMoreMenu = true
  403. },
  404. async handleConfirm(e) {
  405. let _this = this
  406. this.showMoreMenu = false
  407. if (e.value[0] == '删除') {
  408. // if (this.delItem.state == 0) {
  409. // uni.showToast({
  410. // title: '数字人正在生成中,请稍后操作',
  411. // icon: 'none'
  412. // })
  413. // return
  414. // }
  415. uni.showModal({
  416. title: '提示',
  417. confirmColor: '#207CF7',
  418. content: '是否确认删除:' + _this.delItem.name + '?',
  419. success: async (res1) => {
  420. if (res1.confirm) {
  421. // let res = await delWork({
  422. // id: _this.delItem.id
  423. // })
  424. let res = await _this.$http('digitalMen.delWork', {
  425. id: _this.delItem.id
  426. })
  427. if (res.code == 0) {
  428. _this.workList.splice(this.delIndex, 1)
  429. if (_this.workList.length == 0) {
  430. clearInterval(_this.timer)
  431. }
  432. console.log('删除数字人返回值:', res);
  433. uni.showToast({
  434. title: '数字人:' + _this.delItem.name + '删除成功!',
  435. icon: 'success'
  436. })
  437. } else {
  438. uni.showToast({
  439. title: res.msg,
  440. icon: 'none'
  441. })
  442. }
  443. } else if (res1.cancel) {
  444. }
  445. }
  446. });
  447. } else if (e.value[0] == '复制链接') {
  448. if (this.delItem.state == 0) {
  449. uni.showToast({
  450. title: '数字人正在生成中,请稍后复制链接',
  451. icon: 'none'
  452. })
  453. return
  454. }
  455. uni.setClipboardData({
  456. data: this.delItem.url,
  457. success: function() {
  458. uni.showToast({
  459. title: '链接复制成功!',
  460. duration: 1500
  461. });
  462. }
  463. });
  464. } else if (e.value[0] == '下载视频') {
  465. if (this.delItem.state == 0) {
  466. uni.showToast({
  467. title: '数字人正在生成中,请稍后下载视频',
  468. icon: 'none'
  469. })
  470. return
  471. }
  472. const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i
  473. .test(
  474. navigator.userAgent) ? false : true;
  475. if (this.is_wx) {
  476. // 微信内置浏览器
  477. // this.downLoad2(this.delItem.url)
  478. let _that = this
  479. uni.showModal({
  480. title: '温馨提示',
  481. content: '微信内置浏览器不支持视频文件下载,请复制视频链接至手机浏览器打开',
  482. confirmText: '复制',
  483. confirmColor: '#207CF7',
  484. success: function(res) {
  485. if (res.confirm) {
  486. uni.setClipboardData({
  487. data: _that.delItem.url,
  488. success: function() {
  489. uni.showToast({
  490. title: "复制成功",
  491. icon: 'success',
  492. })
  493. }
  494. });
  495. } else if (res.cancel) {}
  496. }
  497. })
  498. return
  499. } else {
  500. if (detectDeviceType()) {
  501. let _this = this
  502. if (_this.isDowload) {
  503. uni.showToast({
  504. icon: 'none',
  505. title: '请等待上一个视频下载完成后,再下载',
  506. });
  507. }
  508. // PC端
  509. // this.delItem.url = 'http://www.liwantao.top/test.mp4'
  510. const downloadTask = uni.downloadFile({
  511. url: _this.delItem.url, //文件链接
  512. timeout: 99999999,
  513. success: (res) => {
  514. if (res.statusCode === 200) {
  515. var oA = document.createElement("a");
  516. oA.download = _this.delItem.name; // 设置下载的文件名,默认是'下载'
  517. oA.href = res.tempFilePath; //临时路径再保存到本地
  518. document.body.appendChild(oA);
  519. oA.click();
  520. oA.remove(); // 下载之后把创建的元素删除
  521. }
  522. },
  523. fail: (err) => {
  524. _this.show = false;
  525. _this.isDowload = false
  526. _this.progress = 0
  527. // console.log(_this.show, _this.isDowload, _this.progress, err);
  528. uni.showToast({
  529. icon: 'none',
  530. mask: true,
  531. title: '失败请重新下载',
  532. });
  533. },
  534. })
  535. downloadTask.onProgressUpdate((res) => {
  536. if (res.progress > 0) {
  537. _this.show = true;
  538. _this.isDowload = true
  539. }
  540. _this.progress = res.progress;
  541. if (res.progress == 100) {
  542. _this.show = false;
  543. _this.isDowload = false
  544. _this.progress = 0
  545. uni.showToast({
  546. icon: 'success',
  547. title: _this.delItem.name + ',下载成功!',
  548. });
  549. }
  550. })
  551. } else {
  552. // 其他移动端浏览器
  553. // window.open(this.delItem.url)
  554. let _this = this
  555. // this.delItem.url = 'http://www.liwantao.top/test.mp4'
  556. var oA = document.createElement("a");
  557. oA.download = _this.delItem.name;
  558. oA.href = _this.delItem.url;
  559. document.body.appendChild(oA);
  560. oA.click();
  561. oA.remove();
  562. }
  563. }
  564. }
  565. }
  566. }
  567. };
  568. </script>
  569. <style lang="scss" scoped>
  570. @import './index.scss';
  571. </style>