Commit 2b7b1622 by cwq0219

图片上传

1 parent cebc6e7e
......@@ -60,9 +60,10 @@
@click="handleImg()"
>
<gl-upload
id="upload"
v-if="isEdit"
class="upload-demo"
name="files"
name="file"
:action="uploadAction"
:limit="2"
:before-upload="beforeUpload"
......@@ -74,6 +75,7 @@
size="small"
>上传图片</gl-button>
</gl-upload>
<input type="file" id="id" name="image" class="getImgUrl_file" @change="shangc($event)" accept="image/jpg,image/jpeg,image/png">
</span>
<gl-select
v-else-if="i.name == 'merchantChannelName' && isEdit"
......@@ -171,6 +173,7 @@
<script>
import VueAMap from 'vue-amap'
import Vue from 'vue'
import axios from 'axios'
import { businessManagenMethods, bizMethods, request } from '@/api'
import notice from '@/common/notice'
var marker = []
......@@ -207,6 +210,7 @@ export default {
isMarkAddr: false,
editOptions: ['address', 'contactor', 'contactPhone', 'phone', 'email'],
channelList: [],
fileInfo: { fileType: '', fileBase: '' },
List: [
{
name: 'merchantName',
......@@ -398,7 +402,7 @@ export default {
// }/gps/common/uploadFile`
// this.uploadAction = 'http://192.168.2.109:8085/customer/gfs.test.glsx.com.cn'
// this.uploadAction = 'https://jsonplaceholder.typicode.com/posts/'
console.log(this.$get_session_common_config())
// console.log(this.$get_session_common_config())
this.uploadAction = 'http://192.168.3.217:9220/file/upstring'
this.$root.eventBus.$on('params', (params) => {
this.activeName = 'first'
......@@ -602,6 +606,8 @@ export default {
// 上传附件,限制用户上传的附件格式和大小
beforeUpload(file) {
console.log(file)
// const files = document.getElementById('upload')
// console.log(files)
const fileType = ['image/jpeg', 'image/jpg', 'image/gif', 'image/png']
const isFileType = fileType.includes(file.type)
const isLT20M = file.size / 1024 / 1024 < 20
......@@ -619,6 +625,61 @@ export default {
},
handleRemove(file, fileList) {
this.merchantInfo.merchantPortrait = ''
},
shangc(e) {
const _this = this
console.log(e)
const files = document.getElementById('id').files[0]
// const name = document.getElementById('id').files[0].name
// const arr = name.split('.')
// this.fileInfo.name = arr[0]
// console.log(arr)
this.fileInfo.fileType = document.getElementById('id').files[0].name
let fileSize = 0
// const fileMaxSize = 10240 // 1M
if (files) {
console.log(files)
fileSize = files.size
if (fileSize > 5 * 1024 * 1024) {
alert('文件大小不能大于5M!')
// file.value = ''
return false
} else if (fileSize <= 0) {
alert('文件大小不能为0M!')
// file.value = ''
return false
}
} else {
return false
}
// // 转码base64
const reader = new FileReader()
// let imgFile = ''
// let that = this
reader.readAsDataURL(files)
reader.onload = e => {
console.log(e)
// imgFile = e.target.result
// const arrBase64 = imgFile.split(',')
this.fileInfo.fileBase = e.target.result
console.log(this.fileInfo.fileType)
console.log(this.fileInfo.fileBase)
axios.post('http://192.168.3.217:9220/file/upstring', {
systemSign: '/mechantData',
fileType: _this.fileInfo.fileType,
uploadData: _this.fileInfo.fileBase
}, {
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
requestType: 'jsonString'
}).then(res => {
console.log(res)
}).catch(err => {
console.log(err)
})
}
}
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!