index.vue 1.5 KB
Newer Older
1
<template>
2
  <el-drawer v-model="drawer" title="媒体库">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
3
    <div class="media">
4 5 6
      <el-image
        v-for="(item,key) in picList"
        :key="key"
何秀钢 已提交
7 8
        class="header-img-box-list"
        :src="(item.url && item.url.slice(0, 4) !== 'http')?path+item.url:item.url"
9
        @click="chooseImg(item.url,target,targetKey)"
10
      >
11 12
        <template #error>
          <div class="header-img-box-list">
P
piexlmax 已提交
13
            <el-icon><picture /></el-icon>
14 15
          </div>
        </template>
16 17 18 19 20 21
      </el-image>
    </div>
  </el-drawer>
</template>

<script>
Mr.奇淼('s avatar
Mr.奇淼( 已提交
22
const path = import.meta.env.VITE_BASE_API
何秀钢 已提交
23
import { getFileList } from '@/api/fileUploadAndDownload'
24 25
export default {
  props: {
何秀钢 已提交
26 27 28 29 30 31 32 33
    target: {
      type: Object,
      default: null
    },
    targetKey: {
      type: String,
      default: ''
    }
34 35 36 37
  },
  data() {
    return {
      drawer: false,
38
      picList: [],
何秀钢 已提交
39 40
      path: path
    }
41 42 43
  },
  methods: {
    chooseImg(url, target, targetKey) {
何秀钢 已提交
44 45
      if (target && targetKey) {
        target[targetKey] = url
46
      }
何秀钢 已提交
47 48
      this.$emit('enter-img', url)
      this.drawer = false
49 50
    },
    async open() {
何秀钢 已提交
51 52 53
      const res = await getFileList({ page: 1, pageSize: 9999 })
      this.picList = res.data.list
      this.drawer = true
54 55
    }
  }
何秀钢 已提交
56
}
57 58 59
</script>

<style lang="scss">
Mr.奇淼('s avatar
Mr.奇淼( 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72
.media{
  display:flex;
  flex-wrap:wrap;
  .header-img-box-list {
    margin-top: 20px;
    width: 120px;
    margin-left: 20px;
    height: 120px;
    border: 1px dashed #ccc;
    border-radius: 20px;
    text-align: center;
    line-height: 180px;
    cursor: pointer;
73
}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
74 75
}

何秀钢 已提交
76
</style>