UploadAudio.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <div class="com-upload-audio" @click="onSelect">
  3. <div>
  4. <upload ref="uploadFile" media-type="audio" @file-change="onFileChange"></upload>
  5. <div class="btn-push" v-show="!filename">
  6. <i class="iconfont icon_plus"></i>
  7. <span>{{tips}}</span>
  8. </div>
  9. <div class="filename" v-show="filename"><span>{{filename}}</span></div>
  10. <button class="ui-button submit" v-show="filename">{{$t('common.change')}}</button>
  11. <a class="btn-clear" v-show="filename" @click.stop="onClear">
  12. <i class="iconfont icon-close"></i>
  13. </a>
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. import Upload from "./Upload";
  19. export default {
  20. name: "UploadAudio",
  21. components: {
  22. Upload
  23. },
  24. props: {
  25. name:String,
  26. tips: String,
  27. clear: Boolean
  28. },
  29. data() {
  30. return {
  31. isClear: false,
  32. dataURL: "",
  33. fileName: ""
  34. };
  35. },
  36. computed:{
  37. filename(){
  38. if(this.isClear){
  39. return null
  40. }
  41. return this.fileName || this.name
  42. }
  43. },
  44. methods: {
  45. onSelect() {
  46. this.$refs.uploadFile.click();
  47. },
  48. onClear() {
  49. this.$refs.uploadFile.clear();
  50. this.isClear = true
  51. this.dataURL = "";
  52. this.fileName = "";
  53. this.$emit("file-change", null);
  54. },
  55. onFileChange(file) {
  56. this.isClear = false
  57. this.dataURL = file.dataURL;
  58. this.fileName = file.name;
  59. this.$emit("file-change", file);
  60. }
  61. }
  62. };
  63. </script>
  64. <style lang="less" scoped>
  65. .com-upload-audio {
  66. cursor: pointer;
  67. display: inline-block;
  68. min-width: 60px;
  69. min-height: 60px;
  70. width: 100%;
  71. height: 100%;
  72. border-radius: 2px;
  73. border: 1px solid #5d5d5d;
  74. position: relative;
  75. background: #414141;
  76. background-position: center center;
  77. background-size: cover;
  78. &:hover {
  79. > div {
  80. background-color: rgba(0, 0, 0, 0.5);
  81. }
  82. .ui-button {
  83. display: block;
  84. }
  85. .btn-clear {
  86. display: block;
  87. }
  88. }
  89. > div {
  90. position: relative;
  91. display: flex;
  92. width: 100%;
  93. height: 100%;
  94. align-items: center;
  95. justify-content: center;
  96. flex-direction: column;
  97. font-size: 12px;
  98. color: @color;
  99. }
  100. .filename {
  101. padding: 10px;
  102. width: 100%;
  103. height: 100%;
  104. display: flex;
  105. align-items: center;
  106. span {
  107. max-height: 100%;
  108. overflow: hidden;
  109. white-space: normal;
  110. word-break: break-all;
  111. }
  112. }
  113. .icon_plus {
  114. font-size: 28px;
  115. }
  116. .icon-close {
  117. color: #fff;
  118. font-size: 12px;
  119. }
  120. .ui-button {
  121. width: 60px;
  122. display: none;
  123. position: absolute;
  124. left: 50%;
  125. top: 50%;
  126. transform: translate(-50%, -50%);
  127. }
  128. .btn-push {
  129. text-align: center;
  130. span {
  131. display: block;
  132. }
  133. }
  134. .btn-clear {
  135. display: none;
  136. position: absolute;
  137. right: 0;
  138. top: 0;
  139. width: 20px;
  140. height: 20px;
  141. line-height: 20px;
  142. text-align: center;
  143. background-color: #c77a7a;
  144. border-radius: 50%;
  145. transform: translate(50%, -50%);
  146. &:hover {
  147. background-color: #e85353;
  148. }
  149. }
  150. }
  151. </style>