You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

245 lines
6.1 KiB

  1. <template>
  2. <view v-if="ready">
  3. <view class="uploadBox">
  4. <view class="uploadPercentage" v-if="edit&&uploadTimer">
  5. <view class="textBox">
  6. <text v-if="percentage != 100">上传中... {{uploadedSize||'--'}}M/{{needUploadSize||'--'}}M 预计还需要{{needUploadTime||'--'}}s</text>
  7. <text style="color: #0C86D8;" v-if="percentage == 100">上传成功!</text>
  8. </view>
  9. <view class="percentageLine">
  10. <view class="percentage" :style="{width:percentage+'%'}"></view>
  11. </view>
  12. </view>
  13. <view class="chooseBox">
  14. <view v-if="!uploadList.length" class="empty" @click="chooseFile">
  15. <span>+</span>
  16. </view>
  17. <view v-else class="fileBox" @click="chooseFile">
  18. <video :src="uploadList[0].path"></video>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="fromItemBox">
  23. <view class="title">课程名称</view>
  24. <view class="inputBox">
  25. <input type="text" :disabled="!edit&&disable" v-model="form.NAME" placeholder="请输入课程名称" />
  26. </view>
  27. </view>
  28. <view v-if="edit" class="AIBtn" @click="submitClick" :style="{opacity:disable?0.6:1}">
  29. AI分析
  30. </view>
  31. <uni-toast data-duration="100000000" v-if="loading">
  32. <div class="uni-mask" style="background: rgba(17,17,17,0.3);"></div>
  33. <div class="uni-toast" style="background: #fff!important;">
  34. <i class="uni-icon_toast uni-loading"></i>
  35. <p class="uni-toast__content" style="color: #000;font-size: 14px;"> AI分析中 </p>
  36. </div>
  37. </uni-toast>
  38. </view>
  39. </template>
  40. <script>
  41. import customFormMixins from '@/common/customform.js'
  42. export default {
  43. mixins: [customFormMixins],
  44. data() {
  45. return {
  46. loading:false,
  47. form: {
  48. NAME:'',
  49. PICPATH:'',
  50. VIDEOPATH:'',
  51. },
  52. ready:false,
  53. edit:false,
  54. disable:false,
  55. uploadList:[],
  56. uploadedSize:0,
  57. needUploadSize:0,
  58. percentage:0,
  59. uploadTime:0,
  60. uploadTimer:null,
  61. needUploadTime:0,
  62. }
  63. },
  64. async onLoad({ type, id }) {
  65. await this.init(type, id)
  66. },
  67. methods: {
  68. async init(type,id){
  69. if(type == 'add'){
  70. }else{
  71. // let res = this.HTTP_GET('learun/adms/smartEducation/smartSelfCourseInfo',id)
  72. // if(!res)return
  73. // this.form = res
  74. // if(this.form.folderId){
  75. // let fileList = await this.convertToFormValue({type:'upload'},this.form.folderId)
  76. // this.uploadList = fileList.map(e=>{
  77. // e.uploaded = true
  78. // return e
  79. // })
  80. // }
  81. }
  82. this.edit = ['edit','add'].includes(type)
  83. this.ready = true
  84. },
  85. async submitClick(){
  86. if(!this.edit||this.disable)return
  87. if(!this.uploadList[0]){
  88. this.TOAST('请选择上传课程视频')
  89. return
  90. }
  91. if(!this.form.NAME){
  92. this.TOAST('请输入课程名称')
  93. return
  94. }
  95. this.loading = true
  96. this.disable = true
  97. let res = await this.uploadFile()
  98. if(!res){
  99. this.disable = false
  100. this.loading = false
  101. return
  102. }
  103. this.form.VIDEOPATH = res
  104. let result = await this.HTTP_POST('learun/adms/smartEducation/smartSelfCourseAdd',this.form,null,{timeout:60000*10});
  105. this.disable = false
  106. this.loading = false
  107. if(result){
  108. this.EMIT('list-change')
  109. this.JUMP_TO('./AIres',result,true)
  110. }
  111. },
  112. async chooseFile() {
  113. if(!this.edit||this.disable)return
  114. uni.chooseVideo({
  115. sourceType: ['album'],
  116. compressed:false,
  117. success: async (res) => {
  118. this.uploadList = [
  119. {path:res.tempFilePath,uploaded:false}
  120. ]
  121. }
  122. })
  123. },
  124. async uploadFile(){
  125. return new Promise(async (resolve)=>{
  126. let guid = this.form.VIDEOPATH || this.GUID()
  127. if(!this.uploadList[0]||this.uploadList[0].uploaded){
  128. resolve(guid)
  129. return
  130. }
  131. this.uploadTimer = setInterval(()=>{
  132. this.uploadTime++
  133. },1000)
  134. const uploadTask = await this.UPLOAD('/learun/adms/annexes/wxupload', this.uploadList[0].path,{},guid,{
  135. complete:async ()=>{
  136. if(this.percentage == 100){
  137. this.uploadList[0].uploaded = true
  138. // let fileList = await this.convertToFormValue({type:'upload'},guid)
  139. // console.log(fileList)
  140. resolve(guid)
  141. }else{
  142. resolve('')
  143. }
  144. uploadTask.abort();
  145. clearInterval(this.uploadTimer)
  146. this.uploadTimer = null
  147. this.uploadTime = 0
  148. this.percentage = 0
  149. this.uploadedSize = 0
  150. this.needUploadSize = 0
  151. this.needUploadTime = 0
  152. },
  153. },true)
  154. uploadTask.onProgressUpdate(res => {
  155. this.percentage = res.progress
  156. this.uploadedSize = this.bytesToMegabytesFixed(res.totalBytesSent)
  157. this.needUploadSize = this.bytesToMegabytesFixed(res.totalBytesExpectedToSend)
  158. this.needUploadTime = ((100-this.percentage)*this.uploadTime/this.percentage).toFixed(0)
  159. })
  160. })
  161. },
  162. bytesToMegabytesFixed(bytes) {
  163. const megabytes = bytes / (1024 * 1024);
  164. return megabytes.toFixed(2);
  165. }
  166. }
  167. }
  168. </script>
  169. <style scoped>
  170. uni-page-body{
  171. height: 100%;
  172. background-color: #fff;
  173. }
  174. .uploadBox{
  175. .uploadPercentage{
  176. .textBox{
  177. color: #666;
  178. font-size: 12px;
  179. padding: 30rpx;
  180. }
  181. .percentageLine{
  182. margin: 0 -30rpx;
  183. height: 6rpx;
  184. background-color: #ccc;
  185. .percentage{
  186. height: 100%;
  187. width: 0;
  188. background-color: #0C86D8;
  189. }
  190. }
  191. }
  192. .chooseBox{
  193. padding: 30rpx;
  194. height: 440rpx;
  195. border-radius: 16rpx;
  196. .empty{
  197. border: 2rpx dashed #0C86D8;
  198. border-radius: 16rpx;
  199. height: 100%;
  200. overflow: hidden;
  201. display: flex;
  202. justify-content: center;
  203. align-items: center;
  204. font-size: 36px;
  205. color: #0C86D8;
  206. background-color: #F1F8FD;
  207. }
  208. .fileBox{
  209. border: 2rpx dashed #0C86D8;
  210. border-radius: 16rpx;
  211. height: 100%;
  212. overflow: hidden;
  213. uni-video{
  214. height: 100%;
  215. width: 100%;
  216. }
  217. }
  218. }
  219. }
  220. .fromItemBox{
  221. margin: 30rpx;
  222. border-bottom: 2rpx solid #ccc;
  223. color: #666;
  224. font-size: 15px;
  225. input{
  226. margin-top:30rpx;
  227. margin-bottom: 30rpx;
  228. font-size: 16px;
  229. color: #333;
  230. }
  231. }
  232. .AIBtn{
  233. margin: 0 30rpx;
  234. margin-top:160rpx;
  235. color: #fff;
  236. border-radius: 15rpx;
  237. line-height: 86rpx;
  238. background-color: #0C86D8;
  239. text-align: center;
  240. font-size: 16px;
  241. }
  242. </style>