view.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <div class="basic-image">
  3. <template v-for="(image,index) in fileList" :key="index">
  4. <img-row :file="image"
  5. :config="config"
  6. @preview="handlePictureCardPreview"></img-row>
  7. </template>
  8. <el-dialog title="图片预览" v-model="dialogVisible">
  9. <Media style="width:100%" :type="config.mediaType" :src="dialogImageUrl" alt=""/>
  10. </el-dialog>
  11. </div>
  12. </template>
  13. <script>
  14. import { ref } from 'vue'
  15. import { formInputProps } from '../../form-input-props'
  16. import { ElDialog } from 'element-plus'
  17. import ImgRow from './img-row'
  18. import Media from './media'
  19. import { uploadProps } from '../file/upload'
  20. export default {
  21. props: formInputProps,
  22. components: { ElDialog, ImgRow, Media },
  23. emits: ['update:modelValue'],
  24. setup (props, context) {
  25. const { fileList } = uploadProps(props, context)
  26. const dialogImageUrl = ref('')
  27. const dialogVisible = ref(false)
  28. const handlePictureCardPreview = (file) => {
  29. dialogImageUrl.value = props.config.imgTemplate ? props.config.imgTemplate(file.url) : file.url
  30. dialogVisible.value = true
  31. }
  32. return {
  33. fileList,
  34. handlePictureCardPreview,
  35. dialogVisible,
  36. dialogImageUrl
  37. }
  38. }
  39. }
  40. </script>
  41. <style lang="less" scoped>
  42. .basic-image{
  43. .image-plus{
  44. background-color: #fbfdff;
  45. border: 1px dashed #c0ccda;
  46. border-radius: 6px;
  47. box-sizing: border-box;
  48. width: 148px;
  49. height: 148px;
  50. cursor: pointer;
  51. line-height: 146px;
  52. vertical-align: top;
  53. text-align: center;
  54. i{
  55. font-size: 28px;
  56. color: #8c939d;
  57. }
  58. &:hover{
  59. border: 1px dashed #409eff;
  60. }
  61. }
  62. .upload-plus{
  63. display: inline-block;
  64. vertical-align: top;
  65. }
  66. .dialog-image{
  67. display: block;
  68. max-height: 50vh;
  69. margin: 0 auto;
  70. }
  71. }
  72. </style>