index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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="addPd">
  7. <view class="createPro" @click="handleCreatePro">
  8. <view class="centerAdd">
  9. <view class="addIcon">
  10. <image src="/static/add_icon.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>
  19. <view class="context">
  20. <view class="" style="padding-left: 30rpx;padding-right: 30rpx;">
  21. <view class="swiperBox" v-if="isLogin">
  22. <view class="draftLabel">
  23. <image src="/static/caogao_icon.png" mode="" class="labelIcon"></image>
  24. 草稿
  25. </view>
  26. <empty v-if="draftList.length==0" tipTxt="暂无草稿" style="margin-top: -50rpx;"></empty>
  27. <view class="swiperCard" v-else>
  28. <view class="itemBox" :style="{backgroundImage:`url(${item.backs.url})`}"
  29. v-for="(item,index) in draftList" @click="toCreateDetail(item)">
  30. <image class="role" :src="item.roles.url" mode=""></image>
  31. <div class="barBox">
  32. <div class="name">
  33. {{item.name}}
  34. </div>
  35. <text @click.stop="delDraft(item,index)" style="color:white;font-size: 28rpx;"
  36. class="iconfont icon-shanchu"></text>
  37. </div>
  38. </view>
  39. </view>
  40. <div class="dotBox" v-if="draftList.length!==0">
  41. <div class="i1"></div>
  42. <div class="i2"></div>
  43. <div class="i3"></div>
  44. <div class="i4"></div>
  45. <div class="i5"></div>
  46. </div>
  47. </view>
  48. </view>
  49. <view style="padding-left: 15rpx;padding-right: 15rpx;">
  50. <view class="draft">
  51. <view class="draftLabel" style="padding-left: 30rpx;padding-right: 30rpx;">
  52. <image style="width: 34rpx;height: 34rpx; " src="/static/zuopin_icon.png" mode="" class="labelIcon">
  53. </image>
  54. <view style="margin-left: 14rpx;">数字人作品</view>
  55. </view>
  56. <view class="draftList1" v-if="isLogin">
  57. <view class="isLoginList" v-for="(item,index) in ['推荐作品','我的作品']" :key="index" >
  58. <view class="item" @click="getInfoWorkList(index)" :style="{ backgroundColor: current== index?'#207CF4':'',color:current == index?'white':''}">{{item}}</view>
  59. </view>
  60. </view>
  61. <view class="draftList" v-else>我的作品</view>
  62. <empty v-if="workList.length==0" :tipTxt="isLogin?'暂无作品':'暂无案例'"></empty>
  63. <view class="draftList" v-else>
  64. <view class="itemBox" v-for="(item,index) in workList" @click="goWorkDetail(item)">
  65. <!-- <view class="top" :style="{minHeight:isPc?'184rpx':'184rpx'}"> -->
  66. <view class="top">
  67. <image :src="item.cover" mode="aspectFit" v-if="item.state">
  68. </image>
  69. <view class="tipBox" v-else>
  70. <view class="preloader_1 loadingBox" style="">
  71. <view></view>
  72. <view></view>
  73. <view></view>
  74. <view></view>
  75. <view></view>
  76. </view>
  77. <!-- <view class="progress">
  78. <u-line-progress :percentage="'percentage'+item.id" :showText="true"
  79. activeColor="#9b59b6" height="12"></u-line-progress>
  80. </view> -->
  81. <view class="tip" style="color:#237FED">
  82. 生成中...
  83. </view>
  84. </view>
  85. </view>
  86. <view class="bottom" v-if="isLogin">
  87. <view class="left">
  88. {{item.name}}
  89. </view>
  90. <!-- <view class="left">
  91. {{item.state==1?"已生成":'生成中'}}
  92. </view> -->
  93. <view class="delIcon" @click.stop="handleShowMoreMenu(item,index)">
  94. <!-- <image src="/static/images/head.jpg" mode=""></image> -->
  95. <text class="iconfont icon-gengduo-shuxiang" style="font-size:32rpx;"></text>
  96. </view>
  97. </view>
  98. </view>
  99. </view>
  100. </view>
  101. </view>
  102. <wike-tabbar2 :currTabIndex='3' v-if="appInfo.page_template == 3" :is_aipainting="appInfo.is_aipainting"
  103. :onTabbar="true" :isShowAnimate="true" :appInfos="appInfo.page_template"></wike-tabbar2>
  104. <wike-tabbar :currTabIndex='3' v-else :onTabbar="true" :is_aipainting="appInfo.is_aipainting"
  105. :isShowAnimate="true" :appInfos="appInfo.page_template"></wike-tabbar>
  106. <u-popup :show="show" @close="close" @open="open" mode="center">
  107. <view
  108. style="background: rgba(0, 0, 0, 0);width: 300rpx;height: 300rpx;display: flex;align-items: center;flex-direction: column;justify-content: center;color:#26b3a0;">
  109. <l-circularProgress :isBgShow="true" :lineWidth="10" boxWidth="100" boxHeight="100"
  110. progressColor="##237FED" fontColor="##237FED" gradualColor="##237FED"
  111. :percent="progress"></l-circularProgress>
  112. <view class="">
  113. 视频下载中...
  114. </view>
  115. </view>
  116. </u-popup>
  117. <u-picker ref="picker" defaultIndex='' :closeOnClickOverlay="true" :showIcon="true" :show="showMoreMenu"
  118. :columns="columns" title="更多" confirmColor="" @cancel="showMoreMenu=false" @confirm="handleConfirm"
  119. @close="handleClosePicker"></u-picker>
  120. <!-- <wike-tabbar :onTabbar="true" :isShowAnimate="true"></wike-tabbar> -->
  121. <!-- 数字人初始引导界面 -->
  122. <div class="leadBg" v-if="showInitLead">
  123. <div class="leadBox1" v-if="showLead1" :style="{'background-image': `url(${leadBaseUrl}szr_lead.png)`}">
  124. <div class="nextBtn" @click="nextLead">
  125. </div>
  126. </div>
  127. <div class="leadBox2" v-if="showLead2">
  128. <div class="nextBtn" @click="finishLead">
  129. </div>
  130. </div>
  131. </div>
  132. <view class="pos2">
  133. </view>
  134. </view>
  135. </view>
  136. </template>
  137. <script>
  138. import BaseUrl from '@/common/config.js';
  139. import empty from '@/components/empty/empty.vue'
  140. import {
  141. demoList,
  142. workList,
  143. delWork,
  144. draftList
  145. } from '@/api/robot/index.js'
  146. import {
  147. downLoad3
  148. } from '@/utils/download3.js'
  149. import {
  150. mapMutations,
  151. mapActions,
  152. mapState,
  153. mapGetters
  154. } from 'vuex';
  155. export default {
  156. data() {
  157. return {
  158. leadBaseUrl: BaseUrl.leadBaseUrl,
  159. showInitLead: false,
  160. showLead2: false,
  161. showLead1: true,
  162. current:0,
  163. demoList: [],
  164. show: false,
  165. showMoreMenu: false,
  166. columns: [
  167. ['删除', '下载视频', '复制链接']
  168. ],
  169. draftList: [],
  170. workList: [],
  171. delItem: {},
  172. delIndex: -1,
  173. is_wx: false,
  174. isPc: false,
  175. timer: null,
  176. // percentage: 0,
  177. reqTimes: 0,
  178. progress: 0,
  179. isDowload: false
  180. };
  181. },
  182. computed: {
  183. ...mapGetters(['appInfo', 'userInfo', 'userData', 'isLogin']),
  184. isLogin() {
  185. if (uni.getStorageSync('token')) {
  186. return true
  187. } else {
  188. return false
  189. }
  190. }
  191. },
  192. onReady() {
  193. },
  194. onUnload() {
  195. },
  196. onLoad(o) {
  197. this.showInitLead = !uni.getStorageSync('showInitLead_szr')
  198. console.log("uni.getStorageSync('showInitLead')", uni.getStorageSync('showInitLead_szr'));
  199. },
  200. beforeDestroy() {
  201. console.log('beforeDestroy()---------------------');
  202. clearInterval(this.timer)
  203. },
  204. onHide() {
  205. console.log('onHide()---------------------');
  206. // 清除定时器
  207. clearInterval(this.timer)
  208. },
  209. onShow() {
  210. if (this.timer) {
  211. this.timer = null
  212. }
  213. // console.log('当前时间戳:', Date.now() + 180000);
  214. let _this = this
  215. // if (getApp().from == 'create') {
  216. // }
  217. this.getWorkList()
  218. this.getIndexData()
  219. const userAgent = navigator.userAgent.toLowerCase();
  220. if (/ipad|iphone|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/.test(userAgent)) {
  221. // 移动端
  222. console.log('移动端')
  223. this.isPc = false
  224. } else {
  225. // pc端
  226. this.isPc = true
  227. console.log('PC端')
  228. }
  229. // console.log('1213', download);
  230. this.is_wx = this.is_weixin()
  231. console.log('this.is_wx', this.is_wx);
  232. },
  233. onShareAppMessage: function(res) {
  234. },
  235. // async onPullDownRefresh() {
  236. // this.getIndexData()
  237. // },
  238. methods: {
  239. nextLead() {
  240. // this.showLead1 = false
  241. // this.showLead2 = true
  242. this.showInitLead = false
  243. this.showLead1 = false
  244. uni.setStorageSync('showInitLead_szr', true)
  245. },
  246. finishLead() {
  247. this.showInitLead = false
  248. this.showLead2 = false
  249. uni.setStorageSync('showInitLead_szr', true)
  250. },
  251. open() {
  252. // console.log('open');
  253. },
  254. close() {
  255. this.show = false
  256. // console.log('close');
  257. },
  258. handleClosePicker() {
  259. this.showMoreMenu = false
  260. // this.columns = [
  261. // ['删除', '下载视频', '复制链接']
  262. // ]
  263. },
  264. toCreateDetail(item) {
  265. getApp().draftDetail = item
  266. uni.navigateTo({
  267. url: '/pages/digitalMen/generate/index'
  268. })
  269. },
  270. delDraft(item, index) {
  271. let _this = this
  272. uni.showModal({
  273. title: '提示',
  274. confirmColor: '#207CF7',
  275. content: '是否确认删除:' + item.name + '?',
  276. success: async (res1) => {
  277. if (res1.confirm) {
  278. // let res = await delWork({
  279. // id: item.id
  280. // })
  281. let res = await this.$http('digitalMen.delWork', {
  282. id: item.id
  283. })
  284. if (res.code == 0) {
  285. _this.draftList.splice(index, 1)
  286. console.log('删除数字人草稿返回值:', res);
  287. uni.showToast({
  288. title: '数字人:' + item.name + '草稿删除成功!',
  289. icon: 'success'
  290. })
  291. } else {
  292. uni.showToast({
  293. title: res.msg,
  294. icon: 'none'
  295. })
  296. }
  297. } else if (res1.cancel) {
  298. }
  299. }
  300. });
  301. },
  302. downLoad(url) {
  303. uni.downloadFile({
  304. url: url,
  305. header: {
  306. // 'Authorization':this.$utils.localData.getToken(),
  307. },
  308. success: (res) => {
  309. if (res.statusCode === 200) {
  310. console.log('res.tempFilePath', res.tempFilePath);
  311. return
  312. //res.tempFilePath; //此参数为本地的缓存地址
  313. var link = document.createElement('a');
  314. link.href = url; //url 为获取的本地缓存地址或者直接是url地址
  315. link.download = name + '.file'; //name为自定义的文件名称 .file为文件后缀名
  316. document.body.appendChild(link)
  317. link.click()
  318. //移除
  319. setTimeout(() => document.body.removeChild(link), 1000)
  320. }
  321. },
  322. fail: (e) => {
  323. uni.showToast({
  324. title: '数据处理错误,请刷新重试',
  325. icon: 'none',
  326. duration: 2000
  327. });
  328. }
  329. })
  330. },
  331. downLoad2(url) {
  332. var link = document.createElement('a');
  333. link.href = url; //url 为获取的本地缓存地址或者直接是url地址
  334. link.download = '数字人视频' + '.mp4'; //name为自定义的文件名称 .file为文件后缀名
  335. document.body.appendChild(link)
  336. link.click()
  337. //移除
  338. setTimeout(() => document.body.removeChild(link), 1000)
  339. },
  340. // 判断是否是微信浏览器
  341. is_weixin() {
  342. var ua = window.navigator.userAgent.toLowerCase();
  343. if (ua.match(/MicroMessenger/i) == 'micromessenger') {
  344. console.log('微信浏览器');
  345. return true;
  346. } else {
  347. console.log("不是微信浏览器");
  348. return false;
  349. }
  350. },
  351. getInfoWorkList(index){
  352. this.current =index
  353. if(index == 0){
  354. let params = {
  355. is_select:1
  356. }
  357. this.getWorkList(params)
  358. }
  359. else{
  360. this.getWorkList(null)
  361. }
  362. },
  363. async getWorkList(params) {
  364. let _this = this
  365. let res = await this.$http('digitalMen.workList', params)
  366. if (res.code == 0) {
  367. // uni.stopPullDownRefresh()
  368. this.workList = res.data
  369. let allSuc = res.data.every((item, index) => {
  370. return item.state == 1
  371. })
  372. if (allSuc || res.data.length == 0) {
  373. clearInterval(_this.timer)
  374. return
  375. }
  376. console.log('onshow------------------_this.timer', _this.timer);
  377. if (_this.timer) {
  378. return
  379. }
  380. _this.timer = setInterval(() => {
  381. _this.getWorkList()
  382. }, 5000)
  383. console.log('数字人作品列表返回值:', res);
  384. } else {
  385. uni.showToast({
  386. title: res.msg,
  387. icon: 'none'
  388. })
  389. }
  390. },
  391. async getIndexData() {
  392. if (!uni.getStorageSync('token')) {
  393. return
  394. }
  395. let res1 = await this.$http('digitalMen.draftList', {})
  396. if (res1.code == 0) {
  397. // uni.stopPullDownRefresh()
  398. this.draftList = res1.data
  399. console.log('数字人草稿列表返回值:', res1);
  400. } else {
  401. uni.showToast({
  402. title: res1.msg,
  403. icon: 'none'
  404. })
  405. }
  406. if (res1.code == 0 && res.code == 0) {
  407. uni.stopPullDownRefresh()
  408. }
  409. },
  410. goWorkDetail(item) {
  411. if (item.state == 0) {
  412. uni.showToast({
  413. title: '数字人正在生成中,请稍后查看',
  414. icon: 'none'
  415. })
  416. return
  417. }
  418. getApp().url = item.url
  419. uni.navigateTo({
  420. url: '/pages/digitalMen/workDetail/index'
  421. })
  422. },
  423. handleCreatePro() {
  424. if (!uni.getStorageSync('token')) {
  425. uni.showToast({
  426. title: '请登录后创建项目',
  427. icon: 'none'
  428. })
  429. setTimeout(() => {
  430. uni.navigateTo({
  431. url: '/pages/user/signin'
  432. })
  433. }, 1500)
  434. return
  435. } else {
  436. uni.navigateTo({
  437. url: '/pages/digitalMen/generate/index?type=create'
  438. })
  439. }
  440. },
  441. handleShowMoreMenu(item, index) {
  442. this.$refs.picker.setIndexs([0])
  443. this.delIndex = index
  444. this.delItem = item
  445. this.showMoreMenu = true
  446. },
  447. async handleConfirm(e) {
  448. let _this = this
  449. this.showMoreMenu = false
  450. if (e.value[0] == '删除') {
  451. // if (this.delItem.state == 0) {
  452. // uni.showToast({
  453. // title: '数字人正在生成中,请稍后操作',
  454. // icon: 'none'
  455. // })
  456. // return
  457. // }
  458. uni.showModal({
  459. title: '提示',
  460. confirmColor: '#207CF7',
  461. content: '是否确认删除:' + _this.delItem.name + '?',
  462. success: async (res1) => {
  463. if (res1.confirm) {
  464. // let res = await delWork({
  465. // id: _this.delItem.id
  466. // })
  467. let res = await _this.$http('digitalMen.delWork', {
  468. id: _this.delItem.id
  469. })
  470. if (res.code == 0) {
  471. _this.workList.splice(this.delIndex, 1)
  472. if (_this.workList.length == 0) {
  473. clearInterval(_this.timer)
  474. }
  475. console.log('删除数字人返回值:', res);
  476. uni.showToast({
  477. title: '数字人:' + _this.delItem.name + '删除成功!',
  478. icon: 'success'
  479. })
  480. } else {
  481. uni.showToast({
  482. title: res.msg,
  483. icon: 'none'
  484. })
  485. }
  486. } else if (res1.cancel) {
  487. }
  488. }
  489. });
  490. } else if (e.value[0] == '复制链接') {
  491. if (this.delItem.state == 0) {
  492. uni.showToast({
  493. title: '数字人正在生成中,请稍后复制链接',
  494. icon: 'none'
  495. })
  496. return
  497. }
  498. uni.setClipboardData({
  499. data: this.delItem.url,
  500. success: function() {
  501. uni.showToast({
  502. title: '链接复制成功!',
  503. duration: 1500
  504. });
  505. }
  506. });
  507. } else if (e.value[0] == '下载视频') {
  508. if (this.delItem.state == 0) {
  509. uni.showToast({
  510. title: '数字人正在生成中,请稍后下载视频',
  511. icon: 'none'
  512. })
  513. return
  514. }
  515. const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i
  516. .test(
  517. navigator.userAgent) ? false : true;
  518. if (this.is_wx) {
  519. // 微信内置浏览器
  520. // this.downLoad2(this.delItem.url)
  521. let _that = this
  522. uni.showModal({
  523. title: '温馨提示',
  524. content: '微信内置浏览器不支持视频文件下载,请复制视频链接至手机浏览器打开',
  525. confirmText: '复制',
  526. confirmColor: '#207CF7',
  527. success: function(res) {
  528. if (res.confirm) {
  529. uni.setClipboardData({
  530. data: _that.delItem.url,
  531. success: function() {
  532. uni.showToast({
  533. title: "复制成功",
  534. icon: 'success',
  535. })
  536. }
  537. });
  538. } else if (res.cancel) {}
  539. }
  540. })
  541. return
  542. } else {
  543. if (detectDeviceType()) {
  544. let _this = this
  545. if (_this.isDowload) {
  546. uni.showToast({
  547. icon: 'none',
  548. title: '请等待上一个视频下载完成后,再下载',
  549. });
  550. }
  551. // PC端
  552. // this.delItem.url = 'http://www.liwantao.top/test.mp4'
  553. const downloadTask = uni.downloadFile({
  554. url: _this.delItem.url, //文件链接
  555. timeout: 99999999,
  556. success: (res) => {
  557. if (res.statusCode === 200) {
  558. var oA = document.createElement("a");
  559. oA.download = _this.delItem.name; // 设置下载的文件名,默认是'下载'
  560. oA.href = res.tempFilePath; //临时路径再保存到本地
  561. document.body.appendChild(oA);
  562. oA.click();
  563. oA.remove(); // 下载之后把创建的元素删除
  564. }
  565. },
  566. fail: (err) => {
  567. _this.show = false;
  568. _this.isDowload = false
  569. _this.progress = 0
  570. // console.log(_this.show, _this.isDowload, _this.progress, err);
  571. uni.showToast({
  572. icon: 'none',
  573. mask: true,
  574. title: '失败请重新下载',
  575. });
  576. },
  577. })
  578. downloadTask.onProgressUpdate((res) => {
  579. if (res.progress > 0) {
  580. _this.show = true;
  581. _this.isDowload = true
  582. }
  583. _this.progress = res.progress;
  584. if (res.progress == 100) {
  585. _this.show = false;
  586. _this.isDowload = false
  587. _this.progress = 0
  588. uni.showToast({
  589. icon: 'success',
  590. title: _this.delItem.name + ',下载成功!',
  591. });
  592. }
  593. })
  594. } else {
  595. // 其他移动端浏览器
  596. // window.open(this.delItem.url)
  597. let _this = this
  598. // this.delItem.url = 'http://www.liwantao.top/test.mp4'
  599. var oA = document.createElement("a");
  600. oA.download = _this.delItem.name;
  601. oA.href = _this.delItem.url;
  602. document.body.appendChild(oA);
  603. oA.click();
  604. oA.remove();
  605. }
  606. }
  607. }
  608. }
  609. }
  610. };
  611. </script>
  612. <style lang="scss" scoped>
  613. @import './index.scss';
  614. </style>