index.vue 15 KB

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