index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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">
  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. <image src="/static/images/head.jpg" mode=""></image>
  26. </view>
  27. <view class="bottom">
  28. <view class="left">
  29. {{item.name}}
  30. </view>
  31. <view class="delIcon" @click.stop="delDraft(item,index)">
  32. <!-- <image src="/static/images/head.jpg" mode=""></image> -->
  33. <text class="iconfont icon-shanchu" style="font-size: 32rpx;"></text>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="draft">
  40. <view class="draftLabel">
  41. 数字人作品
  42. </view>
  43. <view class="draftList">
  44. <view class="itemBox" v-for="(item,index) in workList" @click="goWorkDetail(item)">
  45. <view class="top">
  46. <image :src="item.cover" mode="" v-if="item.state"></image>
  47. <view class="tipBox" v-else>
  48. <view class="preloader_1">
  49. <view></view>
  50. <view></view>
  51. <view></view>
  52. <view></view>
  53. <view></view>
  54. </view>
  55. <view class="tip" style="color:#26b3a0">
  56. 生成中...
  57. </view>
  58. </view>
  59. </view>
  60. <view class="bottom">
  61. <view class="left">
  62. {{item.name}}
  63. </view>
  64. <!-- <view class="left">
  65. {{item.state==1?"已生成":'生成中'}}
  66. </view> -->
  67. <view class="delIcon" @click.stop="handleShowMoreMenu(item,index)">
  68. <!-- <image src="/static/images/head.jpg" mode=""></image> -->
  69. <text class="iconfont icon-gengduo-shuxiang" style="font-size: 32rpx;"></text>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <!-- <button @click="test">测试网络请求</button> -->
  76. <u-picker :showIcon="true" :show="showMoreMenu" :columns="columns" title="更多" confirmColor=""
  77. @cancel="showMoreMenu=false" @confirm="handleConfirm"></u-picker>
  78. <wike-tabbar :onTabbar="true" :isShowAnimate="true"></wike-tabbar>
  79. </view>
  80. </view>
  81. </template>
  82. <script>
  83. import {
  84. workList,
  85. delWork,
  86. draftList
  87. } from '@/api/robot/index.js'
  88. import {
  89. downLoad3
  90. } from '@/utils/download3.js'
  91. export default {
  92. data() {
  93. return {
  94. showMoreMenu: false,
  95. columns: [
  96. ['删除', '下载视频', '复制链接']
  97. ],
  98. draftList: [],
  99. workList: [],
  100. delItem: {},
  101. delIndex: -1,
  102. is_wx: false
  103. };
  104. },
  105. computed: {
  106. },
  107. onReady() {
  108. },
  109. onUnload() {
  110. },
  111. onLoad() {
  112. },
  113. onShow() {
  114. // console.log('1213', download);
  115. this.getIndexData()
  116. this.is_wx = this.is_weixin()
  117. console.log('this.is_wx', this.is_wx);
  118. },
  119. onShareAppMessage: function(res) {
  120. },
  121. async onPullDownRefresh() {
  122. this.getIndexData()
  123. },
  124. methods: {
  125. toCreateDetail(item) {
  126. getApp().draftDetail = item
  127. uni.navigateTo({
  128. url: '/pages/robot/generate/index'
  129. })
  130. },
  131. async delDraft(item, index) {
  132. let res = await delWork({
  133. id: item.id
  134. })
  135. if (res.code == 0) {
  136. this.draftList.splice(index, 1)
  137. console.log('删除数字人草稿返回值:', res);
  138. uni.showToast({
  139. title: '数字人:' + item.name + '草稿删除成功!',
  140. icon: 'success'
  141. })
  142. } else {
  143. uni.showToast({
  144. title: res.msg,
  145. icon: 'none'
  146. })
  147. }
  148. },
  149. downLoad(url) {
  150. uni.downloadFile({
  151. url: url,
  152. header: {
  153. // 'Authorization':this.$utils.localData.getToken(),
  154. },
  155. success: (res) => {
  156. if (res.statusCode === 200) {
  157. console.log('res.tempFilePath', res.tempFilePath);
  158. return
  159. //res.tempFilePath; //此参数为本地的缓存地址
  160. var link = document.createElement('a');
  161. link.href = url; //url 为获取的本地缓存地址或者直接是url地址
  162. link.download = name + '.file'; //name为自定义的文件名称 .file为文件后缀名
  163. document.body.appendChild(link)
  164. link.click()
  165. //移除
  166. setTimeout(() => document.body.removeChild(link), 1000)
  167. }
  168. },
  169. fail: (e) => {
  170. uni.showToast({
  171. title: '数据处理错误,请刷新重试',
  172. icon: 'none',
  173. duration: 2000
  174. });
  175. }
  176. })
  177. },
  178. downLoad2(url) {
  179. var link = document.createElement('a');
  180. link.href = url; //url 为获取的本地缓存地址或者直接是url地址
  181. link.download = '数字人视频' + '.mp4'; //name为自定义的文件名称 .file为文件后缀名
  182. document.body.appendChild(link)
  183. link.click()
  184. //移除
  185. setTimeout(() => document.body.removeChild(link), 1000)
  186. },
  187. // 判断是否是微信浏览器
  188. is_weixin() {
  189. var ua = window.navigator.userAgent.toLowerCase();
  190. if (ua.match(/MicroMessenger/i) == 'micromessenger') {
  191. console.log('微信浏览器');
  192. return true;
  193. } else {
  194. console.log("不是微信浏览器");
  195. return false;
  196. }
  197. },
  198. async getIndexData() {
  199. let res = await workList({})
  200. if (res.code == 0) {
  201. uni.stopPullDownRefresh()
  202. this.workList = res.data
  203. console.log('数字人作品列表返回值:', res);
  204. } else {
  205. uni.showToast({
  206. title: res.msg,
  207. icon: 'none'
  208. })
  209. }
  210. let res1 = await draftList({})
  211. if (res1.code == 0) {
  212. uni.stopPullDownRefresh()
  213. this.draftList = res1.data
  214. console.log('数字人草稿列表返回值:', res1);
  215. } else {
  216. uni.showToast({
  217. title: res1.msg,
  218. icon: 'none'
  219. })
  220. }
  221. },
  222. goWorkDetail(item) {
  223. if (item.state == 0) {
  224. uni.showToast({
  225. title: '数字人正在生成中,请稍后查看',
  226. icon: 'none'
  227. })
  228. return
  229. }
  230. getApp().url = item.url
  231. uni.navigateTo({
  232. url: '/pages/robot/workDetail/index'
  233. })
  234. },
  235. handleCreatePro() {
  236. uni.navigateTo({
  237. url: '/pages/robot/generate/index'
  238. })
  239. },
  240. handleShowMoreMenu(item, index) {
  241. this.delIndex = index
  242. this.delItem = item
  243. this.showMoreMenu = true
  244. },
  245. async handleConfirm(e) {
  246. this.showMoreMenu = false
  247. if (e.value[0] == '删除') {
  248. let res = await delWork({
  249. id: this.delItem.id
  250. })
  251. if (res.code == 0) {
  252. this.workList.splice(this.delIndex, 1)
  253. console.log('删除数字人返回值:', res);
  254. uni.showToast({
  255. title: '数字人:' + this.delItem.name + '删除成功!',
  256. icon: 'success'
  257. })
  258. } else {
  259. uni.showToast({
  260. title: res.msg,
  261. icon: 'none'
  262. })
  263. }
  264. } else if (e.value[0] == '复制链接') {
  265. uni.setClipboardData({
  266. data: this.delItem.url,
  267. success: function() {
  268. uni.showToast({
  269. title: '链接复制成功!',
  270. duration: 1500
  271. });
  272. }
  273. });
  274. } else if (e.value[0] == '下载视频') {
  275. const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i
  276. .test(
  277. navigator.userAgent) ? false : true;
  278. if (this.is_wx) {
  279. // 微信内置浏览器
  280. // this.downLoad2(this.delItem.url)
  281. let _that = this
  282. uni.showModal({
  283. title: '温馨提示',
  284. content: '微信内置浏览器不支持视频文件下载,请复制视频链接至手机浏览器打开',
  285. confirmText: '复制',
  286. confirmColor: '#26B3A0',
  287. success: function(res) {
  288. if (res.confirm) {
  289. uni.setClipboardData({
  290. data: _that.delItem.url,
  291. success: function() {
  292. uni.showToast({
  293. title: "复制成功",
  294. icon: 'success',
  295. })
  296. }
  297. });
  298. } else if (res.cancel) {}
  299. }
  300. })
  301. return
  302. } else {
  303. if (detectDeviceType()) {
  304. // PC端
  305. downLoad3(this.delItem.url, '数字人' + this.delItem.name + '视频', 'video/mp4')
  306. } else {
  307. // 其他移动端浏览器
  308. window.open(this.delItem.url)
  309. }
  310. }
  311. }
  312. }
  313. }
  314. };
  315. </script>
  316. <style lang="scss" scoped>
  317. @import './index.scss';
  318. </style>