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

pic

parent cf8465ff
......@@ -13,122 +13,122 @@
:accept="accept"
class="upload-demo"
action
multiple>
multiple
>
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">{{ tip }}</div>
</el-upload>
</div>
</template>
<script>
import {
put,
getFileNameUUID
} from '~/api/ali-oss'
<>
import { put, getFileNameUUID } from "~/api/ali-oss";
export default {
name: 'Upload',
name: "Upload",
props: {
accept: {
type: String,
default: '.pdf,.jpg,.jpeg,.zip,.rar,.doc,.docx'
default: ".pdf,.jpg,.jpeg,.zip,.rar,.doc,.docx",
},
tip: {
type: String,
default: '上传大小不能超过2M'
default: "上传大小不能超过2M",
},
limit: {
type: Number,
default: 5
default: 5,
},
action: {
type: String,
default: ''
default: "",
},
headers: {
type: Object,
default: () => {}
default: () => {},
},
name: {
type: String,
default: ''
default: "",
},
listType: {
type: String,
default: 'text'
default: "text",
},
max: {
type: Number,
default: 10
default: 10,
},
fileList:{
fileList: {
type: Array,
default: () => []
default: () => [],
},
},
data() {
return {
}
return {};
},
methods: {
emitInput(fileList) {
let value = []
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)
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)
this.$emit("input", value);
},
beforeUpload(file) {
const max = this.max
const isLt2M = file.size / 1024 / 1024 < max
const max = this.max;
const isLt2M = file.size / 1024 / 1024 < max;
if (!isLt2M) {
this.$message.error(`上传附件大小不能超过 ${max} MB!`)
this.$message.error(`上传附件大小不能超过 ${max} MB!`);
}
return isLt2M
return isLt2M;
},
handleRemove(file, fileList, index) {
this.$emit('on-remove', file, fileList)
this.fileList = fileList
this.emitInput(fileList)
this.$emit("on-remove", file, fileList);
this.fileList = fileList;
this.emitInput(fileList);
},
handlePreview(file) {
this.$emit('on-preview', file)
this.$emit("on-preview", file);
},
handleExceed(files, fileList) {
this.$message.warning(`每次只能上传 ${this.limit} 个文件`)
this.$message.warning(`每次只能上传 ${this.limit} 个文件`);
},
beforeRemove(file, fileList) {
return this.$confirm(`确定移除 ${file.name}?`)
return this.$confirm(`确定移除 ${file.name}?`);
},
handleSuccess(response, file, fileList) {
console.log('成功')
this.fileList = fileList
this.$emit('on-success', 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
const max = this.max;
const isLt2M = option.file.size / 1024 / 1024 <script max;
if (isLt2M) {
// 生成的文件名称
let objName = getFileNameUUID()
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)
})
}
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>
<!-- Add "scoped" attribute to limit CSS to this component only -->
......
......@@ -13,102 +13,104 @@
:limit="limit"
accept=".jpg, .jpeg, .png, .gif"
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>
</el-upload>
</div>
<el-dialog :visible.sync="dialogVisible">
<img :src="dialogImageUrl" width="100%" alt="">
<img :src="dialogImageUrl" width="100%" alt="" />
</el-dialog>
</div>
</template>
<script>
import {
put,
getFileNameUUID
} from '~/api/ali-oss'
import { put, getFileNameUUID } from "~/api/ali-oss";
export default {
props: {
tip: {
type: String,
default: '上传大小不能超过10M'
default: "上传大小不能超过10M",
},
limit: {
type: Number,
default: 3
default: 3,
},
max: {
type: Number,
default: 10
default: 10,
},
fileList:{
fileList: {
type: Array,
default: () => []
default: () => [],
},
},
data() {
return {
dialogImageUrl: '',
dialogImageUrl: "",
dialogVisible: false,
}
};
},
methods: {
beforeUpload(file) {
const max = this.max
const isLt2M = file.size / 1024 / 1024 < max
const max = this.max;
const isLt2M = file.size / 1024 / 1024 < max;
if (!isLt2M) {
this.$message.error(`上传附件大小不能超过 ${max} MB!`)
this.$message.error(`上传附件大小不能超过 ${max} MB!`);
}
return isLt2M
return isLt2M;
},
emitInput(fileList) {
let value = []
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)
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)
this.$emit("input", value);
},
handleExceed(files, fileList) {
this.$message.warning(`每次只能上传 ${this.limit} 个文件`)
this.$message.warning(`每次只能上传 ${this.limit} 个文件`);
},
beforeRemove(file, fileList) {
return this.$confirm(`确定移除 ${file.name}?`)
return this.$confirm(`确定移除 ${file.name}?`);
},
handlePictureCardPreview(file) {
this.dialogImageUrl = file.url
this.dialogVisible = true
this.dialogImageUrl = file.url;
this.dialogVisible = true;
},
handleRemove(file, fileList) {
this.fileList = fileList
this.emitInput(fileList)
this.fileList = fileList;
this.emitInput(fileList);
},
handleSuccess(response, file, fileList) {
console.log('成功')
this.fileList = fileList
this.$emit('on-success', 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
const max = this.max;
const isLt2M = option.file.size / 1024 / 1024 < max;
if (isLt2M) {
// 生成的文件名称
let objName = getFileNameUUID()
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)
})
}
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>
......@@ -820,7 +820,7 @@ export default {
fileList: [],
flag: true, //该值变化,就会触发刷新
code: "", //刷新后的验证码
active: 0,
active: 1,
checked: true,
adminform: {
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