index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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. async delDraft(item, index) {
  220. let res = await delWork({
  221. id: item.id
  222. })
  223. if (res.code == 0) {
  224. this.draftList.splice(index, 1)
  225. console.log('删除数字人草稿返回值:', res);
  226. uni.showToast({
  227. title: '数字人:' + item.name + '草稿删除成功!',
  228. icon: 'success'
  229. })
  230. } else {
  231. uni.showToast({
  232. title: res.msg,
  233. icon: 'none'
  234. })
  235. }
  236. },
  237. downLoad(url) {
  238. uni.downloadFile({
  239. url: url,
  240. header: {
  241. // 'Authorization':this.$utils.localData.getToken(),
  242. },
  243. success: (res) => {
  244. if (res.statusCode === 200) {
  245. console.log('res.tempFilePath', res.tempFilePath);
  246. return
  247. //res.tempFilePath; //此参数为本地的缓存地址
  248. var link = document.createElement('a');
  249. link.href = url; //url 为获取的本地缓存地址或者直接是url地址
  250. link.download = name + '.file'; //name为自定义的文件名称 .file为文件后缀名
  251. document.body.appendChild(link)
  252. link.click()
  253. //移除
  254. setTimeout(() => document.body.removeChild(link), 1000)
  255. }
  256. },
  257. fail: (e) => {
  258. uni.showToast({
  259. title: '数据处理错误,请刷新重试',
  260. icon: 'none',
  261. duration: 2000
  262. });
  263. }
  264. })
  265. },
  266. downLoad2(url) {
  267. var link = document.createElement('a');
  268. link.href = url; //url 为获取的本地缓存地址或者直接是url地址
  269. link.download = '数字人视频' + '.mp4'; //name为自定义的文件名称 .file为文件后缀名
  270. document.body.appendChild(link)
  271. link.click()
  272. //移除
  273. setTimeout(() => document.body.removeChild(link), 1000)
  274. },
  275. // 判断是否是微信浏览器
  276. is_weixin() {
  277. var ua = window.navigator.userAgent.toLowerCase();
  278. if (ua.match(/MicroMessenger/i) == 'micromessenger') {
  279. console.log('微信浏览器');
  280. return true;
  281. } else {
  282. console.log("不是微信浏览器");
  283. return false;
  284. }
  285. },
  286. async getIndexData() {
  287. let res = await workList({})
  288. if (res.code == 0) {
  289. // uni.stopPullDownRefresh()
  290. this.workList = res.data
  291. // let parm = {}
  292. // res.data.forEach((item, index) => {
  293. // parm['percentage' + item.id] = 0
  294. // })
  295. // this.$data = Object.assign(this.$data, parm);
  296. // console.log('百分比批量赋值后:', this.$data);
  297. console.log('数字人作品列表返回值:', res);
  298. } else {
  299. uni.showToast({
  300. title: res.msg,
  301. icon: 'none'
  302. })
  303. }
  304. let res1 = await draftList({})
  305. if (res1.code == 0) {
  306. // uni.stopPullDownRefresh()
  307. this.draftList = res1.data
  308. console.log('数字人草稿列表返回值:', res1);
  309. } else {
  310. uni.showToast({
  311. title: res1.msg,
  312. icon: 'none'
  313. })
  314. }
  315. if (res1.code == 0 && res.code == 0) {
  316. uni.stopPullDownRefresh()
  317. }
  318. },
  319. goWorkDetail(item) {
  320. if (item.state == 0) {
  321. uni.showToast({
  322. title: '数字人正在生成中,请稍后查看',
  323. icon: 'none'
  324. })
  325. return
  326. }
  327. getApp().url = item.url
  328. uni.navigateTo({
  329. url: '/pages/robot/workDetail/index'
  330. })
  331. },
  332. handleCreatePro() {
  333. uni.navigateTo({
  334. url: '/pages/robot/generate/index?type=create'
  335. })
  336. },
  337. handleShowMoreMenu(item, index) {
  338. this.delIndex = index
  339. this.delItem = item
  340. this.showMoreMenu = true
  341. },
  342. async handleConfirm(e) {
  343. let _this = this
  344. this.showMoreMenu = false
  345. if (e.value[0] == '删除') {
  346. uni.showModal({
  347. title: '提示',
  348. confirmColor: '#26b3a0',
  349. content: '是否确认删除:' + _this.delItem.name + '?',
  350. success: async (res1) => {
  351. if (res1.confirm) {
  352. let res = await delWork({
  353. id: _this.delItem.id
  354. })
  355. if (res.code == 0) {
  356. _this.workList.splice(this.delIndex, 1)
  357. console.log('删除数字人返回值:', res);
  358. uni.showToast({
  359. title: '数字人:' + _this.delItem.name + '删除成功!',
  360. icon: 'success'
  361. })
  362. } else {
  363. uni.showToast({
  364. title: res.msg,
  365. icon: 'none'
  366. })
  367. }
  368. } else if (res1.cancel) {
  369. }
  370. }
  371. });
  372. } else if (e.value[0] == '复制链接') {
  373. if (this.delItem.state == 0) {
  374. uni.showToast({
  375. title: '数字人正在生成中,请稍后复制链接',
  376. icon: 'none'
  377. })
  378. return
  379. }
  380. uni.setClipboardData({
  381. data: this.delItem.url,
  382. success: function() {
  383. uni.showToast({
  384. title: '链接复制成功!',
  385. duration: 1500
  386. });
  387. }
  388. });
  389. } else if (e.value[0] == '下载视频') {
  390. if (this.delItem.state == 0) {
  391. uni.showToast({
  392. title: '数字人正在生成中,请稍后下载视频',
  393. icon: 'none'
  394. })
  395. return
  396. }
  397. const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i
  398. .test(
  399. navigator.userAgent) ? false : true;
  400. if (this.is_wx) {
  401. // 微信内置浏览器
  402. // this.downLoad2(this.delItem.url)
  403. let _that = this
  404. uni.showModal({
  405. title: '温馨提示',
  406. content: '微信内置浏览器不支持视频文件下载,请复制视频链接至手机浏览器打开',
  407. confirmText: '复制',
  408. confirmColor: '#26B3A0',
  409. success: function(res) {
  410. if (res.confirm) {
  411. uni.setClipboardData({
  412. data: _that.delItem.url,
  413. success: function() {
  414. uni.showToast({
  415. title: "复制成功",
  416. icon: 'success',
  417. })
  418. }
  419. });
  420. } else if (res.cancel) {}
  421. }
  422. })
  423. return
  424. } else {
  425. if (detectDeviceType()) {
  426. let _this = this
  427. if (_this.isDowload) {
  428. uni.showToast({
  429. icon: 'none',
  430. title: '请等待上一个视频下载完成后,再下载',
  431. });
  432. }
  433. // PC端
  434. // this.delItem.url = 'http://www.liwantao.top/test.mp4'
  435. const downloadTask = uni.downloadFile({
  436. url: _this.delItem.url, //文件链接
  437. timeout: 99999999,
  438. success: (res) => {
  439. if (res.statusCode === 200) {
  440. var oA = document.createElement("a");
  441. oA.download = _this.delItem.name; // 设置下载的文件名,默认是'下载'
  442. oA.href = res.tempFilePath; //临时路径再保存到本地
  443. document.body.appendChild(oA);
  444. oA.click();
  445. oA.remove(); // 下载之后把创建的元素删除
  446. }
  447. },
  448. fail: (err) => {
  449. _this.show = false;
  450. _this.isDowload = false
  451. _this.progress = 0
  452. // console.log(_this.show, _this.isDowload, _this.progress, err);
  453. uni.showToast({
  454. icon: 'none',
  455. mask: true,
  456. title: '失败请重新下载',
  457. });
  458. },
  459. })
  460. downloadTask.onProgressUpdate((res) => {
  461. if (res.progress > 0) {
  462. _this.show = true;
  463. _this.isDowload = true
  464. }
  465. _this.progress = res.progress;
  466. if (res.progress == 100) {
  467. _this.show = false;
  468. _this.isDowload = false
  469. _this.progress = 0
  470. uni.showToast({
  471. icon: 'success',
  472. title: _this.delItem.name + ',下载成功!',
  473. });
  474. }
  475. })
  476. } else {
  477. // 其他移动端浏览器
  478. // window.open(this.delItem.url)
  479. let _this = this
  480. // this.delItem.url = 'http://www.liwantao.top/test.mp4'
  481. var oA = document.createElement("a");
  482. oA.download = _this.delItem.name;
  483. oA.href = _this.delItem.url;
  484. document.body.appendChild(oA);
  485. oA.click();
  486. oA.remove();
  487. }
  488. }
  489. }
  490. }
  491. }
  492. };
  493. </script>
  494. <style lang="scss" scoped>
  495. @import './index.scss';
  496. </style>