| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <template>
- <div>
- <el-upload
- action="#"
- list-type="picture-card"
- :on-preview="handlePictureCardPreview"
- :on-remove="handleRemove"
- accept="image/png,image/jpeg,image/jpg"
- ref="uploadRef"
- :http-request="handlRequest"
- :before-upload="handlSuccess"
- :file-list="value"
- :multiple="true"
- >
- <i class="el-icon-plus"></i>
- </el-upload>
- <el-dialog :visible.sync="dialogVisible" append-to-body>
- <img width="100%" :src="dialogImageUrl" alt="" />
- </el-dialog>
- </div>
- </template>
- <script>
- import { uploadFile, removeFile } from '@/api/system/file/index.js';
- // import { getImageUrl } from '@/utils/file';
- export default {
- props: {
- value: {
- type: Object,
- default: () => []
- }
- },
- data() {
- return {
- dialogImageUrl: '',
- dialogVisible: false,
- fileList: []
- };
- },
- methods: {
- async handleRemove(file, fileList) {
- this.$emit('input', fileList);
- // if (!file.id) {
- // return;
- // }
- // await removeFile({ fileId: file.id });
- },
- handlePictureCardPreview(file) {
- this.dialogImageUrl = file.url;
- this.dialogVisible = true;
- },
- //图片添加
- async handlSuccess(file) {
- // console.log(params,'params')
- let res = await uploadFile({
- multiPartFile: file,
- module: 'main'
- });
- if (res?.data) {
- this.$emit('input', [...(this.value || []), res.data]);
- }
- },
- handlRequest() {
- return Promise.resolve();
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .img-view {
- width: 280px;
- height: 342px;
- display: flex;
- justify-content: center;
- align-items: center;
- border-width: 1px;
- border-style: solid;
- border-color: rgba(215, 215, 215, 1);
- img {
- max-width: 100%;
- max-height: 100%;
- }
- }
- .placeholder-box {
- width: 250px;
- height: 200px;
- text-align: center;
- background-color: rgba(242, 242, 242, 1);
- box-sizing: border-box;
- border-width: 1px;
- border-style: solid;
- border-color: rgba(215, 215, 215, 1);
- padding-top: 60px;
- img {
- width: 100px;
- height: 100px;
- }
- }
- .btn-box {
- display: flex;
- justify-content: space-around;
- }
- </style>
|