index.vue 15 KB

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