123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505 |
- <template>
- <view class="container">
- <!-- <tn-nav-bar :isBack="false" backgroundColor="#fff" :bottomShadow="false">数字人</tn-nav-bar> -->
- <!-- <view class="pos">
- </view> -->
- <view class="context">
- <view class="createPro" @click="handleCreatePro">
- <view class="centerAdd">
- <view class="addIcon">
- <!-- <image src="/static/images/buy.png" mode=""></image> -->
- <text class="iconfont icon-chuangjian" style="color: white;"></text>
- </view>
- <view class="addTxt">
- 创建项目
- </view>
- </view>
- </view>
- <view class="draft" v-if="draftList.length!=0">
- <view class="draftLabel">
- 草稿
- </view>
- <view class="draftList">
- <view class="itemBox" v-for="(item,index) in draftList" @click="toCreateDetail(item)">
- <view class="top"
- style="display: flex;justify-content: center;align-items: center;aspect-ratio: 4/3;">
- <text class="iconfont icon-caogao" style="color: white;font-size: 46rpx;"></text>
- </view>
- <view class="bottom">
- <view class="left">
- {{item.name}}
- </view>
- <view class="delIcon" @click.stop="delDraft(item,index)">
- <!-- <image src="/static/images/head.jpg" mode=""></image> -->
- <text class="iconfont icon-shanchu" style="font-size: 32rpx;"></text>
- </view>
- </view>
- </view>
- </view>
- </view>
- <view class="draft">
- <view class="draftLabel">
- 数字人作品
- </view>
- <view class="draftList">
- <view class="itemBox" v-for="(item,index) in workList" @click="goWorkDetail(item)">
- <view class="top" :style="{minHeight:isPc?'rpx':'470rpx'}">
- <image :src="item.cover" mode="aspectFit" v-if="item.state">
- </image>
- <view class="tipBox" v-else>
- <!-- <view class="preloader_1" :style="{left:isPc?'':'40%'}">
- <view></view>
- <view></view>
- <view></view>
- <view></view>
- <view></view>
- </view> -->
- <view class="preloader_1" style="">
- <view></view>
- <view></view>
- <view></view>
- <view></view>
- <view></view>
- </view>
- <!-- <view class="progress">
- <u-line-progress :percentage="'percentage'+item.id" :showText="true"
- activeColor="#9b59b6" height="12"></u-line-progress>
- </view> -->
- <view class="tip" style="color:#26b3a0">
- 生成中...
- </view>
- </view>
- </view>
- <view class="bottom">
- <view class="left">
- {{item.name}}
- </view>
- <!-- <view class="left">
- {{item.state==1?"已生成":'生成中'}}
- </view> -->
- <view class="delIcon" @click.stop="handleShowMoreMenu(item,index)">
- <!-- <image src="/static/images/head.jpg" mode=""></image> -->
- <text class="iconfont icon-gengduo-shuxiang" style="font-size: 32rpx;"></text>
- </view>
- </view>
- </view>
- </view>
- </view>
- <u-popup :show="show" @close="close" @open="open" mode="center">
- <view
- style="background: rgba(0, 0, 0, 0);width: 300rpx;height: 300rpx;display: flex;align-items: center;flex-direction: column;justify-content: center;color:#26b3a0;">
- <l-circularProgress :isBgShow="true" :lineWidth="10" boxWidth="100" boxHeight="100"
- progressColor="#26b3a0" fontColor="#26b3a0" gradualColor="#26b3a0"
- :percent="progress"></l-circularProgress>
- <view class="">
- 视频下载中...
- </view>
- </view>
- </u-popup>
- <u-picker :defaultIndex='[0]' :closeOnClickOverlay="true" :showIcon="true" :show="showMoreMenu"
- :columns="columns" title="更多" confirmColor="" @cancel="showMoreMenu=false" @confirm="handleConfirm"
- @close="handleClosePicker"></u-picker>
- <wike-tabbar :onTabbar="true" :isShowAnimate="true"></wike-tabbar>
- </view>
- </view>
- </template>
- <script>
- import {
- workList,
- delWork,
- draftList
- } from '@/api/robot/index.js'
- import {
- downLoad3
- } from '@/utils/download3.js'
- export default {
- data() {
- return {
- show: false,
- showMoreMenu: false,
- columns: [
- ['删除', '下载视频', '复制链接']
- ],
- draftList: [],
- workList: [],
- delItem: {},
- delIndex: -1,
- is_wx: false,
- isPc: false,
- timer: null,
- // percentage: 0,
- reqTimes: 0,
- progress: 0,
- isDowload: false
- };
- },
- computed: {
- },
- onReady() {
- },
- onUnload() {
- },
- onLoad(o) {
- },
- onShow() {
- let _this = this
- if (getApp().from == 'create') {
- _this.timer = setInterval(async () => {
- let res = await workList({})
- if (res.code == 0) {
- // _this.reqTimes += 1
- _this.workList = res.data
- // res.data.forEach((item, index) => {
- // console.log('每一个percentage', _this['percentage' + item.id]);
- // if (_this.reqTimes <= 5) {
- // _this['percentage' + item.id] += 10
- // } else {
- // _this['percentage' + item.id] += 1
- // }
- // if (item.state == 1) {
- // console.log('已完成的那一项', item);
- // _this['percentage' + item.id] = 100
- // }
- // })
- let allSuc = res.data.every((item, index) => {
- return item.state == 1
- })
- if (allSuc) {
- clearInterval(_this.timer)
- // _this.percentage = 100
- return
- }
- console.log('定时器--数字人作品列表返回值:', res);
- } else {
- uni.showToast({
- title: res.msg,
- icon: 'none'
- })
- }
- }, 10000)
- }
- getApp().from = ''
- const userAgent = navigator.userAgent.toLowerCase();
- if (/ipad|iphone|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/.test(userAgent)) {
- // 移动端
- console.log('移动端')
- this.isPc = false
- } else {
- // pc端
- this.isPc = true
- console.log('PC端')
- }
- // console.log('1213', download);
- this.getIndexData()
- this.is_wx = this.is_weixin()
- console.log('this.is_wx', this.is_wx);
- },
- onShareAppMessage: function(res) {
- },
- async onPullDownRefresh() {
- this.getIndexData()
- },
- methods: {
- open() {
- // console.log('open');
- },
- close() {
- this.show = false
- // console.log('close');
- },
- handleClosePicker() {
- this.showMoreMenu = false
- // this.columns = [
- // ['删除', '下载视频', '复制链接']
- // ]
- },
- toCreateDetail(item) {
- getApp().draftDetail = item
- uni.navigateTo({
- url: '/pages/robot/generate/index'
- })
- },
- async delDraft(item, index) {
- let res = await delWork({
- id: item.id
- })
- if (res.code == 0) {
- this.draftList.splice(index, 1)
- console.log('删除数字人草稿返回值:', res);
- uni.showToast({
- title: '数字人:' + item.name + '草稿删除成功!',
- icon: 'success'
- })
- } else {
- uni.showToast({
- title: res.msg,
- icon: 'none'
- })
- }
- },
- downLoad(url) {
- uni.downloadFile({
- url: url,
- header: {
- // 'Authorization':this.$utils.localData.getToken(),
- },
- success: (res) => {
- if (res.statusCode === 200) {
- console.log('res.tempFilePath', res.tempFilePath);
- return
- //res.tempFilePath; //此参数为本地的缓存地址
- var link = document.createElement('a');
- link.href = url; //url 为获取的本地缓存地址或者直接是url地址
- link.download = name + '.file'; //name为自定义的文件名称 .file为文件后缀名
- document.body.appendChild(link)
- link.click()
- //移除
- setTimeout(() => document.body.removeChild(link), 1000)
- }
- },
- fail: (e) => {
- uni.showToast({
- title: '数据处理错误,请刷新重试',
- icon: 'none',
- duration: 2000
- });
- }
- })
- },
- downLoad2(url) {
- var link = document.createElement('a');
- link.href = url; //url 为获取的本地缓存地址或者直接是url地址
- link.download = '数字人视频' + '.mp4'; //name为自定义的文件名称 .file为文件后缀名
- document.body.appendChild(link)
- link.click()
- //移除
- setTimeout(() => document.body.removeChild(link), 1000)
- },
- // 判断是否是微信浏览器
- is_weixin() {
- var ua = window.navigator.userAgent.toLowerCase();
- if (ua.match(/MicroMessenger/i) == 'micromessenger') {
- console.log('微信浏览器');
- return true;
- } else {
- console.log("不是微信浏览器");
- return false;
- }
- },
- async getIndexData() {
- let res = await workList({})
- if (res.code == 0) {
- uni.stopPullDownRefresh()
- this.workList = res.data
- // let parm = {}
- // res.data.forEach((item, index) => {
- // parm['percentage' + item.id] = 0
- // })
- // this.$data = Object.assign(this.$data, parm);
- // console.log('百分比批量赋值后:', this.$data);
- console.log('数字人作品列表返回值:', res);
- } else {
- uni.showToast({
- title: res.msg,
- icon: 'none'
- })
- }
- let res1 = await draftList({})
- if (res1.code == 0) {
- uni.stopPullDownRefresh()
- this.draftList = res1.data
- console.log('数字人草稿列表返回值:', res1);
- } else {
- uni.showToast({
- title: res1.msg,
- icon: 'none'
- })
- }
- },
- goWorkDetail(item) {
- if (item.state == 0) {
- uni.showToast({
- title: '数字人正在生成中,请稍后查看',
- icon: 'none'
- })
- return
- }
- getApp().url = item.url
- uni.navigateTo({
- url: '/pages/robot/workDetail/index'
- })
- },
- handleCreatePro() {
- uni.navigateTo({
- url: '/pages/robot/generate/index?type=create'
- })
- },
- handleShowMoreMenu(item, index) {
- this.delIndex = index
- this.delItem = item
- this.showMoreMenu = true
- },
- async handleConfirm(e) {
- this.showMoreMenu = false
- if (e.value[0] == '删除') {
- let res = await delWork({
- id: this.delItem.id
- })
- if (res.code == 0) {
- this.workList.splice(this.delIndex, 1)
- console.log('删除数字人返回值:', res);
- uni.showToast({
- title: '数字人:' + this.delItem.name + '删除成功!',
- icon: 'success'
- })
- } else {
- uni.showToast({
- title: res.msg,
- icon: 'none'
- })
- }
- } else if (e.value[0] == '复制链接') {
- uni.setClipboardData({
- data: this.delItem.url,
- success: function() {
- uni.showToast({
- title: '链接复制成功!',
- duration: 1500
- });
- }
- });
- } else if (e.value[0] == '下载视频') {
- const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i
- .test(
- navigator.userAgent) ? false : true;
- if (this.is_wx) {
- // 微信内置浏览器
- // this.downLoad2(this.delItem.url)
- let _that = this
- uni.showModal({
- title: '温馨提示',
- content: '微信内置浏览器不支持视频文件下载,请复制视频链接至手机浏览器打开',
- confirmText: '复制',
- confirmColor: '#26B3A0',
- success: function(res) {
- if (res.confirm) {
- uni.setClipboardData({
- data: _that.delItem.url,
- success: function() {
- uni.showToast({
- title: "复制成功",
- icon: 'success',
- })
- }
- });
- } else if (res.cancel) {}
- }
- })
- return
- } else {
- if (detectDeviceType()) {
- let _this = this
- if (_this.isDowload) {
- uni.showToast({
- icon: 'none',
- title: '请等待上一个视频下载完成后,再下载',
- });
- }
- // PC端
- // this.delItem.url = 'http://www.liwantao.top/test.mp4'
- // downLoad3(this.delItem.url, '数字人' + this.delItem.name + '视频', 'video/mp4')
- const downloadTask = uni.downloadFile({
- url: _this.delItem.url, //文件链接
- success: (res) => {
- if (res.statusCode === 200) {
- var oA = document.createElement("a");
- oA.download = _this.delItem.name; // 设置下载的文件名,默认是'下载'
- oA.href = res.tempFilePath; //临时路径再保存到本地
- document.body.appendChild(oA);
- oA.click();
- oA.remove(); // 下载之后把创建的元素删除
- }
- },
- fail: (err) => {
- _this.show = false;
- _this.isDowload = false
- _this.progress = 0
- // console.log(_this.show, _this.isDowload, _this.progress, err);
- uni.showToast({
- icon: 'none',
- mask: true,
- title: '失败请重新下载',
- });
- },
- })
- downloadTask.onProgressUpdate((res) => {
- if (res.progress > 0) {
- _this.show = true;
- _this.isDowload = true
- }
- _this.progress = res.progress;
- if (res.progress == 100) {
- _this.show = false;
- _this.isDowload = false
- _this.progress = 0
- uni.showToast({
- icon: 'success',
- title: _this.delItem.name + ',下载成功!',
- });
- }
- })
- } else {
- // 其他移动端浏览器
- window.open(this.delItem.url)
- }
- }
- }
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- @import './index.scss';
- </style>
|