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

147 lines
3.3 KiB

1 week ago
  1. <template>
  2. <view>
  3. <view class="iu b-relative">
  4. <view class="clicked" 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. <image :style="{'height': height+'rpx'}" :src="files[0].path"
  11. mode="scaleToFill" class="im" />
  12. </view>
  13. </view>
  14. <view v-if="url" class="is" :style="{'height': 'auto'}" >
  15. <image :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. value: [],
  44. progress: 1,
  45. udata: {}
  46. }
  47. },
  48. methods: {
  49. selectImage(){
  50. const _this = this
  51. uni.chooseImage({
  52. count: 1,
  53. success: (res) => {
  54. //控制格式
  55. //if (["video/mp4", "video/ogg", "video/flv", "video/avi", "video/wmv", "video/rmvb", "video/mov",].indexOf(file.type) == -1) {
  56. // this.$message.error("请上传正确的视频格式");
  57. // return false;
  58. //}
  59. _this.files = res.tempFiles
  60. this.$httpGet("/oss/get", {}, (us) => {
  61. console.log('get', us);
  62. _this.udata = us.data
  63. _this.files.forEach(file => {
  64. _this.doUpload(file.path)
  65. })
  66. })
  67. }
  68. })
  69. },
  70. doUpload(filePath){
  71. const key = `${this.module}/${new Date().getTime()}.png`;
  72. uni.uploadFile({
  73. url: this.udata.host,
  74. filePath,
  75. name: 'file',
  76. formData: {
  77. key,
  78. policy: this.udata.policy, //后台获取超时时间
  79. OSSAccessKeyId: this.udata.accessKeyId, //后台获取临时ID
  80. signature: this.udata.signature, //后台获取签名
  81. success_action_status: '200' //让服务端返回200,不然,默认会返回204
  82. },
  83. success: (res) => {
  84. console.log('oss', this.udata.host+"/"+key)
  85. //const cover = video + '?x-oss-process=video/snapshot,t_10,m_fast' // + ',w_' + this.width +',h_' + this.height + '
  86. this.$emit('success', this.udata.host+"/"+key)
  87. },
  88. fail: (err) => {
  89. console.log('oss', err)
  90. }
  91. })
  92. }
  93. },
  94. }
  95. </script>
  96. <style>
  97. .iu{
  98. width: 626rpx;
  99. min-height: 342rpx;
  100. height: auto;
  101. border-radius: 16px;
  102. margin: 15rpx auto;
  103. }
  104. .iu:active{
  105. transform: translateY(2rpx);
  106. box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.4);
  107. transition: transform 0.2s ease;
  108. }
  109. .ii{
  110. width: 626rpx;
  111. height: 342rpx;
  112. border-radius: 16rpx;
  113. filter: blur(3rpx);
  114. opacity: 0.89;
  115. background: rgba(41, 41, 41, 0.4);
  116. border: 1rpx dashed #ccc;
  117. }
  118. .ii:active{
  119. transform: translateY(2rpx);
  120. transition: transform 0.1s ease;
  121. }
  122. .im{
  123. width: 626rpx;
  124. height: 342rpx;
  125. border-radius: 16rpx;
  126. overflow: hidden;
  127. }
  128. .is{
  129. width: 626rpx;
  130. height: 342rpx;
  131. border-radius: 4rpx !important;
  132. overflow: hidden;
  133. }
  134. .ic{
  135. width: 110rpx;
  136. height: 110rpx;
  137. position: absolute;
  138. top: calc(50% - 55rpx);
  139. left: calc(50% - 55rpx);
  140. }
  141. </style>