index.vue 15 KB

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