7 changed files with 889 additions and 274 deletions
@ -1,222 +1,232 @@ |
|||||
<template> |
<template> |
||||
<div> |
<div> |
||||
<el-upload ref="imgUpload" v-loading="loadding" class="avatar-uploader" :headers="accessToken" :action="uploadFile" :accept="accept" list-type="picture-card" :limit="limit" :file-list="files" :on-remove="removeImage" :on-preview="handlePictureCardPreview" :on-progress="uploadProgrees" :on-error="uploadError" :on-success="uploadImgSuccess_FuJian"> |
<el-upload ref="imgUpload" v-loading="loadding" class="avatar-uploader" :headers="accessToken" :action="uploadFile" |
||||
<i class="el-icon-plus avatar-uploader-icon"/> |
:accept="accept" list-type="picture-card" :limit="limit" :file-list="files" :on-remove="removeImage" |
||||
|
:on-preview="handlePictureCardPreview" :on-progress="uploadProgrees" :on-error="uploadError" |
||||
|
:on-success="uploadImgSuccess_FuJian"> |
||||
|
<i class="el-icon-plus avatar-uploader-icon" /> |
||||
</el-upload> |
</el-upload> |
||||
<el-dialog :visible.sync="dialogVisible" title="查看图片"> |
<el-dialog :visible.sync="dialogVisible" title="查看图片"> |
||||
<img width="100%" :src="dialogImageUrl" alt=""> |
<img width="100%" :src="dialogImageUrl" alt=""> |
||||
</el-dialog> |
</el-dialog> |
||||
</div> |
</div> |
||||
</template> |
</template> |
||||
|
|
||||
<script> |
<script> |
||||
import { uploadFile_yanchejiancha } from '@/api/portal/Upload' |
import { |
||||
import { getStorage } from '@/utils/auth.js' |
uploadFile_yanchejiancha |
||||
|
} from '@/api/portal/Upload' |
||||
|
import { |
||||
|
getStorage |
||||
|
} from '@/utils/auth.js' |
||||
|
import { |
||||
|
uploadFile |
||||
|
} from '@/api/portal/Upload' |
||||
|
|
||||
export default { |
export default { |
||||
model: { |
model: { |
||||
prop: 'name', |
prop: 'name', |
||||
event: 'change' |
event: 'change' |
||||
}, |
}, |
||||
props: { |
props: { |
||||
placeholder: { |
placeholder: { |
||||
type: String, |
type: String, |
||||
default: '' |
default: '' |
||||
}, |
}, |
||||
bucket: { |
bucket: { |
||||
type: String, |
type: String, |
||||
default: 'abc' |
default: 'abc' |
||||
}, |
}, |
||||
// 长度 |
// 长度 |
||||
width: { |
width: { |
||||
type: String, |
type: String, |
||||
default: '270px' |
default: '270px' |
||||
}, |
}, |
||||
limit: { |
limit: { |
||||
type: Number, |
type: Number, |
||||
default: '' |
default: '' |
||||
}, |
}, |
||||
accept: { |
accept: { |
||||
type: String, |
type: String, |
||||
default: '.jpg,.jpeg,.png,.JPG,.JPEG,' |
default: '.jpg,.jpeg,.png,.JPG,.JPEG,' |
||||
}, |
}, |
||||
// 文件名称 |
// 文件名称 |
||||
name: { |
name: { |
||||
type: Array, |
type: Array, |
||||
required: true |
required: true |
||||
}, |
}, |
||||
uploadData: { |
uploadData: { |
||||
type: Object, |
type: Object, |
||||
default: {} |
default: {} |
||||
} |
|
||||
}, |
|
||||
data() { |
|
||||
return { |
|
||||
dialogImageUrl: '', |
|
||||
dialogVisible: false, |
|
||||
accessToken: null, |
|
||||
uploadFile: uploadFile_yanchejiancha, |
|
||||
fileList_FuJian: [], |
|
||||
enclosure: '', |
|
||||
file_add: '', |
|
||||
file_catch: '', |
|
||||
files: [], |
|
||||
files_list: [], |
|
||||
filedUrl: '', |
|
||||
// fileUrl: fileUrl, |
|
||||
// showpicture:false, |
|
||||
isview: false, |
|
||||
nameArr: '', |
|
||||
loadding: false |
|
||||
} |
|
||||
}, |
|
||||
watch: { |
|
||||
name: { |
|
||||
deep: true, |
|
||||
immediate: true, |
|
||||
handler(newVal, oldVal) { |
|
||||
console.log('aaaa1', newVal) |
|
||||
this.files = newVal |
|
||||
console.log('aaaa2', this.files) |
|
||||
} |
} |
||||
} |
|
||||
}, |
|
||||
mounted() { |
|
||||
this.$nextTick(() => { |
|
||||
this.Init() |
|
||||
}) |
|
||||
}, |
|
||||
created() { |
|
||||
this.uploadFile = uploadFile_yanchejiancha // 接口 |
|
||||
this.accessToken = { |
|
||||
token: getStorage() |
|
||||
} |
|
||||
}, |
|
||||
methods: { |
|
||||
showImg(imgList) { |
|
||||
this.files = imgList |
|
||||
console.log('123123123', this.files) |
|
||||
}, |
|
||||
view() { |
|
||||
// window.open(this.filedUrl) |
|
||||
}, |
}, |
||||
// 页面第一次加载 |
data() { |
||||
Init() { |
return { |
||||
if (this.name !== undefined) { |
dialogImageUrl: '', |
||||
this.files = [] |
dialogVisible: false, |
||||
for (var i = 0; i < this.name.length; i++) { |
accessToken: null, |
||||
this.files.push({ |
uploadFile: uploadFile, |
||||
name: this.name[i], |
fileList_FuJian: [], |
||||
url: this.name[i] |
enclosure: '', |
||||
}) |
file_add: '', |
||||
} |
file_catch: '', |
||||
|
files: [], |
||||
|
files_list: [], |
||||
|
filedUrl: '', |
||||
|
// fileUrl: fileUrl, |
||||
|
// showpicture:false, |
||||
|
isview: false, |
||||
|
nameArr: '', |
||||
|
loadding: false |
||||
} |
} |
||||
}, |
}, |
||||
handlePictureCardPreview(file) { |
watch: { |
||||
this.dialogVisible = true |
name: { |
||||
this.dialogImageUrl = file.url |
deep: true, |
||||
}, |
immediate: true, |
||||
// 上传方案--成功后执行 |
handler(newVal, oldVal) { |
||||
uploadImgSuccess_FuJian(response, file, fileList) { |
console.log('aaaa1', newVal) |
||||
console.log('您选择的file:', file) |
this.files = newVal |
||||
if (file.response.code === '200') { |
console.log('aaaa2', this.files) |
||||
this.loadding = false |
} |
||||
// 返显图片 |
|
||||
this.filedUrl = this.fileUrl + file.response.data |
|
||||
// var uid = file.response.data |
|
||||
this.files.push({ |
|
||||
name: file.response.data.sourceFileName, |
|
||||
url: file.response.data.fullUrl, |
|
||||
size: file.response.data.size |
|
||||
}) |
|
||||
this.$emit('change', this.files) |
|
||||
this.$emit('eett', this.files) |
|
||||
} |
} |
||||
}, |
}, |
||||
|
mounted() { |
||||
removeImage(file, ImageFileList) { |
this.$nextTick(() => { |
||||
this.files.splice(this.files.indexOf(file), 1) |
this.Init() |
||||
const imgFiles = [] |
|
||||
this.files.forEach((o) => { |
|
||||
imgFiles.push(o.url) |
|
||||
}) |
}) |
||||
this.$emit('fileChange', this.files) |
|
||||
}, |
}, |
||||
handleRemove(file, fileList) { |
created() { |
||||
console.log('file:' + JSON.stringify(file)) |
this.uploadFile = uploadFile // 接口 |
||||
console.log('fileList:' + JSON.stringify(fileList)) |
this.accessToken = { |
||||
this.enclosure = '' |
token: getStorage() |
||||
// 1. 保存新增文件id(this.file_add) |
|
||||
this.getNewFileId(fileList) |
|
||||
// 2. 保存数据库读取的已有文件id(this.file_catch) |
|
||||
this.getCatchFileId(file) |
|
||||
// 3. 保存并拼接id |
|
||||
this.getFileId() |
|
||||
// 4. 返回拼接id |
|
||||
this.$emit('change', this.enclosure) |
|
||||
}, |
|
||||
// 返回this.file_add(新上传文件的id拼接集合) |
|
||||
getNewFileId(fileList) { |
|
||||
// debugger |
|
||||
this.file_add = '' |
|
||||
for (var i = 0; i < fileList.length; i++) { |
|
||||
if (fileList[i].response && fileList[i].response.code === '200') { |
|
||||
this.file_add = this.file_add + fileList[i].response.data + ',' |
|
||||
} |
|
||||
} |
} |
||||
if (this.file_add !== '') { |
|
||||
this.file_add = this.file_add.substring(0, this.file_add.length - 1) |
|
||||
} |
|
||||
// console.log('1. this.file_add: ' + this.file_add) |
|
||||
}, |
}, |
||||
// 返回this.file_catch(数库一寸照的文件的id的拼接集合) |
methods: { |
||||
getCatchFileId(file) { |
showImg(imgList) { |
||||
for (var i = 0; i < this.files_list.length; i++) { |
this.files = imgList |
||||
if (this.file_catch !== '') { |
console.log('123123123', this.files) |
||||
// 1. 检查当前删除的文件是否是修改文件列表里面的,如果是,将修改列表里去除此id |
}, |
||||
if (this.files_list[i].name === file.name) { |
view() { |
||||
// 2. 拆开file_catch到fils_arry |
// window.open(this.filedUrl) |
||||
var fils_arry = this.file_catch.split(',') |
}, |
||||
// 3. 从fils_arry去除 this.files_list[i].id |
// 页面第一次加载 |
||||
var arry = [] |
Init() { |
||||
fils_arry.forEach((element) => { |
if (this.name !== undefined) { |
||||
// 不加载文件里面的 |
this.files = [] |
||||
if (element !== this.files_list[i].id) { |
for (var i = 0; i < this.name.length; i++) { |
||||
arry.push(element) |
this.files.push({ |
||||
} |
name: this.name[i], |
||||
|
url: this.name[i] |
||||
}) |
}) |
||||
// 4. 重新拼接成file_catch |
|
||||
this.file_catch = arry.join(',') |
|
||||
} |
} |
||||
} |
} |
||||
} |
}, |
||||
// console.log('2. this.file_catch:' + this.file_catch) |
handlePictureCardPreview(file) { |
||||
}, |
this.dialogVisible = true |
||||
// 保存并拼接id |
this.dialogImageUrl = file.url |
||||
getFileId() { |
}, |
||||
// console.log('3. this.file_catch:' + this.file_catch + ',this.file_add:' + this.file_add) |
// 上传方案--成功后执行 |
||||
if (this.file_catch !== '') { |
uploadImgSuccess_FuJian(response, file, fileList) { |
||||
|
console.log('您选择的file:', file) |
||||
|
if (file.response.code === '200') { |
||||
|
this.loadding = false |
||||
|
// 返显图片 |
||||
|
this.filedUrl = this.fileUrl + file.response.data |
||||
|
// var uid = file.response.data |
||||
|
this.files.push({ |
||||
|
name: file.response.data.sourceFileName, |
||||
|
url: file.response.data.fullUrl, |
||||
|
size: file.response.data.size |
||||
|
}) |
||||
|
this.$emit('change', this.files) |
||||
|
this.$emit('eett', this.files) |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
removeImage(file, ImageFileList) { |
||||
|
this.files.splice(this.files.indexOf(file), 1) |
||||
|
const imgFiles = [] |
||||
|
this.files.forEach((o) => { |
||||
|
imgFiles.push(o.url) |
||||
|
}) |
||||
|
this.$emit('fileChange', this.files) |
||||
|
}, |
||||
|
handleRemove(file, fileList) { |
||||
|
console.log('file:' + JSON.stringify(file)) |
||||
|
console.log('fileList:' + JSON.stringify(fileList)) |
||||
|
this.enclosure = '' |
||||
|
// 1. 保存新增文件id(this.file_add) |
||||
|
this.getNewFileId(fileList) |
||||
|
// 2. 保存数据库读取的已有文件id(this.file_catch) |
||||
|
this.getCatchFileId(file) |
||||
|
// 3. 保存并拼接id |
||||
|
this.getFileId() |
||||
|
// 4. 返回拼接id |
||||
|
this.$emit('change', this.enclosure) |
||||
|
}, |
||||
|
// 返回this.file_add(新上传文件的id拼接集合) |
||||
|
getNewFileId(fileList) { |
||||
|
// debugger |
||||
|
this.file_add = '' |
||||
|
for (var i = 0; i < fileList.length; i++) { |
||||
|
if (fileList[i].response && fileList[i].response.code === '200') { |
||||
|
this.file_add = this.file_add + fileList[i].response.data + ',' |
||||
|
} |
||||
|
} |
||||
if (this.file_add !== '') { |
if (this.file_add !== '') { |
||||
this.enclosure = this.file_catch + ',' + this.file_add |
this.file_add = this.file_add.substring(0, this.file_add.length - 1) |
||||
|
} |
||||
|
// console.log('1. this.file_add: ' + this.file_add) |
||||
|
}, |
||||
|
// 返回this.file_catch(数库一寸照的文件的id的拼接集合) |
||||
|
getCatchFileId(file) { |
||||
|
for (var i = 0; i < this.files_list.length; i++) { |
||||
|
if (this.file_catch !== '') { |
||||
|
// 1. 检查当前删除的文件是否是修改文件列表里面的,如果是,将修改列表里去除此id |
||||
|
if (this.files_list[i].name === file.name) { |
||||
|
// 2. 拆开file_catch到fils_arry |
||||
|
var fils_arry = this.file_catch.split(',') |
||||
|
// 3. 从fils_arry去除 this.files_list[i].id |
||||
|
var arry = [] |
||||
|
fils_arry.forEach((element) => { |
||||
|
// 不加载文件里面的 |
||||
|
if (element !== this.files_list[i].id) { |
||||
|
arry.push(element) |
||||
|
} |
||||
|
}) |
||||
|
// 4. 重新拼接成file_catch |
||||
|
this.file_catch = arry.join(',') |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
// console.log('2. this.file_catch:' + this.file_catch) |
||||
|
}, |
||||
|
// 保存并拼接id |
||||
|
getFileId() { |
||||
|
// console.log('3. this.file_catch:' + this.file_catch + ',this.file_add:' + this.file_add) |
||||
|
if (this.file_catch !== '') { |
||||
|
if (this.file_add !== '') { |
||||
|
this.enclosure = this.file_catch + ',' + this.file_add |
||||
|
} else { |
||||
|
this.enclosure = this.file_catch |
||||
|
} |
||||
} else { |
} else { |
||||
this.enclosure = this.file_catch |
this.enclosure = this.file_add |
||||
} |
} |
||||
} else { |
}, |
||||
this.enclosure = this.file_add |
// 上传失败 |
||||
} |
uploadError() { |
||||
}, |
this.loadding = false |
||||
// 上传失败 |
}, |
||||
uploadError() { |
uploadProgrees(event, file, fileList) { |
||||
this.loadding = false |
if (Number(event.percent) > 0) { |
||||
}, |
this.loadding = true |
||||
uploadProgrees(event, file, fileList) { |
} |
||||
if (Number(event.percent) > 0) { |
// console.log('event:', event) |
||||
this.loadding = true |
|
||||
} |
} |
||||
// console.log('event:', event) |
|
||||
} |
} |
||||
} |
} |
||||
} |
|
||||
</script> |
</script> |
||||
|
|
||||
<style scoped></style> |
<style scoped></style> |
||||
|
Loading…
Reference in new issue