index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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 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. 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.$refs.picker.setIndexs([0])
  353. this.delIndex = index
  354. this.delItem = item
  355. this.showMoreMenu = true
  356. },
  357. async handleConfirm(e) {
  358. let _this = this
  359. this.showMoreMenu = false
  360. if (e.value[0] == '删除') {
  361. // if (this.delItem.state == 0) {
  362. // uni.showToast({
  363. // title: '数字人正在生成中,请稍后操作',
  364. // icon: 'none'
  365. // })
  366. // return
  367. // }
  368. uni.showModal({
  369. title: '提示',
  370. confirmColor: '#26b3a0',
  371. content: '是否确认删除:' + _this.delItem.name + '?',
  372. success: async (res1) => {
  373. if (res1.confirm) {
  374. let res = await delWork({
  375. id: _this.delItem.id
  376. })
  377. if (res.code == 0) {
  378. _this.workList.splice(this.delIndex, 1)
  379. console.log('删除数字人返回值:', res);
  380. uni.showToast({
  381. title: '数字人:' + _this.delItem.name + '删除成功!',
  382. icon: 'success'
  383. })
  384. } else {
  385. uni.showToast({
  386. title: res.msg,
  387. icon: 'none'
  388. })
  389. }
  390. } else if (res1.cancel) {
  391. }
  392. }
  393. });
  394. } else if (e.value[0] == '复制链接') {
  395. if (this.delItem.state == 0) {
  396. uni.showToast({
  397. title: '数字人正在生成中,请稍后复制链接',
  398. icon: 'none'
  399. })
  400. return
  401. }
  402. uni.setClipboardData({
  403. data: this.delItem.url,
  404. success: function() {
  405. uni.showToast({
  406. title: '链接复制成功!',
  407. duration: 1500
  408. });
  409. }
  410. });
  411. } else if (e.value[0] == '下载视频') {
  412. if (this.delItem.state == 0) {
  413. uni.showToast({
  414. title: '数字人正在生成中,请稍后下载视频',
  415. icon: 'none'
  416. })
  417. return
  418. }
  419. const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i
  420. .test(
  421. navigator.userAgent) ? false : true;
  422. if (this.is_wx) {
  423. // 微信内置浏览器
  424. // this.downLoad2(this.delItem.url)
  425. let _that = this
  426. uni.showModal({
  427. title: '温馨提示',
  428. content: '微信内置浏览器不支持视频文件下载,请复制视频链接至手机浏览器打开',
  429. confirmText: '复制',
  430. confirmColor: '#26B3A0',
  431. success: function(res) {
  432. if (res.confirm) {
  433. uni.setClipboardData({
  434. data: _that.delItem.url,
  435. success: function() {
  436. uni.showToast({
  437. title: "复制成功",
  438. icon: 'success',
  439. })
  440. }
  441. });
  442. } else if (res.cancel) {}
  443. }
  444. })
  445. return
  446. } else {
  447. if (detectDeviceType()) {
  448. let _this = this
  449. if (_this.isDowload) {
  450. uni.showToast({
  451. icon: 'none',
  452. title: '请等待上一个视频下载完成后,再下载',
  453. });
  454. }
  455. // PC端
  456. // this.delItem.url = 'http://www.liwantao.top/test.mp4'
  457. const downloadTask = uni.downloadFile({
  458. url: _this.delItem.url, //文件链接
  459. timeout: 99999999,
  460. success: (res) => {
  461. if (res.statusCode === 200) {
  462. var oA = document.createElement("a");
  463. oA.download = _this.delItem.name; // 设置下载的文件名,默认是'下载'
  464. oA.href = res.tempFilePath; //临时路径再保存到本地
  465. document.body.appendChild(oA);
  466. oA.click();
  467. oA.remove(); // 下载之后把创建的元素删除
  468. }
  469. },
  470. fail: (err) => {
  471. _this.show = false;
  472. _this.isDowload = false
  473. _this.progress = 0
  474. // console.log(_this.show, _this.isDowload, _this.progress, err);
  475. uni.showToast({
  476. icon: 'none',
  477. mask: true,
  478. title: '失败请重新下载',
  479. });
  480. },
  481. })
  482. downloadTask.onProgressUpdate((res) => {
  483. if (res.progress > 0) {
  484. _this.show = true;
  485. _this.isDowload = true
  486. }
  487. _this.progress = res.progress;
  488. if (res.progress == 100) {
  489. _this.show = false;
  490. _this.isDowload = false
  491. _this.progress = 0
  492. uni.showToast({
  493. icon: 'success',
  494. title: _this.delItem.name + ',下载成功!',
  495. });
  496. }
  497. })
  498. } else {
  499. // 其他移动端浏览器
  500. // window.open(this.delItem.url)
  501. let _this = this
  502. // this.delItem.url = 'http://www.liwantao.top/test.mp4'
  503. var oA = document.createElement("a");
  504. oA.download = _this.delItem.name;
  505. oA.href = _this.delItem.url;
  506. document.body.appendChild(oA);
  507. oA.click();
  508. oA.remove();
  509. }
  510. }
  511. }
  512. }
  513. }
  514. };
  515. </script>
  516. <style lang="scss" scoped>
  517. @import './index.scss';
  518. </style>