index.vue 15 KB

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