Commit 44cfaf49 authored by 吴冠's avatar 吴冠

pic

parent cf8465ff
<template> <template>
<div class="hello"> <div class="hello">
<el-upload <el-upload
:http-request="handleUpload" :http-request="handleUpload"
:on-preview="handlePreview" :on-preview="handlePreview"
:on-remove="handleRemove" :on-remove="handleRemove"
:on-success="handleSuccess" :on-success="handleSuccess"
:before-remove="beforeRemove" :before-remove="beforeRemove"
:limit="limit" :limit="limit"
:on-exceed="handleExceed" :on-exceed="handleExceed"
:file-list="fileList" :file-list="fileList"
:list-type="listType" :list-type="listType"
:accept="accept" :accept="accept"
class="upload-demo" class="upload-demo"
action action
multiple> multiple
<el-button size="small" type="primary">点击上传</el-button> >
<div slot="tip" class="el-upload__tip">{{ tip }}</div> <el-button size="small" type="primary">点击上传</el-button>
</el-upload> <div slot="tip" class="el-upload__tip">{{ tip }}</div>
</div> </el-upload>
</div>
</template> </template>
<script> <>
import { import { put, getFileNameUUID } from "~/api/ali-oss";
put,
getFileNameUUID
} from '~/api/ali-oss'
export default { export default {
name: 'Upload', name: "Upload",
props: { props: {
accept: { accept: {
type: String, type: String,
default: '.pdf,.jpg,.jpeg,.zip,.rar,.doc,.docx' default: ".pdf,.jpg,.jpeg,.zip,.rar,.doc,.docx",
},
tip: {
type: String,
default: "上传大小不能超过2M",
},
limit: {
type: Number,
default: 5,
},
action: {
type: String,
default: "",
},
headers: {
type: Object,
default: () => {},
},
name: {
type: String,
default: "",
},
listType: {
type: String,
default: "text",
},
max: {
type: Number,
default: 10,
},
fileList: {
type: Array,
default: () => [],
},
}, },
tip: { data() {
type: String, return {};
default: '上传大小不能超过2M'
}, },
limit: { methods: {
type: Number, emitInput(fileList) {
default: 5 let value = [];
for (let i = 0; i < fileList.length; i++) {
let message = {};
message.name = fileList[i].name;
message.url = fileList[i].url;
message.fileName = fileList[i].name;
message.fileUrl = fileList[i].url;
value.push(message);
}
this.$emit("input", value);
},
beforeUpload(file) {
const max = this.max;
const isLt2M = file.size / 1024 / 1024 < max;
if (!isLt2M) {
this.$message.error(`上传附件大小不能超过 ${max} MB!`);
}
return isLt2M;
},
handleRemove(file, fileList, index) {
this.$emit("on-remove", file, fileList);
this.fileList = fileList;
this.emitInput(fileList);
},
handlePreview(file) {
this.$emit("on-preview", file);
},
handleExceed(files, fileList) {
this.$message.warning(`每次只能上传 ${this.limit} 个文件`);
},
beforeRemove(file, fileList) {
return this.$confirm(`确定移除 ${file.name}?`);
},
handleSuccess(response, file, fileList) {
console.log("成功");
this.fileList = fileList;
this.$emit("on-success", file, fileList);
},
/**
* 自定义上传方法
*/
handleUpload(option) {
const max = this.max;
const isLt2M = option.file.size / 1024 / 1024 <script max;
if (isLt2M) {
// 生成的文件名称
let objName = getFileNameUUID();
// 调用 ali-oss 中的方法
put(`${objName}${option.file.name}`, option.file).then(
(res) => {
res.fileName = res.name;
res.fileUrl = res.url;
this.fileList.push(res);
this.emitInput(this.fileList);
}
);
}
},
}, },
action: { };
type: String,
default: ''
},
headers: {
type: Object,
default: () => {}
},
name: {
type: String,
default: ''
},
listType: {
type: String,
default: 'text'
},
max: {
type: Number,
default: 10
},
fileList:{
type: Array,
default: () => []
},
},
data() {
return {
}
},
methods: {
emitInput(fileList) {
let value = []
for (let i = 0; i < fileList.length; i++) {
let message = {}
message.fileName = fileList[i].name
message.fileUrl = fileList[i].url
value.push(message)
}
this.$emit('input', value)
},
beforeUpload(file) {
const max = this.max
const isLt2M = file.size / 1024 / 1024 < max
if (!isLt2M) {
this.$message.error(`上传附件大小不能超过 ${max} MB!`)
}
return isLt2M
},
handleRemove(file, fileList, index) {
this.$emit('on-remove', file, fileList)
this.fileList = fileList
this.emitInput(fileList)
},
handlePreview(file) {
this.$emit('on-preview', file)
},
handleExceed(files, fileList) {
this.$message.warning(`每次只能上传 ${this.limit} 个文件`)
},
beforeRemove(file, fileList) {
return this.$confirm(`确定移除 ${file.name}?`)
},
handleSuccess(response, file, fileList) {
console.log('成功')
this.fileList = fileList
this.$emit('on-success', file, fileList)
},
/**
* 自定义上传方法
*/
handleUpload(option) {
const max = this.max
const isLt2M = option.file.size / 1024 / 1024 < max
if (isLt2M) {
// 生成的文件名称
let objName = getFileNameUUID()
// 调用 ali-oss 中的方法
put(`${objName}${option.file.name}`, option.file).then(res => {
res.fileName = res.name
res.fileUrl = res.url
this.fileList.push(res)
this.emitInput(this.fileList)
})
}
}
}
}
</script> </script>
<!-- Add "scoped" attribute to limit CSS to this component only --> <!-- Add "scoped" attribute to limit CSS to this component only -->
......
<template> <template>
<div> <div>
<div v-show="!dialogVisible"> <div v-show="!dialogVisible">
<el-upload <el-upload
:http-request="handleUpload" :http-request="handleUpload"
:on-preview="handlePictureCardPreview" :on-preview="handlePictureCardPreview"
:on-remove="handleRemove" :on-remove="handleRemove"
:on-exceed="handleExceed" :on-exceed="handleExceed"
:on-success="handleSuccess" :on-success="handleSuccess"
:before-upload="beforeUpload" :before-upload="beforeUpload"
:before-remove="beforeRemove" :before-remove="beforeRemove"
:file-list="fileList" :file-list="fileList"
:limit="limit" :limit="limit"
accept=".jpg, .jpeg, .png, .gif" accept=".jpg, .jpeg, .png, .gif"
action action
list-type="picture-card"> list-type="picture-card"
<i class="el-icon-plus" v-if="!dialogVisible"></i> >
<div slot="tip" class="el-upload__tip">{{ tip }}</div> <i class="el-icon-plus" v-if="!dialogVisible"></i>
</el-upload> <div slot="tip" class="el-upload__tip">{{ tip }}</div>
</el-upload>
</div>
<el-dialog :visible.sync="dialogVisible">
<img :src="dialogImageUrl" width="100%" alt="" />
</el-dialog>
</div> </div>
<el-dialog :visible.sync="dialogVisible">
<img :src="dialogImageUrl" width="100%" alt="">
</el-dialog>
</div>
</template> </template>
<script> <script>
import { import { put, getFileNameUUID } from "~/api/ali-oss";
put,
getFileNameUUID
} from '~/api/ali-oss'
export default { export default {
props: { props: {
tip: { tip: {
type: String, type: String,
default: '上传大小不能超过10M' default: "上传大小不能超过10M",
},
limit: {
type: Number,
default: 3,
},
max: {
type: Number,
default: 10,
},
fileList: {
type: Array,
default: () => [],
},
}, },
limit: { data() {
type: Number, return {
default: 3 dialogImageUrl: "",
}, dialogVisible: false,
max: { };
type: Number,
default: 10
},
fileList:{
type: Array,
default: () => []
},
},
data() {
return {
dialogImageUrl: '',
dialogVisible: false,
}
},
methods: {
beforeUpload(file) {
const max = this.max
const isLt2M = file.size / 1024 / 1024 < max
if (!isLt2M) {
this.$message.error(`上传附件大小不能超过 ${max} MB!`)
}
return isLt2M
},
emitInput(fileList) {
let value = []
for (let i = 0; i < fileList.length; i++) {
let message = {}
message.fileName = fileList[i].name
message.fileUrl = fileList[i].url
value.push(message)
}
this.$emit('input', value)
},
handleExceed(files, fileList) {
this.$message.warning(`每次只能上传 ${this.limit} 个文件`)
}, },
methods: {
beforeUpload(file) {
const max = this.max;
const isLt2M = file.size / 1024 / 1024 < max;
if (!isLt2M) {
this.$message.error(`上传附件大小不能超过 ${max} MB!`);
}
return isLt2M;
},
emitInput(fileList) {
let value = [];
for (let i = 0; i < fileList.length; i++) {
let message = {};
message.name = fileList[i].name;
message.url = fileList[i].url;
message.fileName = fileList[i].name;
message.fileUrl = fileList[i].url;
value.push(message);
}
this.$emit("input", value);
},
handleExceed(files, fileList) {
this.$message.warning(`每次只能上传 ${this.limit} 个文件`);
},
beforeRemove(file, fileList) { beforeRemove(file, fileList) {
return this.$confirm(`确定移除 ${file.name}?`) return this.$confirm(`确定移除 ${file.name}?`);
}, },
handlePictureCardPreview(file) { handlePictureCardPreview(file) {
this.dialogImageUrl = file.url this.dialogImageUrl = file.url;
this.dialogVisible = true this.dialogVisible = true;
}, },
handleRemove(file, fileList) { handleRemove(file, fileList) {
this.fileList = fileList this.fileList = fileList;
this.emitInput(fileList) this.emitInput(fileList);
}, },
handleSuccess(response, file, fileList) { handleSuccess(response, file, fileList) {
console.log('成功') console.log("成功");
this.fileList = fileList this.fileList = fileList;
this.$emit('on-success', file, fileList) this.$emit("on-success", file, fileList);
},
handleUpload(option) {
const max = this.max;
const isLt2M = option.file.size / 1024 / 1024 < max;
if (isLt2M) {
// 生成的文件名称
let objName = getFileNameUUID();
// 调用 ali-oss 中的方法
put(`${objName}${option.file.name}`, option.file).then(
(res) => {
res.fileName = res.name;
res.fileUrl = res.url;
this.fileList.push(res);
this.emitInput(this.fileList);
}
);
}
},
}, },
handleUpload(option) { };
const max = this.max
const isLt2M = option.file.size / 1024 / 1024 < max
if (isLt2M) {
// 生成的文件名称
let objName = getFileNameUUID()
// 调用 ali-oss 中的方法
put(`${objName}${option.file.name}`, option.file).then(res => {
res.fileName = res.name
res.fileUrl = res.url
this.fileList.push(res)
this.emitInput(this.fileList)
})
}
}
}
}
</script> </script>
...@@ -820,7 +820,7 @@ export default { ...@@ -820,7 +820,7 @@ export default {
fileList: [], fileList: [],
flag: true, //该值变化,就会触发刷新 flag: true, //该值变化,就会触发刷新
code: "", //刷新后的验证码 code: "", //刷新后的验证码
active: 0, active: 1,
checked: true, checked: true,
adminform: { adminform: {
name: "", name: "",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment