setHomework.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <view class="center">
  3. <view class="text">上传视频</view>
  4. <view class="add_picture" v-if="src" >
  5. <video :src="src" ></video>
  6. <view @click="DelImg" class="x">x</view>
  7. </view>
  8. <view v-else class="add_picture">
  9. <image src="https://zhibo.liuniu946.com/img/phone.png" @click="test"></image>
  10. </view>
  11. <view class="text">上传图片</view>
  12. <view class="add_picture">
  13. <image :src="cardimg" mode="" class="upload-img" @click.stop="imgsub" v-if="cardimg"></image>
  14. <image src="https://zhibo.liuniu946.com/img/phone.png" class="upload-img" mode="" v-if="!cardimg" @click.stop="imgsub"></image>
  15. </view>
  16. <view class="buttom" @click="submit()">上传作业</view>
  17. </view>
  18. </template>
  19. <script>
  20. import { sethomework } from '@/api/homework.js';
  21. import {
  22. uploads, upvideo
  23. } from '@/api/apply.js';
  24. export default {
  25. data(){
  26. return{
  27. id: '',
  28. src:'',
  29. key:'',
  30. cardimg:'',
  31. token:''//七牛云的token
  32. }
  33. },
  34. onLoad(option) {
  35. this.id = option.id
  36. },
  37. methods:{
  38. // 上传图片
  39. imgsub() {
  40. console.log('上传图片')
  41. uploads({
  42. filename: ''
  43. }).then(data => {
  44. console.log("data",data);
  45. this.cardimg = data[0].url;
  46. })
  47. },
  48. submit(){
  49. sethomework({
  50. timetable_id: this.id,
  51. task_video: this.src
  52. }).then(() =>{
  53. }).catch(err =>{
  54. console.log(err)
  55. })
  56. },
  57. test(){
  58. console.log('上传视频')
  59. upvideo({
  60. filename: ''
  61. }).then(data => {
  62. console.log("data",data);
  63. // this.src = data[0].url;
  64. })
  65. },
  66. // test: function () {
  67. // var self = this;
  68. // uni.chooseVideo({
  69. // count: 1,
  70. // sourceType: ['camera', 'album'],
  71. // success: function (res) {
  72. // console.log("选择视频成功",res)
  73. // self.src = res.tempFilePath;
  74. // uni.uploadFile({
  75. // url: 'https://up-z2.qiniup.com', //仅为示例,非真实的接口地址
  76. // filePath: res.tempFilePath,
  77. // name: 'files',
  78. // formData: {
  79. // 'token':self.token,
  80. // 'key':self.key
  81. // },
  82. // header: {
  83. // Authorization: 'Bearer ' + uni.getStorageSync('access')
  84. // },
  85. // success: (uploadFileRes) => {
  86. // console.log('1张', uploadFileRes);
  87. // let bold = JSON.parse(uploadFileRes.data)
  88. // console.log(bold)
  89. // console.log(bold.result[0].filePath)
  90. // self.src = bold.result[0].filePath + bold.result[0].fileName
  91. // console.log("this.returnImage", self.returnImage)
  92. // },
  93. // });
  94. // }
  95. // });
  96. // },
  97. //右上角删除视频
  98. DelImg(){
  99. this.src='',
  100. this.showVideo=false,
  101. this.addVideo=true
  102. },
  103. }
  104. }
  105. </script>
  106. <style lang="scss">
  107. .buttom {
  108. margin: 50rpx auto;
  109. width: 560rpx;
  110. height: 90rpx;
  111. background: #1CC7C7;
  112. border-radius: 45px;
  113. text-align: center;
  114. line-height: 90rpx;
  115. }
  116. .add_picture {
  117. text-align: center;
  118. position: relative;
  119. .x{
  120. position: absolute;
  121. top: 10rpx;
  122. right: 90rpx;
  123. width: 40rpx;
  124. height: 40rpx;
  125. color: #FFFFFF;
  126. z-index: 99;
  127. }
  128. }
  129. .text {
  130. text-align: center;
  131. }
  132. </style>