1. 图片上传

This commit is contained in:
邱贞招 2024-04-01 19:42:42 +08:00
parent 8f91a75244
commit e87f5e3520
4 changed files with 61 additions and 93 deletions

View File

@ -10,7 +10,7 @@
:on-exceed="handleExceed" :on-exceed="handleExceed"
:on-success="handleUploadSuccess" :on-success="handleUploadSuccess"
:show-file-list="false" :show-file-list="false"
:headers="headers" :data="uploadData"
class="upload-file-uploader" class="upload-file-uploader"
ref="fileUpload" ref="fileUpload"
> >
@ -41,6 +41,7 @@
<script> <script>
import { getToken } from "@/utils/auth"; import { getToken } from "@/utils/auth";
import { getQiniuToken } from "@/api/common/common";
export default { export default {
name: "FileUpload", name: "FileUpload",
@ -73,13 +74,22 @@ export default {
number: 0, number: 0,
uploadList: [], uploadList: [],
baseUrl: process.env.VUE_APP_BASE_API, baseUrl: process.env.VUE_APP_BASE_API,
uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", // uploadData: {key:'',token:''},
headers: { uploadFileUrl: "https://up-z2.qiniup.com", //
Authorization: "Bearer " + getToken(), // headers: {
}, // Authorization: "Bearer " + getToken(),
// },
fileList: [], fileList: [],
}; };
}, },
mounted() {
getQiniuToken().then((res)=> {
console.log("七牛云获取token"+JSON.stringify(res));
if (res.code === 200) {
this.uploadData.token = res.token
}
})
},
watch: { watch: {
value: { value: {
handler(val) { handler(val) {
@ -146,6 +156,8 @@ export default {
}, },
// //
handleUploadSuccess(res, file) { handleUploadSuccess(res, file) {
console.log("七牛云获取res"+JSON.stringify(res));
console.log("七牛云获取file"+JSON.stringify(file));
if (res.code === 200) { if (res.code === 200) {
this.uploadList.push({ name: res.fileName, url: res.fileName }); this.uploadList.push({ name: res.fileName, url: res.fileName });
this.uploadedSuccessfully(); this.uploadedSuccessfully();

View File

@ -12,7 +12,7 @@
ref="imageUpload" ref="imageUpload"
:on-remove="handleDelete" :on-remove="handleDelete"
:show-file-list="true" :show-file-list="true"
:headers="headers" :data='uploadData'
:file-list="fileList" :file-list="fileList"
:on-preview="handlePictureCardPreview" :on-preview="handlePictureCardPreview"
:class="{hide: this.fileList.length >= this.limit}" :class="{hide: this.fileList.length >= this.limit}"
@ -44,6 +44,7 @@
<script> <script>
import { getToken } from "@/utils/auth"; import { getToken } from "@/utils/auth";
import {getQiniuToken} from "@/api/common/common";
export default { export default {
props: { props: {
@ -77,13 +78,25 @@ export default {
dialogVisible: false, dialogVisible: false,
hideUpload: false, hideUpload: false,
baseUrl: process.env.VUE_APP_BASE_API, baseUrl: process.env.VUE_APP_BASE_API,
uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload", // uploadData: {key:'',token:''},
headers: { domain:"",
Authorization: "Bearer " + getToken(), uploadImgUrl:"https://up-z2.qiniup.com", //
}, // headers: {
// Authorization: "Bearer " + getToken(),
// },
fileList: [] fileList: []
}; };
}, },
mounted(){
getQiniuToken().then(res => {
debugger
console.log("获取到七牛云token"+JSON.stringify(res));
if (res.code === 200) {
this.uploadData.token = res.token;
this.domain = res.domain;
}
})
},
watch: { watch: {
value: { value: {
handler(val) { handler(val) {
@ -93,11 +106,7 @@ export default {
// //
this.fileList = list.map(item => { this.fileList = list.map(item => {
if (typeof item === "string") { if (typeof item === "string") {
if (item.indexOf(this.baseUrl) === -1) { item = { name: item, url: item };
item = { name: this.baseUrl + item, url: this.baseUrl + item };
} else {
item = { name: item, url: item };
}
} }
return item; return item;
}); });
@ -154,16 +163,18 @@ export default {
}, },
// //
handleUploadSuccess(res, file) { handleUploadSuccess(res, file) {
if (res.code === 200) { console.log("上传成功回调token"+JSON.stringify(res));
this.uploadList.push({ name: res.fileName, url: res.fileName }); console.log("上传成功回调file"+JSON.stringify(file));
this.uploadedSuccessfully(); // if (res.code === 200) {
} else { this.uploadList.push({ name: res.hash, url: this.domain+"/"+res.hash });
this.number--; this.uploadedSuccessfully();
this.$modal.closeLoading(); // } else {
this.$modal.msgError(res.msg); // this.number--;
this.$refs.imageUpload.handleRemove(file); // this.$modal.closeLoading();
this.uploadedSuccessfully(); // this.$modal.msgError(res.msg);
} // this.$refs.imageUpload.handleRemove(file);
// this.uploadedSuccessfully();
// }
}, },
// //
handleDelete(file) { handleDelete(file) {
@ -180,7 +191,9 @@ export default {
}, },
// //
uploadedSuccessfully() { uploadedSuccessfully() {
if (this.number > 0 && this.uploadList.length === this.number) { console.log("this.number"+this.number);
console.log("this.uploadList.length"+this.uploadList.length);
if (this.number > 0) {
this.fileList = this.fileList.concat(this.uploadList); this.fileList = this.fileList.concat(this.uploadList);
this.uploadList = []; this.uploadList = [];
this.number = 0; this.number = 0;
@ -190,6 +203,7 @@ export default {
}, },
// //
handlePictureCardPreview(file) { handlePictureCardPreview(file) {
console.log("预览:"+JSON.stringify(file));
this.dialogImageUrl = file.url; this.dialogImageUrl = file.url;
this.dialogVisible = true; this.dialogVisible = true;
}, },

View File

@ -71,7 +71,7 @@
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="植物数" align="center" prop="plantNum" /> <el-table-column label="植物数" align="center" prop="plantNum" />
<el-table-column label="备注" align="center" prop="remark" /> <el-table-column label="备注" align="center" :show-overflow-tooltip="true" prop="remark" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <el-button

View File

@ -7,57 +7,17 @@
</el-form-item> </el-form-item>
</el-form> </el-form>
<!-- <el-row :gutter="10" class="mb8">-->
<!-- <el-col :span="1.5">-->
<!-- <el-button-->
<!-- type="primary"-->
<!-- plain-->
<!-- icon="el-icon-plus"-->
<!-- size="mini"-->
<!-- @click="handleAdd"-->
<!-- v-hasPermi="['device:log:add']"-->
<!-- >新增</el-button>-->
<!-- </el-col>-->
<!-- <el-col :span="1.5">-->
<!-- <el-button-->
<!-- type="success"-->
<!-- plain-->
<!-- icon="el-icon-edit"-->
<!-- size="mini"-->
<!-- :disabled="single"-->
<!-- @click="handleUpdate"-->
<!-- v-hasPermi="['device:log:edit']"-->
<!-- >修改</el-button>-->
<!-- </el-col>-->
<!-- <el-col :span="1.5">-->
<!-- <el-button-->
<!-- type="danger"-->
<!-- plain-->
<!-- icon="el-icon-delete"-->
<!-- size="mini"-->
<!-- :disabled="multiple"-->
<!-- @click="handleDelete"-->
<!-- v-hasPermi="['device:log:remove']"-->
<!-- >删除</el-button>-->
<!-- </el-col>-->
<!-- <el-col :span="1.5">-->
<!-- <el-button-->
<!-- type="warning"-->
<!-- plain-->
<!-- icon="el-icon-download"-->
<!-- size="mini"-->
<!-- @click="handleExport"-->
<!-- v-hasPermi="['device:log:export']"-->
<!-- >导出</el-button>-->
<!-- </el-col>-->
<!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!-- </el-row>-->
<el-table v-loading="loading" :data="logList" @selection-change="handleSelectionChange"> <el-table v-loading="loading" :data="logList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" /> <el-table-column type="selection" width="55" align="center" />
<el-table-column label="id" align="center" prop="id" /> <!-- <el-table-column label="id" align="center" prop="id" />-->
<el-table-column label="用户ID" align="center" prop="userId" /> <el-table-column label="用户ID" align="center" prop="userId" />
<el-table-column label="url" align="center" prop="url" /> <!-- <el-table-column label="url" align="center" prop="url" />-->
<el-table-column label="图片" align="center" prop="url" width="100">
<template slot-scope="scope">
<image-preview :src="scope.row.url" :width="50" :height="50"/>
</template>
</el-table-column>
<el-table-column label="百度识别返回" align="center" prop="response" :show-overflow-tooltip="true"/> <el-table-column label="百度识别返回" align="center" prop="response" :show-overflow-tooltip="true"/>
<el-table-column label="消息" align="center" prop="msg" /> <el-table-column label="消息" align="center" prop="msg" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180"> <el-table-column label="创建时间" align="center" prop="createTime" width="180">
@ -65,24 +25,6 @@
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span> <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
</template> </template>
</el-table-column> </el-table-column>
<!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!-- <template slot-scope="scope">-->
<!-- <el-button-->
<!-- size="mini"-->
<!-- type="text"-->
<!-- icon="el-icon-edit"-->
<!-- @click="handleUpdate(scope.row)"-->
<!-- v-hasPermi="['device:log:edit']"-->
<!-- >修改</el-button>-->
<!-- <el-button-->
<!-- size="mini"-->
<!-- type="text"-->
<!-- icon="el-icon-delete"-->
<!-- @click="handleDelete(scope.row)"-->
<!-- v-hasPermi="['device:log:remove']"-->
<!-- >删除</el-button>-->
<!-- </template>-->
<!-- </el-table-column>-->
</el-table> </el-table>
<pagination <pagination