image-element.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <message-bubble :isMine=isMine :message=message>
  3. <!-- el-image在IE下会自动加上用于兼容object-fit的类,该类的样式在没设置图片宽高是会 GG -->
  4. <img class="image-element" :src="imageUrl" @load="onImageLoaded" @click="handlePreview" />
  5. <el-progress
  6. v-if="showProgressBar"
  7. :percentage="percentage"
  8. :color="percentage => (percentage === 100 ? '#67c23a' : '#409eff')"
  9. />
  10. </message-bubble>
  11. </template>
  12. <script>
  13. import MessageBubble from '../message-bubble'
  14. import { Progress } from 'element-ui'
  15. import { mapGetters } from 'vuex'
  16. export default {
  17. name: 'ImageElemnt',
  18. props: {
  19. payload: {
  20. type: Object,
  21. required: true
  22. },
  23. message: {
  24. type: Object,
  25. required: true
  26. },
  27. isMine: {
  28. type: Boolean
  29. }
  30. },
  31. components: {
  32. MessageBubble,
  33. ElProgress: Progress
  34. },
  35. computed: {
  36. ...mapGetters(['imgUrlList']),
  37. imageUrl() {
  38. console.log("this.payload",this.payload)
  39. const url = this.payload.sourcePicture.url
  40. if (typeof url !== 'string') {
  41. return ''
  42. }
  43. return url.slice(0, 2) === '//' ? `https:${url}` : url
  44. },
  45. showProgressBar() {
  46. return this.$parent.message.status === 'unSend'
  47. },
  48. percentage() {
  49. return Math.floor((this.$parent.message.progress || 0) * 100)
  50. }
  51. },
  52. methods: {
  53. onImageLoaded(event) {
  54. this.$bus.$emit('image-loaded', event)
  55. },
  56. handlePreview() {
  57. this.$bus.$emit('image-preview', {
  58. url: this.payload.sourcePicture.url
  59. })
  60. }
  61. }
  62. }
  63. </script>
  64. <style lang="stylus" scoped>
  65. .image-element
  66. max-width 250px
  67. cursor zoom-in
  68. </style>