混凝土运输管理微信小程序、替班
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.

151 lines
3.3 KiB

1 week ago
  1. <template>
  2. <view>
  3. <view class="iu b-relative">
  4. <view v-if="!url" @click="selectImage()">
  5. <view class="ii" :style="{'height': height+'rpx'}" v-if="!url && files.length<1"></view>
  6. <view class="ic">
  7. <image style="width: 110rpx; height: 110rpx;" src="/static/re/ico.png" />
  8. </view>
  9. <view class="im" :style="{'height': height+'rpx'}" v-if="!url && files.length>0">
  10. <video :style="{'height': height+'rpx'}" :src="files[0].tempFilePath"
  11. mode="scaleToFill" class="im" />
  12. </view>
  13. </view>
  14. <view v-if="url" class="is" :style="{'height': 'auto'}" >
  15. <video :style="{'height': 'auto'}" :src="url"
  16. mode="widthFix" class="is" />
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. props: {
  24. height: {
  25. type: Number,
  26. required: false,
  27. default: 342
  28. },
  29. module: {
  30. type: String,
  31. required: false,
  32. default: "upload"
  33. },
  34. url: {
  35. type: String,
  36. required: false,
  37. default: ""
  38. }
  39. },
  40. data() {
  41. return {
  42. files: [],
  43. paths: [],
  44. value: [],
  45. progress: 1,
  46. udata: {}
  47. }
  48. },
  49. methods: {
  50. selectImage(){
  51. const _this = this
  52. uni.chooseMedia({
  53. count: 1,
  54. maxDuration: 300,
  55. mediaType: ["video"],
  56. success: (res) => {
  57. _this.files = res.tempFiles
  58. _this.paths = res.tempFiles[0].tempFilePath
  59. this.$httpGet("/oss/get", {}, (us) => {
  60. console.log('get', us);
  61. console.log('file', res);
  62. _this.udata = us.data
  63. _this.doUpload(_this.paths)
  64. })
  65. }
  66. })
  67. },
  68. doUpload(filePath){
  69. const key = `${this.module}/${new Date().getTime()}.mp4`;
  70. uni.uploadFile({
  71. url: this.udata.host,
  72. filePath,
  73. name: 'file',
  74. formData: {
  75. key,
  76. policy: this.udata.policy, //后台获取超时时间
  77. OSSAccessKeyId: this.udata.accessKeyId, //后台获取临时ID
  78. signature: this.udata.signature, //后台获取签名
  79. success_action_status: '200' //让服务端返回200,不然,默认会返回204
  80. },
  81. success: (res) => {
  82. console.log('oss', this.udata.host+"/"+key)
  83. //const cover = video + ' // + ',w_' + this.width +',h_' + this.height + '
  84. this.$emit('success', this.udata.host+"/"+key)
  85. //uni.showToast({
  86. // icon:'none', title:this.udata.host+"/"+key+'?x-oss-process=video/snapshot,t_10,m_fast'
  87. //})
  88. },
  89. fail: (err) => {
  90. uni.showToast({
  91. icon:'none', title: '视频存储失败'
  92. })
  93. console.log('oss', err)
  94. }
  95. })
  96. }
  97. },
  98. }
  99. </script>
  100. <style>
  101. .iu{
  102. width: 626rpx;
  103. min-height: 342rpx;
  104. height: auto;
  105. border-radius: 16px;
  106. margin: 15rpx auto;
  107. }
  108. .iu:active{
  109. transform: translateY(2rpx);
  110. box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.4);
  111. transition: transform 0.2s ease;
  112. }
  113. .ii{
  114. width: 626rpx;
  115. height: 342rpx;
  116. border-radius: 16rpx;
  117. filter: blur(3rpx);
  118. opacity: 0.89;
  119. background: rgba(41, 41, 41, 0.4);
  120. border: 1rpx dashed #ccc;
  121. }
  122. .ii:active{
  123. transform: translateY(2rpx);
  124. transition: transform 0.1s ease;
  125. }
  126. .im{
  127. width: 626rpx;
  128. height: 342rpx;
  129. border-radius: 16rpx;
  130. overflow: hidden;
  131. }
  132. .is{
  133. width: 626rpx;
  134. height: 342rpx;
  135. border-radius: 4rpx !important;
  136. overflow: hidden;
  137. }
  138. .ic{
  139. width: 110rpx;
  140. height: 110rpx;
  141. position: absolute;
  142. top: calc(50% - 55rpx);
  143. left: calc(50% - 55rpx);
  144. }
  145. </style>