Browse Source

车辆巡检单中上传相关照片的功能

master
yunuo970428 3 years ago
parent
commit
35e1c3af5d
  1. 6
      anrui-scm/anrui-scm-ui/src/api/portal/Upload.js
  2. 258
      anrui-scm/anrui-scm-ui/src/components/uploadFile/FaImages.vue
  3. 9
      anrui-scm/anrui-scm-ui/src/views/kucunguanli/cheliangweihu/richangxunjian/xunjiandan.vue

6
anrui-scm/anrui-scm-ui/src/api/portal/Upload.js

@ -1,10 +1,8 @@
import request from '@/utils/request' import request from '@/utils/request'
import qs from 'qs' import qs from 'qs'
// 统一请求路径前缀
const base = process.env.VUE_APP_URL
// 文件上传接口 // 文件上传接口
export const uploadFile = '/api/portal/file/upload' export const uploadFile = '/api/base/file/upload'
// 上传图片 // 上传图片
// export function imageUpload(data) { // export function imageUpload(data) {

258
anrui-scm/anrui-scm-ui/src/components/uploadFile/FaImages.vue

@ -1,53 +1,92 @@
<template> <template>
<div> <div>
<div> <el-upload ref="imgUpload" v-loading="loadding" class="avatar-uploader" :headers="accessToken"
<el-upload v-loading="loadding" ref="imgUpload" class="avatar-uploader" :headers="accessToken" :action="uploadFile" accept=".jpg,.jpeg,.png,.bmp,.pdf,.JPG,.JPEG,.BMP" list-type="picture-card" :file-list="files" :on-remove="removeImage" :on-preview="handlePictureCardPreview" :on-progress="uploadProgrees" :on-error="uploadError" :on-success="uploadImgSuccess_FuJian"> :action="uploadFile" accept=".jpg,.jpeg,.png,.bmp,.pdf,.JPG,.JPEG,.BMP" list-type="picture-card"
<i class="el-icon-plus avatar-uploader-icon"></i> :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>
</div> <el-dialog :visible.sync="dialogVisible" :append-to-body="true" title="查看图片">
<el-dialog :visible.sync="showpicture" :append-to-body="true" title="查看图片">
<img width="100%" :src="dialogImageUrl" alt=""> <img width="100%" :src="dialogImageUrl" alt="">
</el-dialog> </el-dialog>
<!-- <el-upload list-type="picture-card" :on-preview="handlePictureCardPreview" :on-remove="handleRemove">-->
<!-- <i class="el-icon-plus"></i>-->
<!-- </el-upload>-->
<!-- <el-dialog :visible.sync="dialogVisible">-->
<!-- <img width="100%" :src="dialogImageUrl" alt="">-->
<!-- </el-dialog>-->
<!-- <el-upload class="upload-demo" :headers="accessToken" :action="uploadFile" :accept="accept" :data="uploadData" :on-success="uploadImgSuccess_FuJian" :on-remove="handleRemove" :file-list="fileList_FuJian">-->
<!-- <el-button size="small" type="primary">点击上传</el-button>-->
<!-- &lt;!&ndash; <el-button v-show="isview" size="small" type="primary" @click="view()">查看</el-button> &ndash;&gt;-->
<!-- &lt;!&ndash; <div slot="tip" class="el-upload__tip">单个文件大小不允许超过100M,支持上传文件类型{{ accept }}</div> &ndash;&gt;-->
<!-- </el-upload>-->
</div> </div>
</template> </template>
<script> <script>
import { imageUpload } from '@/api/portal/Upload.js' import {uploadFile} from '@/api/portal/Upload'
import { mapGetters } from 'vuex' import {getStorage} from '@/utils/auth.js' //token
import {mapGetters} from 'vuex'
export default { export default {
model: { model: {
prop: 'imageFileList', prop: 'name',
event: 'fileListChange', event: 'change',
}, },
props: { props: {
placeholder: { placeholder: {
type: String, type: String,
default: '', default: '',
}, },
bucket: {
type: String,
default: 'abc',
},
// //
width: { width: {
type: String, type: String,
default: '270px', default: '270px',
}, },
// limit: {
imageFileList: { type: Number,
type: Array, default: 1,
required: [],
}, },
num: { accept: {
type: String, type: String,
default: '', default:
'.jpg,.jpeg,.png,.bmp,.pdf,.JPG,.JPEG,.BMP,.PDF,.xls,.docx,.xlsx,.ppt,.pptx',
},
//
name: {
type: Array,
required: true,
},
uploadData: {
type: Object,
default: {},
}, },
}, },
data() { data() {
return { return {
dialogImageUrl: '', dialogImageUrl: '',
accessToken: {}, dialogVisible: false,
fileUrl: fileUrl, accessToken: null,
uploadFile: imageUpload, uploadFile: uploadFile,
fileList_FuJian: [],
enclosure: '',
file_add: '',
file_catch: '',
files: [], files: [],
showpicture: false, files_list: [],
filedUrl: '',
// fileUrl: fileUrl,
// showpicture:false,
isview: false,
nameArr: '',
loadding: false, loadding: false,
stateName: '',
} }
}, },
computed: { computed: {
@ -60,16 +99,19 @@ export default {
]), ]),
}, },
watch: { watch: {
imageFileList: { name: {
deep: true, deep: true,
immediate: true,
handler(newVal, oldVal) { handler(newVal, oldVal) {
this.files = [] console.log('aaaa1', newVal)
for (var i = 0; i < newVal.length; i++) { console.log('aaaa2', oldVal)
this.files.push({ this.files = newVal
name: newVal[i].name, if (this.stateName = 'xunidingjinAdd') {
url: fileUrl + newVal[i].url, if (this.files.length > 1) {
}) this.files.splice(0, 1);
}
} }
console.log('aaaa2', this.files)
}, },
}, },
}, },
@ -79,62 +121,124 @@ export default {
}) })
}, },
created() { created() {
if (this.imageFileList !== undefined) { this.uploadFile = uploadFile //
this.files = [] this.accessToken = {
for (var i = 0; i < this.imageFileList.length; i++) { token: getStorage(),
this.files.push({
name: this.imageFileList[i].name,
url: fileUrl + this.imageFileList[i].url,
})
}
} }
}, },
methods: { methods: {
showImg(imgList) {
this.stateName = 'xunidingjinAdd'
this.files = imgList
console.log('回显图片', this.files)
},
view() {
// window.open(this.filedUrl)
},
// //
Init() { Init() {
// if (this.name !== undefined) {
// 1. token this.files = []
this.accessToken = { for (var i = 0; i < this.name.length; i++) {
accessToken: this.token, this.files.push({
name: this.name[i],
url: this.name[i],
})
} }
}, // -- }
uploadImgSuccess_FuJian(response, file, ImageFileList) { },
// --
uploadImgSuccess_FuJian(response, file, fileList) {
console.log('您选择的file:', file)
if (file.response.code === '200') {
this.loadding = false this.loadding = false
if (file.response.code === 20000) {
// //
var imageUrl = this.fileUrl + file.response.data this.filedUrl = this.fileUrl + file.response.data
var uid = file.response.data // var uid = file.response.data
this.files.push({ name: file.name, url: imageUrl }) 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)
}
},
var fileList = [] removeImage(file, ImageFileList) {
for (var i = 0; i < this.files.length; i++) { this.files.splice(this.files.indexOf(file), 1)
console.log(this.files[i].url, 'this.files[i].url') const imgFiles = []
fileList.push({ this.files.forEach((o) => {
name: this.files[i].name, imgFiles.push(o.url)
url: this.files[i].url.substr(this.fileUrl.length),
num: this.num,
}) })
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 + ','
} }
this.$emit('fileListChange', fileList)
} }
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)
}, },
removeImage(file, ImageFileList) { // this.file_catchid
this.files.splice(this.files.indexOf(file), 1) getCatchFileId(file) {
var fileList = [] for (var i = 0; i < this.files_list.length; i++) {
for (var i = 0; i < this.files.length; i++) { if (this.file_catch !== '') {
fileList.push({ // 1. id
name: this.files[i].name, if (this.files_list[i].name === file.name) {
url: this.files[i].url.substr(this.fileUrl.length), // 2. file_catchfils_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 {
this.enclosure = this.file_add
} }
this.$emit('fileListChange', fileList)
}, },
handlePictureCardPreview(file) { handlePictureCardPreview(file) {
this.dialogImageUrl = file.url this.dialogImageUrl = file.url
this.showpicture = true
}, },
// //
uploadError() { uploadError() {
@ -144,35 +248,9 @@ export default {
if (Number(event.percent) > 0) { if (Number(event.percent) > 0) {
this.loadding = true this.loadding = true
} }
// console.log('event:', event)
}, },
}, },
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped></style>
.avatar-uploader .el-upload {
border: 1px dashed #d9d9d9;
border-radius: 6px;
cursor: pointer;
position: relative;
overflow: hidden;
}
.avatar-uploader .el-upload:hover {
border-color: #409eff;
}
.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 100px;
height: 250px;
line-height: 100px;
text-align: center;
}
.avatar {
width: 200px;
height: 200px;
display: block;
// float: left;
}
</style>

9
anrui-scm/anrui-scm-ui/src/views/kucunguanli/cheliangweihu/richangxunjian/xunjiandan.vue

@ -55,7 +55,9 @@
<el-row> <el-row>
<el-col :span="24"> <el-col :span="24">
<div class="span-sty spanOneWidth"><span>相关照片</span></div> <div class="span-sty spanOneWidth"><span>相关照片</span></div>
<el-form-item><span>{{ formobj.vinNo }}</span></el-form-item> <el-form-item>
<upload ref="uploadImg" class="addinputw addinputwOne" v-model="list1" :limit="1" bucket="map" :upload-data="{type:'0001'}"/>
</el-form-item>
</el-col> </el-col>
</el-row> </el-row>
</el-form> </el-form>
@ -67,9 +69,13 @@
<script> <script>
import req from '@/api/weishoumaiduan/unsold' import req from '@/api/weishoumaiduan/unsold'
import { typeValues } from '@/api/cheliang/dictcommons' import { typeValues } from '@/api/cheliang/dictcommons'
import upload from '@/components/uploadFile/FaImages'
export default { export default {
name: 'cheliangxunjiancaozuo', name: 'cheliangxunjiancaozuo',
components: {
upload
},
data() { data() {
return { return {
viewTitle: '车辆巡检操作', viewTitle: '车辆巡检操作',
@ -80,6 +86,7 @@ export default {
list: [], list: [],
warehouse_list: [], warehouse_list: [],
staff_list: [], staff_list: [],
list1: [],
// //
formobj: { formobj: {
sid: '', // sid sid: '', // sid

Loading…
Cancel
Save