index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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">
  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="font-size: 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="{left:isPc?'':'40%'}">
  51. <view></view>
  52. <view></view>
  53. <view></view>
  54. <view></view>
  55. <view></view>
  56. </view> -->
  57. <view class="preloader_1" style="">
  58. <view></view>
  59. <view></view>
  60. <view></view>
  61. <view></view>
  62. <view></view>
  63. </view>
  64. <!-- <view class="progress">
  65. <u-line-progress :percentage="'percentage'+item.id" :showText="true"
  66. activeColor="#9b59b6" height="12"></u-line-progress>
  67. </view> -->
  68. <view class="tip" style="color:#26b3a0">
  69. 生成中...
  70. </view>
  71. </view>
  72. </view>
  73. <view class="bottom">
  74. <view class="left">
  75. {{item.name}}
  76. </view>
  77. <!-- <view class="left">
  78. {{item.state==1?"已生成":'生成中'}}
  79. </view> -->
  80. <view class="delIcon" @click.stop="handleShowMoreMenu(item,index)">
  81. <!-- <image src="/static/images/head.jpg" mode=""></image> -->
  82. <text class="iconfont icon-gengduo-shuxiang" style="font-size: 32rpx;"></text>
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. </view>
  88. <!-- <button @click="test">{{percentage216}}</button> -->
  89. <u-picker :defaultIndex='[0]' :closeOnClickOverlay="true" :showIcon="true" :show="showMoreMenu"
  90. :columns="columns" title="更多" confirmColor="" @cancel="showMoreMenu=false" @confirm="handleConfirm"
  91. @close="handleClosePicker"></u-picker>
  92. <wike-tabbar :onTabbar="true" :isShowAnimate="true"></wike-tabbar>
  93. </view>
  94. </view>
  95. </template>
  96. <script>
  97. import {
  98. workList,
  99. delWork,
  100. draftList
  101. } from '@/api/robot/index.js'
  102. import {
  103. downLoad3
  104. } from '@/utils/download3.js'
  105. export default {
  106. data() {
  107. return {
  108. showMoreMenu: false,
  109. columns: [
  110. ['删除', '下载视频', '复制链接']
  111. ],
  112. draftList: [],
  113. workList: [],
  114. delItem: {},
  115. delIndex: -1,
  116. is_wx: false,
  117. isPc: false,
  118. timer: null,
  119. // percentage: 0,
  120. reqTimes: 0
  121. };
  122. },
  123. computed: {
  124. },
  125. onReady() {
  126. },
  127. onUnload() {
  128. },
  129. onLoad(o) {
  130. },
  131. onShow() {
  132. let _this = this
  133. if (getApp().from == 'create') {
  134. _this.timer = setInterval(async () => {
  135. let res = await workList({})
  136. if (res.code == 0) {
  137. // _this.reqTimes += 1
  138. _this.workList = res.data
  139. // res.data.forEach((item, index) => {
  140. // console.log('每一个percentage', _this['percentage' + item.id]);
  141. // if (_this.reqTimes <= 5) {
  142. // _this['percentage' + item.id] += 10
  143. // } else {
  144. // _this['percentage' + item.id] += 1
  145. // }
  146. // if (item.state == 1) {
  147. // console.log('已完成的那一项', item);
  148. // _this['percentage' + item.id] = 100
  149. // }
  150. // })
  151. let allSuc = res.data.every((item, index) => {
  152. return item.state == 1
  153. })
  154. if (allSuc) {
  155. clearInterval(_this.timer)
  156. // _this.percentage = 100
  157. return
  158. }
  159. console.log('定时器--数字人作品列表返回值:', res);
  160. } else {
  161. uni.showToast({
  162. title: res.msg,
  163. icon: 'none'
  164. })
  165. }
  166. }, 10000)
  167. }
  168. getApp().from = ''
  169. const userAgent = navigator.userAgent.toLowerCase();
  170. if (/ipad|iphone|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/.test(userAgent)) {
  171. // 移动端
  172. console.log('移动端')
  173. this.isPc = false
  174. } else {
  175. // pc端
  176. this.isPc = true
  177. console.log('PC端')
  178. }
  179. // console.log('1213', download);
  180. this.getIndexData()
  181. this.is_wx = this.is_weixin()
  182. console.log('this.is_wx', this.is_wx);
  183. },
  184. onShareAppMessage: function(res) {
  185. },
  186. async onPullDownRefresh() {
  187. this.getIndexData()
  188. },
  189. methods: {
  190. handleClosePicker() {
  191. this.showMoreMenu = false
  192. // this.columns = [
  193. // ['删除', '下载视频', '复制链接']
  194. // ]
  195. },
  196. toCreateDetail(item) {
  197. getApp().draftDetail = item
  198. uni.navigateTo({
  199. url: '/pages/robot/generate/index'
  200. })
  201. },
  202. async delDraft(item, index) {
  203. let res = await delWork({
  204. id: item.id
  205. })
  206. if (res.code == 0) {
  207. this.draftList.splice(index, 1)
  208. console.log('删除数字人草稿返回值:', res);
  209. uni.showToast({
  210. title: '数字人:' + item.name + '草稿删除成功!',
  211. icon: 'success'
  212. })
  213. } else {
  214. uni.showToast({
  215. title: res.msg,
  216. icon: 'none'
  217. })
  218. }
  219. },
  220. downLoad(url) {
  221. uni.downloadFile({
  222. url: url,
  223. header: {
  224. // 'Authorization':this.$utils.localData.getToken(),
  225. },
  226. success: (res) => {
  227. if (res.statusCode === 200) {
  228. console.log('res.tempFilePath', res.tempFilePath);
  229. return
  230. //res.tempFilePath; //此参数为本地的缓存地址
  231. var link = document.createElement('a');
  232. link.href = url; //url 为获取的本地缓存地址或者直接是url地址
  233. link.download = name + '.file'; //name为自定义的文件名称 .file为文件后缀名
  234. document.body.appendChild(link)
  235. link.click()
  236. //移除
  237. setTimeout(() => document.body.removeChild(link), 1000)
  238. }
  239. },
  240. fail: (e) => {
  241. uni.showToast({
  242. title: '数据处理错误,请刷新重试',
  243. icon: 'none',
  244. duration: 2000
  245. });
  246. }
  247. })
  248. },
  249. downLoad2(url) {
  250. var link = document.createElement('a');
  251. link.href = url; //url 为获取的本地缓存地址或者直接是url地址
  252. link.download = '数字人视频' + '.mp4'; //name为自定义的文件名称 .file为文件后缀名
  253. document.body.appendChild(link)
  254. link.click()
  255. //移除
  256. setTimeout(() => document.body.removeChild(link), 1000)
  257. },
  258. // 判断是否是微信浏览器
  259. is_weixin() {
  260. var ua = window.navigator.userAgent.toLowerCase();
  261. if (ua.match(/MicroMessenger/i) == 'micromessenger') {
  262. console.log('微信浏览器');
  263. return true;
  264. } else {
  265. console.log("不是微信浏览器");
  266. return false;
  267. }
  268. },
  269. async getIndexData() {
  270. let res = await workList({})
  271. if (res.code == 0) {
  272. uni.stopPullDownRefresh()
  273. this.workList = res.data
  274. // let parm = {}
  275. // res.data.forEach((item, index) => {
  276. // parm['percentage' + item.id] = 0
  277. // })
  278. // this.$data = Object.assign(this.$data, parm);
  279. // console.log('百分比批量赋值后:', this.$data);
  280. console.log('数字人作品列表返回值:', res);
  281. } else {
  282. uni.showToast({
  283. title: res.msg,
  284. icon: 'none'
  285. })
  286. }
  287. let res1 = await draftList({})
  288. if (res1.code == 0) {
  289. uni.stopPullDownRefresh()
  290. this.draftList = res1.data
  291. console.log('数字人草稿列表返回值:', res1);
  292. } else {
  293. uni.showToast({
  294. title: res1.msg,
  295. icon: 'none'
  296. })
  297. }
  298. },
  299. goWorkDetail(item) {
  300. if (item.state == 0) {
  301. uni.showToast({
  302. title: '数字人正在生成中,请稍后查看',
  303. icon: 'none'
  304. })
  305. return
  306. }
  307. getApp().url = item.url
  308. uni.navigateTo({
  309. url: '/pages/robot/workDetail/index'
  310. })
  311. },
  312. handleCreatePro() {
  313. uni.navigateTo({
  314. url: '/pages/robot/generate/index?type=create'
  315. })
  316. },
  317. handleShowMoreMenu(item, index) {
  318. this.delIndex = index
  319. this.delItem = item
  320. this.showMoreMenu = true
  321. },
  322. async handleConfirm(e) {
  323. this.showMoreMenu = false
  324. if (e.value[0] == '删除') {
  325. let res = await delWork({
  326. id: this.delItem.id
  327. })
  328. if (res.code == 0) {
  329. this.workList.splice(this.delIndex, 1)
  330. console.log('删除数字人返回值:', res);
  331. uni.showToast({
  332. title: '数字人:' + this.delItem.name + '删除成功!',
  333. icon: 'success'
  334. })
  335. } else {
  336. uni.showToast({
  337. title: res.msg,
  338. icon: 'none'
  339. })
  340. }
  341. } else if (e.value[0] == '复制链接') {
  342. uni.setClipboardData({
  343. data: this.delItem.url,
  344. success: function() {
  345. uni.showToast({
  346. title: '链接复制成功!',
  347. duration: 1500
  348. });
  349. }
  350. });
  351. } else if (e.value[0] == '下载视频') {
  352. const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i
  353. .test(
  354. navigator.userAgent) ? false : true;
  355. if (this.is_wx) {
  356. // 微信内置浏览器
  357. // this.downLoad2(this.delItem.url)
  358. let _that = this
  359. uni.showModal({
  360. title: '温馨提示',
  361. content: '微信内置浏览器不支持视频文件下载,请复制视频链接至手机浏览器打开',
  362. confirmText: '复制',
  363. confirmColor: '#26B3A0',
  364. success: function(res) {
  365. if (res.confirm) {
  366. uni.setClipboardData({
  367. data: _that.delItem.url,
  368. success: function() {
  369. uni.showToast({
  370. title: "复制成功",
  371. icon: 'success',
  372. })
  373. }
  374. });
  375. } else if (res.cancel) {}
  376. }
  377. })
  378. return
  379. } else {
  380. if (detectDeviceType()) {
  381. let _this = this
  382. // PC端
  383. this.delItem.url = 'http://www.liwantao.top/test.mp4'
  384. // downLoad3(this.delItem.url, '数字人' + this.delItem.name + '视频', 'video/mp4')
  385. const downloadTask = uni.downloadFile({
  386. url: _this.delItem.url, //文件链接
  387. success: (res) => {
  388. if (res.statusCode === 200) {
  389. var oA = document.createElement("a");
  390. oA.download = _this.delItem.name; // 设置下载的文件名,默认是'下载'
  391. oA.href = res.tempFilePath; //临时路径再保存到本地
  392. document.body.appendChild(oA);
  393. oA.click();
  394. oA.remove(); // 下载之后把创建的元素删除
  395. }
  396. },
  397. fail: (err) => {
  398. uni.showToast({
  399. icon: 'none',
  400. mask: true,
  401. title: '失败请重新下载',
  402. });
  403. },
  404. })
  405. downloadTask.onProgressUpdate((res) => {
  406. if (res.progress > 0) {
  407. // this.isShowProgress = true;
  408. }
  409. // this.progress = res.progress;
  410. console.log('下载进度:' + res.progress);
  411. console.log('已下载长度:' + res.totalBytesWritten);
  412. console.log('文件总长度:' + res.totalBytesExpectedToWrite);
  413. })
  414. } else {
  415. // 其他移动端浏览器
  416. window.open(this.delItem.url)
  417. }
  418. }
  419. }
  420. }
  421. }
  422. };
  423. </script>
  424. <style lang="scss" scoped>
  425. @import './index.scss';
  426. </style>