西藏巴青项目

index.vue 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <image
  3. v-if="realSrc"
  4. :src="realSrc"
  5. :mode="mode"
  6. :class="imgClass"
  7. :style="imgStyle"
  8. @click="onImageClick"
  9. @error="$emit('error', $event)"
  10. />
  11. </template>
  12. <script>
  13. import { resolveResourceUrl, resolveResourceUrlList } from '@/utils/resourceUrl'
  14. /**
  15. * 接口图片预览(对齐 ruoyi-ui/src/components/ImagePreview)
  16. * 相对路径自动拼接 BASE_API;H5 生产环境为当前浏览器 origin + /prod-api
  17. */
  18. export default {
  19. name: 'ImagePreview',
  20. props: {
  21. src: {
  22. type: String,
  23. default: ''
  24. },
  25. mode: {
  26. type: String,
  27. default: 'aspectFill'
  28. },
  29. width: {
  30. type: [Number, String],
  31. default: ''
  32. },
  33. height: {
  34. type: [Number, String],
  35. default: ''
  36. },
  37. preview: {
  38. type: Boolean,
  39. default: false
  40. },
  41. imgClass: {
  42. type: String,
  43. default: ''
  44. }
  45. },
  46. emits: ['error', 'click'],
  47. computed: {
  48. realSrc() {
  49. return resolveResourceUrl(this.src)
  50. },
  51. realSrcList() {
  52. return resolveResourceUrlList(this.src)
  53. },
  54. imgStyle() {
  55. const style = {}
  56. if (this.width !== '' && this.width != null) {
  57. style.width = typeof this.width === 'string' ? this.width : `${this.width}px`
  58. }
  59. if (this.height !== '' && this.height != null) {
  60. style.height = typeof this.height === 'string' ? this.height : `${this.height}px`
  61. }
  62. return style
  63. }
  64. },
  65. methods: {
  66. onImageClick(e) {
  67. this.$emit('click', e)
  68. if (!this.preview || !this.realSrcList.length) {
  69. return
  70. }
  71. uni.previewImage({
  72. urls: this.realSrcList,
  73. current: this.realSrc
  74. })
  75. }
  76. }
  77. }
  78. </script>