提交 7d93e017 编写于 作者: M maguohua

上传图片

上级 d8e827ad
MIT License
Copyright (c) 2017 cangdu
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
......@@ -66,4 +66,4 @@ npm run dev
### License
[MIT](https://mit-license.org/)
[MIT](https://github.com/bailicangdu/vue2-manage/blob/master/LICENSE)
......@@ -72,33 +72,33 @@
<el-form-item label="上传店铺头像">
<el-upload
class="avatar-uploader"
action="//jsonplaceholder.typicode.com/posts/"
:action="baseUrl + '/shopping/addimg'"
:show-file-list="false"
:on-success="handleShopAvatarScucess"
:before-upload="beforeAvatarUpload">
<img v-if="formData.image_path" :src="formData.image_path" class="avatar">
<img v-if="formData.image_path" :src="baseUrl + formData.image_path" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
</el-form-item>
<el-form-item label="上传营业执照">
<el-upload
class="avatar-uploader"
action="//jsonplaceholder.typicode.com/posts/"
:action="baseUrl + '/shopping/addimg'"
:show-file-list="false"
:on-success="handleBusinessAvatarScucess"
:before-upload="beforeAvatarUpload">
<img v-if="formData.business_license_image" :src="formData.business_license_image" class="avatar">
<img v-if="formData.business_license_image" :src="baseUrl + formData.business_license_image" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
</el-form-item>
<el-form-item label="上传餐饮服务许可证">
<el-upload
class="avatar-uploader"
action="//jsonplaceholder.typicode.com/posts/"
:action="baseUrl + '/shopping/addimg'"
:show-file-list="false"
:on-success="handleServiceAvatarScucess"
:before-upload="beforeAvatarUpload">
<img v-if="formData.catering_service_license_image" :src="formData.catering_service_license_image" class="avatar">
<img v-if="formData.catering_service_license_image" :src="baseUrl + formData.catering_service_license_image" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
</el-form-item>
......@@ -157,6 +157,7 @@
<script>
import headTop from '@/components/headTop'
import {cityGuess, addShop, searchplace} from '@/api/getData'
import {baseUrl} from '@/config/env'
export default {
data(){
return {
......@@ -213,7 +214,8 @@
icon_name: '',
name: '满减优惠',
description: '满30减5,满60减8',
}]
}],
baseUrl,
}
},
components: {
......@@ -252,13 +254,25 @@
console.log(address)
},
handleShopAvatarScucess(res, file) {
this.formData.image_path = URL.createObjectURL(file.raw);
if (res.status == 1) {
this.formData.image_path = res.image_path;
}else{
this.$message.error('上传图片失败!');
}
},
handleBusinessAvatarScucess(res, file) {
this.formData.business_license_image = URL.createObjectURL(file.raw);
if (res.status == 1) {
this.formData.business_license_image = res.image_path;
}else{
this.$message.error('上传图片失败!');
}
},
handleServiceAvatarScucess(res, file) {
this.formData.catering_service_license_image = URL.createObjectURL(file.raw);
if (res.status == 1) {
this.formData.catering_service_license_image = res.image_path;
}else{
this.$message.error('上传图片失败!');
}
},
beforeAvatarUpload(file) {
const isRightType = (file.type === 'image/jpeg') || (file.type === 'image/png');
......@@ -270,7 +284,7 @@
if (!isLt2M) {
this.$message.error('上传头像图片大小不能超过 2MB!');
}
return isJPG && isLt2M;
return isRightType && isLt2M;
},
tableRowClassName(row, index) {
if (index === 1) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册