filePreview.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div class="preview-wrap">
  3. <div class="preview-hd">{{fileInfo && fileInfo.type==1?$t('chat.imageComfirm'):$t('chat.videoComfirm')}}:</div>
  4. <div class="preview-bd">
  5. <img :src="this.fileInfo && this.fileInfo.preview" v-if="fileInfo && fileInfo.type==1">
  6. <video v-if="fileInfo && (fileInfo.type==2 || fileInfo.type==3)" controls
  7. :src="this.fileInfo && this.fileInfo.preview"
  8. :class="[{'ext-audio':fileInfo.type==3}]"></video>
  9. </div>
  10. <div class="preview-ft">
  11. <el-button @click="closeFilePreview">{{$t('public.cancel')}}</el-button>
  12. <el-button type="primary" @click="handleFileSend">{{$t('public.confirm')}}</el-button>
  13. </div>
  14. </div>
  15. </template>
  16. <script>
  17. import Vue from 'vue'
  18. import { Button } from 'element-ui'
  19. Vue.component(Button.name, Button)
  20. export default {
  21. props: {
  22. fileInfo: Object
  23. },
  24. computed: {
  25. previewUrl () {
  26. if (!this.fileInfo) return ''
  27. if (this.fileInfo.type == 1) {
  28. return this.fileInfo.preview
  29. } else {
  30. return window.webkitURL.createObjectURL(this.fileInfo.res)
  31. }
  32. }
  33. },
  34. methods: {
  35. closeFilePreview () {
  36. this.$emit('closeFilePreview')
  37. },
  38. handleFileSend () {
  39. this.$emit('handleFileSend', this.fileInfo)
  40. }
  41. }
  42. }
  43. </script>
  44. <style lang="scss" scoped>
  45. .preview-wrap {
  46. position: absolute;
  47. top: -10px;
  48. left: 4px;
  49. transform: translateY(-100%);
  50. padding: 0 10px;
  51. border-radius: 4px;
  52. border: 1px solid #d6d6d6;
  53. background-color: #ffffff;
  54. box-shadow: 0px 1px 5px 1px #cdcdcd;
  55. }
  56. .preview-hd{
  57. line-height: 36px;
  58. font-size: 14px;
  59. color: #333;
  60. }
  61. .preview-bd {
  62. position: relative;
  63. text-align: center;
  64. min-width: 200px;
  65. min-height: 100px;
  66. border-radius: 2px;
  67. display: flex;
  68. align-items: center;
  69. justify-content: center;
  70. &::after{
  71. content: '';
  72. display: inline-block;
  73. height: 100%;
  74. vertical-align: middle;
  75. }
  76. img{
  77. max-width: 280px;
  78. max-height: 280px;
  79. }
  80. video{
  81. border: 0;
  82. max-width: 280px;
  83. max-height: 280px;
  84. &:focus{
  85. outline: none;
  86. }
  87. &.ext-audio{
  88. height: 50px;
  89. width: 200px;
  90. }
  91. }
  92. }
  93. .preview-ft {
  94. text-align: right;
  95. line-height: 44px;
  96. }
  97. </style>