upload.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div class="preview">
  3. <span><i v-if="required">*</i>{{title}}</span>
  4. <input type="text" v-model="file.name" class="el-input__inner" :placeholder="placeholder">
  5. <input type="file" :accept="accept" @change="upload">
  6. <div class="close" @click="closeClick"><i class="el-icon-close"></i></div>
  7. <a v-if="fileData" class="download" @click="downFileData(fileData)"><i class="el-icon-download"></i></a>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. name: 'uploadView',
  13. props: ['title', 'required', 'placeholder', 'accept', 'fileData'],
  14. data () {
  15. return {
  16. file: ''
  17. }
  18. },
  19. methods: {
  20. downFileData (type) {
  21. window.open(type)
  22. },
  23. upload (e) {
  24. this.file = e.target.files[0]
  25. this.$emit('uploadEvent', e.target.files[0])
  26. },
  27. closeClick () {
  28. this.$emit('closeEvent', this.file)
  29. let _this = this
  30. setTimeout(() => {_this.file = ''}, 300)
  31. },
  32. }
  33. }
  34. </script>
  35. <style scoped type="text/scss" lang="scss">
  36. .preview{
  37. position:relative;
  38. display: inline-block;
  39. width:100%;
  40. margin-bottom:30px;
  41. vertical-align:middle;
  42. font-size: 14px;
  43. color:#333;
  44. height:28px;
  45. line-height: 28px;
  46. &:hover{
  47. .close{
  48. cursor:pointer;
  49. display:inline-block;
  50. }
  51. }
  52. .download{
  53. position:absolute;
  54. right:0;
  55. top:3px;
  56. width:22px;
  57. height:22px;
  58. line-height: 22px;
  59. font-size: 24px;
  60. font-weight: bold;
  61. text-align: center;
  62. }
  63. .close{
  64. display:none;
  65. position:absolute;
  66. right:5%;
  67. top:3px;
  68. width:22px;
  69. height:22px;
  70. line-height: 22px;
  71. font-size: 14px;
  72. font-weight: bold;
  73. border-radius:50%;
  74. background: #fff;
  75. border:1px solid #dcdfe6;
  76. color:#dcdfe6;
  77. text-align: center;
  78. }
  79. span{
  80. display:inline-block;
  81. vertical-align: top;
  82. width:25%;
  83. text-align: right;
  84. float:left;
  85. padding-right:10px;
  86. i{
  87. color: red;
  88. margin-right:5px;
  89. }
  90. }
  91. input[type=text]{
  92. height:28px;
  93. margin:0 5px;
  94. width:70%;
  95. }
  96. input[type=file]{
  97. position:absolute;
  98. top:0;
  99. left:0;
  100. opacity:0;
  101. width:90%;
  102. }
  103. }
  104. </style>