Commit addc99e3 by cwq0219

图片上传

1 parent 90f19a5f
......@@ -59,33 +59,7 @@
alt=""
@click="handleImg()"
>
<!-- <gl-upload
id="upload"
v-if="isEdit"
class="upload-demo"
name="file"
:action="uploadAction"
:limit="2"
:before-upload="beforeUpload"
:on-success="handleSuccess"
:on-error="handleError"
:on-remove="handleRemove"
:file-list="fileList">
<gl-button
size="small"
>上传图片</gl-button>
</gl-upload> -->
<!-- <input v-if="isEdit" type="file" id="id" name="image" class="getImgUrl_file" @change="shangc($event)" accept="image/jpg,image/jpeg,image/png"> -->
<!-- <form id="uploadForm" enctype="application/x-www-form-urlencoded">
<input type="file" id="id" name="image" class="getImgUrl_file" accept="image/jpg,image/jpeg,image/png">
<button id="upload" type="button" @click="aa($event)">upload</button>
</form> -->
<!-- <form v-if="isEdit" method="post" action="http://gfs.test.glsx.com.cn/file/upstring" >
<input type="file" id="id" name="image" class="getImgUrl_file" @change="shangc($event)" accept="image/jpg,image/jpeg,image/png">
<input name="systemSign" value="mechantData"><br>
<input name="files" v-model="fileImg"><br>
<input type="submit" value="登录">
</form> -->
<input v-if="isEdit" 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"
......@@ -184,6 +158,7 @@
import VueAMap from 'vue-amap'
import Vue from 'vue'
import axios from 'axios'
import qs from 'qs'
import { businessManagenMethods, bizMethods, request } from '@/api'
import notice from '@/common/notice'
var marker = []
......@@ -221,7 +196,7 @@ export default {
editOptions: ['address', 'contactor', 'contactPhone', 'phone', 'email'],
channelList: [],
fileInfo: { fileType: '', fileBase: '' },
fileImg: '',
// fileImg: '',
List: [
{
name: 'merchantName',
......@@ -445,13 +420,13 @@ export default {
}
// 保存
if (!isCancel && this.isEdit) {
console.log('调保存接口--')
console.log(this.merchantInfo)
// console.log('调保存接口--')
// console.log(this.merchantInfo)
this.merchantInfo.merchantPortrait = this.List[9].value
const params = this.$deep_clone(this.merchantInfo)
// params.merchantChannel = params.merchantId
delete params.merchantChannelName
params.method = bizMethods.MerchantModify
console.log(params)
// console.log(params)
request.req(params).then(res => {
this.isEdit = !this.isEdit
notice.okTips()
......@@ -462,6 +437,7 @@ export default {
// this.getAddress(this.merchantInfo.lng, this.merchantInfo.lat)
if (isCancel) {
this.merchantInfo = JSON.parse(JSON.stringify(this.tempMerchantInfo))
this.List[9].value = this.merchantInfo.merchantPortrait
if (!this.merchantInfo.lng && !this.merchantInfo.lat) {
marker && amapManager._map.remove(marker)
this.hasLocation = false
......@@ -640,18 +616,15 @@ export default {
},
shangc(e) {
// const _this = this
console.log(e)
// console.log(e)
const files = document.getElementById('id').files[0]
const name = document.getElementById('id').files[0].name
const name = files ? 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
this.fileInfo.fileType = arr[1]
let fileSize = 0
let fileSize = files.size
// const fileMaxSize = 10240 // 1M
if (files) {
console.log(files)
// console.log(files)
fileSize = files.size
if (fileSize > 5 * 1024 * 1024) {
alert('文件大小不能大于5M!')
......@@ -680,63 +653,20 @@ export default {
// console.log(this.fileInfo.fileType)
// console.log(this.fileInfo.fileBase)
const fileParams = this.fileInfo.fileType + '@' + this.fileInfo.fileBase
this.fileImg = this.fileInfo.fileType + '@' + this.fileInfo.fileBase
const aa = {
axios.post('http://gfs.test.glsx.com.cn/file/upstring', qs.stringify({
systemSign: 'mechantData',
files: fileParams
}
console.log(aa)
// const fileTemp = JSON.stringify(aa)
// console.log(fileTemp)
// var formData = new FormData()
// formData.append('systemSign', 'mechantData')
// formData.append('files', fileParams)
// axios({
// method: 'post',
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded'
// },
// // transformRequest: [function(data) {
// // console.log('---------')
// // data = JSON.stringify(data)
// // return data
// // }],
// url: 'http://gfs.test.glsx.com.cn/file/upstring',
// data: aa,
// // dataType: 'json', // jsonp会把请求类型强制转换为get请求
// // contentType: false,
// processData: false
// })
// axios.post('http://gfs.test.glsx.com.cn/file/upstring', formData,
// {
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded'
// }
// // requestType: 'jsonString'
// }).then(res => {
// console.log(res)
// }).catch(err => {
// console.log(err)
// })
// axios({
// method: 'post',
// url: 'http://gfs.test.glsx.com.cn/file/upstring',
// data: aa,
// // headers: {
// // 'content-type': 'application/x-www-form-urlencoded'
// // },
// transformRequest: [function(data) {
// console.log(data)
// data = JSON.stringify(data)
// console.log(data)
// return data
// }]
// // requestType: 'jsonString'
// }).then(res => {
// console.log(res)
// }).catch(err => {
// console.log(err)
// })
}),
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(res => {
this.merchantInfo.merchantPortrait = res.data.url
this.List[9].value = res.data.url
}).catch(err => {
notice.errorTips(err)
})
}
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!