update 图片上传

This commit is contained in:
2023-04-28 15:04:45 +08:00
parent b9f29d5179
commit 61f3103824
2 changed files with 41 additions and 34 deletions

View File

@@ -17,20 +17,7 @@
<div id="container"></div> <div id="container"></div>
</div> </div>
<div>上传图片</div>
<el-upload
action="http://localhost:8080/common/uploadOSS"
:headers="headers"
list-type="picture-card"
:on-preview="handlePictureCardPreview"
:on-remove="handleRemove"
:on-success="handleSuccess"
>
<i class="el-icon-plus"></i>
</el-upload>
<el-dialog :visible.sync="dialogVisible">
<img width="100%" :src="dialogImageUrl" alt="">
</el-dialog>
<!-- <div class="img">--> <!-- <div class="img">-->
<!-- <el-input--> <!-- <el-input-->
@@ -77,26 +64,11 @@ export default {
placeSearch: "", placeSearch: "",
stationId: this.$route.params.id, stationId: this.$route.params.id,
avatar: "", avatar: "",
headers: {
Authorization: "Bearer " + getToken()
},
imageUrl: null
}; };
}, },
methods: { methods: {
handleSuccess(res, file) {
this.imageUrl = URL.createObjectURL(file.raw);
console.log("图片上传成功 url", this.imageUrl);
console.log("图片上传成功 res", res);
},
handleRemove(file, fileList) {
console.log(file, fileList);
},
handlePictureCardPreview(file) {
this.dialogImageUrl = file.url;
console.log(this.dialogImageUrl)
this.dialogVisible = true;
},
// 点击搜索按钮 // 点击搜索按钮
send() { send() {
this.searchPlaceInput = this.inputObject.userInput; this.searchPlaceInput = this.inputObject.userInput;

View File

@@ -1,5 +1,19 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<div>上传图片</div>
<el-upload
action="http://localhost:8080/common/uploadOSS"
:headers="headers"
list-type="picture-card"
:on-preview="handlePictureCardPreview"
:on-remove="handleRemove"
:on-success="handleSuccess"
>
<i class="el-icon-plus"></i>
</el-upload>
<el-dialog :visible.sync="dialogVisible">
<img width="100%" :src="dialogImageUrl" alt="">
</el-dialog>
<el-form <el-form
:label-position="labelPosition" :label-position="labelPosition"
label-width="120px" label-width="120px"
@@ -174,11 +188,17 @@ import {
} from "@/api/pile/station.js"; } from "@/api/pile/station.js";
import bus from "@/bus/bus"; import bus from "@/bus/bus";
import { regionData} from "element-china-area-data"; import { regionData} from "element-china-area-data";
import {getToken} from "@/utils/auth";
export default { export default {
dicts: ["station_type", "match_cars", "construction_type"], dicts: ["station_type", "match_cars", "construction_type"],
data() { data() {
return { return {
headers: {
Authorization: "Bearer " + getToken()
},
imageUrl: null,
dialogImageUrl:'',
options: regionData, options: regionData,
labelPosition: "right", labelPosition: "right",
station: { station: {
@@ -197,6 +217,7 @@ export default {
stationStatus: "", stationStatus: "",
construction: "", construction: "",
businessHours: "", businessHours: "",
pictures: "",
}, },
stationId: this.$route.params.id, stationId: this.$route.params.id,
publicFlagOptions: [ publicFlagOptions: [
@@ -269,12 +290,27 @@ export default {
{ required: true, message: "请输入营业时间", trigger: "blur" }, { required: true, message: "请输入营业时间", trigger: "blur" },
], ],
}, },
pictureList: [],
}; };
}, },
created() { created() {
}, },
methods: { methods: {
handleSuccess(res, file) {
this.imageUrl = URL.createObjectURL(file.raw);
console.log("图片上传成功 url", this.imageUrl);
console.log("图片上传成功 res", res);
this.pictureList.push(res.url);
},
handleRemove(file, fileList) {
console.log(file, fileList);
},
handlePictureCardPreview(file) {
this.dialogImageUrl = file.url;
console.log(this.dialogImageUrl)
this.dialogVisible = true;
},
handleChange() { handleChange() {
console.log("111"); console.log("111");
}, },
@@ -283,15 +319,14 @@ export default {
const res = await getStationInfo(this.stationId); const res = await getStationInfo(this.stationId);
console.log(res); console.log(res);
this.station = res.data; this.station = res.data;
this.pictureList = this.station.pictures.split(',');
console.log("queryStationInfo表格数据", this.station); console.log("queryStationInfo表格数据", this.station);
}, },
// 提交按钮 // 提交按钮
present() { present() {
// console.log("matchCars提交时", this.station.matchCars);
// console.log("selectMatchCars提交时", this.station.selectMatchCars);
// 赋值 // 赋值
this.station.matchCars = this.station.selectMatchCars.join(","); this.station.matchCars = this.station.selectMatchCars.join(",");
this.station.pictures = this.pictureList.join(',');
// console.log("matchCars赋值后", this.station.matchCars); // console.log("matchCars赋值后", this.station.matchCars);
this.$refs.stationRef.validate((valid) => { this.$refs.stationRef.validate((valid) => {
if (valid) { if (valid) {