setHomework.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <view class="center">
  3. <view class="" v-if="showVideo" >
  4. <video :src="src" ></video>
  5. <view @click="DelImg">x</view>
  6. </view>
  7. <view v-else class="add_picture">
  8. <image src="https://zhibo.liuniu946.com/img/phone.png" @click="test"></image>
  9. </view>
  10. <view class="buttom" @click="submit()">上传作业</view>
  11. </view>
  12. </template>
  13. <script>
  14. import { sethomework } from '@/api/homework.js'
  15. export default {
  16. data(){
  17. return{
  18. id: '',
  19. showVideo: false,
  20. addVideo: false,
  21. src:''
  22. }
  23. },
  24. onLoad(option) {
  25. this.id = option.id
  26. },
  27. methods:{
  28. submit(){
  29. sethomework({
  30. timetable_id: this.id,
  31. task_video: this.src
  32. }).then(() =>{
  33. }).catch(err =>{
  34. console.log(err)
  35. })
  36. },
  37. test: function () {
  38. var self = this;
  39. uni.chooseVideo({
  40. count: 1,
  41. sourceType: ['camera', 'album'],
  42. success: function (res) {
  43. console.log("选择视频成功",res)
  44. self.showVideo=true
  45. self.addVideo=false
  46. self.src = res.tempFilePath;
  47. uni.uploadFile({
  48. url: config.upload_img_url, //仅为示例,非真实的接口地址
  49. filePath: res.tempFilePath,
  50. name: 'files',
  51. // formData: {
  52. // 'user': 'test'
  53. // },
  54. header: {
  55. Authorization: 'Bearer ' + uni.getStorageSync('access')
  56. },
  57. success: (uploadFileRes) => {
  58. console.log('1张', uploadFileRes);
  59. let bold = JSON.parse(uploadFileRes.data)
  60. console.log(bold)
  61. console.log(bold.result[0].filePath)
  62. self.returnImage = bold.result[0].filePath + bold.result[0].fileName
  63. console.log("this.returnImage", self.returnImage)
  64. },
  65. });
  66. }
  67. });
  68. },
  69. //右上角删除视频
  70. DelImg(){
  71. this.src='',
  72. this.showVideo=false,
  73. this.addVideo=true
  74. },
  75. }
  76. }
  77. </script>
  78. <style>
  79. </style>