|
@@ -27,15 +27,12 @@
|
|
<div class="form-el-upload">
|
|
<div class="form-el-upload">
|
|
<el-upload
|
|
<el-upload
|
|
class="avatar-uploader"
|
|
class="avatar-uploader"
|
|
- accept="image/jpeg,image/gif,image/png"
|
|
|
|
- action="https://www-b.caimei365.com/register/imageUpload.action"
|
|
|
|
|
|
+ :action="action"
|
|
:show-file-list="false"
|
|
:show-file-list="false"
|
|
:on-success="handleAvatarSuccess"
|
|
:on-success="handleAvatarSuccess"
|
|
:before-upload="beforeAvatarUpload"
|
|
:before-upload="beforeAvatarUpload"
|
|
- :multiple="false"
|
|
|
|
- :limit="1"
|
|
|
|
>
|
|
>
|
|
- <img v-if="form.imageUrl" :src="form.imageUrl" class="avatar">
|
|
|
|
|
|
+ <img v-if="form.businessLicenseImage" :src="form.businessLicenseImage" class="avatar">
|
|
<i v-else class="el-icon-plus avatar-uploader-icon" />
|
|
<i v-else class="el-icon-plus avatar-uploader-icon" />
|
|
<div slot="tip" class="el-upload__tip">注意:请上传jpg/png格式的图片,最大不超过5M</div>
|
|
<div slot="tip" class="el-upload__tip">注意:请上传jpg/png格式的图片,最大不超过5M</div>
|
|
</el-upload>
|
|
</el-upload>
|
|
@@ -45,13 +42,12 @@
|
|
<div class="form-el-upload">
|
|
<div class="form-el-upload">
|
|
<el-upload
|
|
<el-upload
|
|
class="avatar-uploader"
|
|
class="avatar-uploader"
|
|
- accept="image/jpeg,image/gif,image/png,image/jpg"
|
|
|
|
- action="https://jsonplaceholder.typicode.com/posts/"
|
|
|
|
|
|
+ :action="action"
|
|
:show-file-list="false"
|
|
:show-file-list="false"
|
|
:on-success="handleDoorwaySuccess"
|
|
:on-success="handleDoorwaySuccess"
|
|
- :before-upload="beforeDoorwayUpload"
|
|
|
|
|
|
+ :before-upload="beforeAvatarUpload"
|
|
>
|
|
>
|
|
- <img v-if="form.doorwayImageUrl" :src="form.doorwayImageUrl" class="avatar">
|
|
|
|
|
|
+ <img v-if="form.headpic" :src="form.headpic" class="avatar">
|
|
<i v-else class="el-icon-plus avatar-uploader-icon" />
|
|
<i v-else class="el-icon-plus avatar-uploader-icon" />
|
|
<div slot="tip" class="el-upload__tip">注意:请上传jpg/png格式的图片,最大不超过5M</div>
|
|
<div slot="tip" class="el-upload__tip">注意:请上传jpg/png格式的图片,最大不超过5M</div>
|
|
</el-upload>
|
|
</el-upload>
|
|
@@ -77,12 +73,12 @@
|
|
// 引入省市区组件,公共组件所在的路径
|
|
// 引入省市区组件,公共组件所在的路径
|
|
import City from '@/components/Ctiy'
|
|
import City from '@/components/Ctiy'
|
|
import { saveAddClubUser } from '@/api/club'
|
|
import { saveAddClubUser } from '@/api/club'
|
|
|
|
+import { uploadFile, getBase64 } from '@/api/other'
|
|
export default {
|
|
export default {
|
|
components: { City },
|
|
components: { City },
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
- dialogImageUrl: '',
|
|
|
|
- dialogVisible: false,
|
|
|
|
|
|
+ action: `${this.baseUrl}/mall/uploadFile/imageUpload`,
|
|
form: {
|
|
form: {
|
|
name: '',
|
|
name: '',
|
|
linkMan: '',
|
|
linkMan: '',
|
|
@@ -121,46 +117,44 @@ export default {
|
|
this.addList.cityID = data.cityid
|
|
this.addList.cityID = data.cityid
|
|
this.addList.townID = data.townid
|
|
this.addList.townID = data.townid
|
|
},
|
|
},
|
|
|
|
+ // 上传图标事件
|
|
handleAvatarSuccess(res, file) {
|
|
handleAvatarSuccess(res, file) {
|
|
- this.getBase64(file.raw).then(res => {
|
|
|
|
- console.log(res)
|
|
|
|
|
|
+ getBase64(file.raw).then(res => {
|
|
|
|
+ uploadFile({ imgStr: res }).then(response => {
|
|
|
|
+ console.log(response)
|
|
|
|
+ if (response.code === '1') {
|
|
|
|
+ this.form.businessLicenseImage = response.data
|
|
|
|
+ } else {
|
|
|
|
+ this.$message.error('上传图片失败')
|
|
|
|
+ }
|
|
|
|
+ })
|
|
})
|
|
})
|
|
- const fileName = file.name
|
|
|
|
- const regex = /(.jpg|.jpeg|.gif|.png|.bmp)$/
|
|
|
|
- if (regex.test(fileName.toLowerCase())) {
|
|
|
|
- this.form.imageUrl = URL.createObjectURL(file.raw)
|
|
|
|
- } else {
|
|
|
|
- this.$message.error('请选择图片文件')
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- beforeAvatarUpload(file) {
|
|
|
|
- const isLt5M = file.size / 1024 / 1024 < 5
|
|
|
|
- if (!isLt5M) {
|
|
|
|
- this.$message.error('上传头像图片大小不能超过 5MB!')
|
|
|
|
- }
|
|
|
|
- return isLt5M
|
|
|
|
},
|
|
},
|
|
handleDoorwaySuccess(res, file) {
|
|
handleDoorwaySuccess(res, file) {
|
|
- this.getBase64(file.raw).then(res => {
|
|
|
|
- console.log(res)
|
|
|
|
|
|
+ getBase64(file.raw).then(res => {
|
|
|
|
+ uploadFile({ imgStr: res }).then(response => {
|
|
|
|
+ console.log(response)
|
|
|
|
+ if (response.code === '1') {
|
|
|
|
+ this.form.headpic = response.data
|
|
|
|
+ } else {
|
|
|
|
+ this.$message.error('上传图片失败')
|
|
|
|
+ }
|
|
|
|
+ })
|
|
})
|
|
})
|
|
- const fileName = file.name
|
|
|
|
- const regex = /(.jpg|.jpeg|.gif|.png|.bmp)$/
|
|
|
|
- if (regex.test(fileName.toLowerCase())) {
|
|
|
|
- this.form.doorwayImageUrl = URL.createObjectURL(file.raw)
|
|
|
|
- } else {
|
|
|
|
- this.$message.error('请选择图片文件')
|
|
|
|
- }
|
|
|
|
},
|
|
},
|
|
- beforeDoorwayUpload(file) {
|
|
|
|
- this.getBase64(file.raw).then(res => {
|
|
|
|
- console.log(res)
|
|
|
|
- })
|
|
|
|
|
|
+ // 对上传图片的大小、格式进行限制
|
|
|
|
+ beforeAvatarUpload(file) {
|
|
|
|
+ const isJPG = file.type === 'image/jpeg'
|
|
|
|
+ const isJPG2 = file.type === 'image/jpg'
|
|
|
|
+ const isPNG = file.type === 'image/png'
|
|
const isLt5M = file.size / 1024 / 1024 < 5
|
|
const isLt5M = file.size / 1024 / 1024 < 5
|
|
|
|
+ if (!isJPG && !isJPG2 && !isPNG) {
|
|
|
|
+ this.$message.error('只支持jpg或png格式图片')
|
|
|
|
+ }
|
|
if (!isLt5M) {
|
|
if (!isLt5M) {
|
|
- this.$message.error('上传头像图片大小不能超过 5MB!')
|
|
|
|
|
|
+ this.$message.error('请上传5MB以内的图片!')
|
|
}
|
|
}
|
|
- return isLt5M
|
|
|
|
|
|
+ return (isJPG || isJPG2 || isPNG) && isLt5M
|
|
},
|
|
},
|
|
onSubmite() {
|
|
onSubmite() {
|
|
this.$refs['dataForm'].validate((valid) => {
|
|
this.$refs['dataForm'].validate((valid) => {
|
|
@@ -179,22 +173,6 @@ export default {
|
|
})
|
|
})
|
|
}
|
|
}
|
|
})
|
|
})
|
|
- },
|
|
|
|
- getBase64(file) {
|
|
|
|
- return new Promise(function(resolve, reject) {
|
|
|
|
- const reader = new FileReader()
|
|
|
|
- let imgResult = ''
|
|
|
|
- reader.readAsDataURL(file)
|
|
|
|
- reader.onload = function() {
|
|
|
|
- imgResult = reader.result
|
|
|
|
- }
|
|
|
|
- reader.onerror = function(error) {
|
|
|
|
- reject(error)
|
|
|
|
- }
|
|
|
|
- reader.onloadend = function() {
|
|
|
|
- resolve(imgResult)
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -214,23 +192,24 @@ export default {
|
|
.avatar-uploader-icon {
|
|
.avatar-uploader-icon {
|
|
font-size: 28px;
|
|
font-size: 28px;
|
|
color: #8c939d;
|
|
color: #8c939d;
|
|
- width: 178px;
|
|
|
|
- height: 178px;
|
|
|
|
- line-height: 178px;
|
|
|
|
|
|
+ width: 148px;
|
|
|
|
+ height: 148px;
|
|
|
|
+ line-height: 148px;
|
|
text-align: center;
|
|
text-align: center;
|
|
}
|
|
}
|
|
.avatar {
|
|
.avatar {
|
|
- width: 178px;
|
|
|
|
- height: 178px;
|
|
|
|
|
|
+ width: 148px;
|
|
|
|
+ height: 148px;
|
|
display: block;
|
|
display: block;
|
|
}
|
|
}
|
|
.el-form-item__label{
|
|
.el-form-item__label{
|
|
text-align: right !important;
|
|
text-align: right !important;
|
|
}
|
|
}
|
|
.form-el-upload{
|
|
.form-el-upload{
|
|
- width: 180px;
|
|
|
|
|
|
+ width: 150px;
|
|
}
|
|
}
|
|
.el-upload__tip{
|
|
.el-upload__tip{
|
|
|
|
+ margin-top: 0;
|
|
line-height: 20px;
|
|
line-height: 20px;
|
|
color: red;
|
|
color: red;
|
|
text-align: left;
|
|
text-align: left;
|