index.vue 14 KB

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