物资管理上传图片调整

master
zhangdi 3 months ago
parent 6d2e4c41e0
commit ca8bd84c03
  1. 86
      src/views/materials/index.vue

@ -1,9 +1,28 @@
<template> <template>
<div> <div>
<basic-container> <basic-container>
<avue-crud :option="option" v-model="form" :data="data" @row-del="rowDel" @on-load="onLoad" <avue-crud
:table-loading="loading" @row-update="rowUpdate" @row-save="rowSave" @search-change="searchChange" :option="option"
@search-reset="searchReset" :page.sync="page"> v-model="form"
:data="data"
@row-del="rowDel"
@on-load="onLoad"
:table-loading="loading"
@row-update="rowUpdate"
@row-save="rowSave"
@search-change="searchChange"
@search-reset="searchReset"
:page.sync="page"
:upload-after="uploadAfter"
>
<template slot="pictureImg" slot-scope="scope">
<!-- {{scope.row.picture}} -->
<el-image
style="width: 60px; height: 60px"
:src="scope.row.picture"
fit="fill"
></el-image>
</template>
</avue-crud> </avue-crud>
</basic-container> </basic-container>
</div> </div>
@ -69,8 +88,7 @@ export default {
type: "select", type: "select",
headerAlign: "center", headerAlign: "center",
align: "center", align: "center",
dicData: [ dicData: [],
],
props: { props: {
label: "label", label: "label",
value: "value", value: "value",
@ -94,33 +112,25 @@ export default {
return "无"; return "无";
} }
return value; return value;
} },
}, },
{ {
label: '图片', label: "图片",
prop: 'picture', prop: "picture",
type: 'upload', type: "upload",
headerAlign: "center", headerAlign: "center",
align: "center", align: "center",
loadText: "图片上传中,请稍等", loadText: "图片上传中,请稍等",
span: 12, span: 12,
tip: "只能上传jpg/png文件", tip: "只能上传jpg/png文件",
// rules: [{ hide: true,
// required: true, httpRequest: this.handleUpload,
// message: "",
// trigger: "change",
// }],
formatter: (row, column) => {
const value = row.picture;
if (value === null || value === undefined || value === "") {
return "无"
}
return value;
}, },
onSuccess: (res, file, fileList) => { {
this.form.picture = res.data label: "图片",
}, prop: "pictureImg",
httpRequest: this.handleUpload span: 12,
display: false,
}, },
], ],
}, },
@ -135,16 +145,20 @@ export default {
this.fetchMaterialCode(); this.fetchMaterialCode();
}, },
methods: { methods: {
uploadAfter(res, done, loading, column) {
console.log("上传成功", res, done, loading, column);
},
handleUpload(params) { handleUpload(params) {
const formData = new FormData() const formData = new FormData();
formData.append('file', params.file) formData.append("file", params.file);
upload(formData) upload(formData)
.then(res => { .then((res) => {
params.onSuccess(res) this.form.picture = res.data.message;
}) params.onSuccess(res);
.catch(err => {
params.onError(err)
}) })
.catch((err) => {
params.onError(err);
});
}, },
fetchMaterialCode() { fetchMaterialCode() {
getCode() getCode()
@ -152,17 +166,17 @@ export default {
const dicData = res.data.result.map((item) => ({ const dicData = res.data.result.map((item) => ({
label: item.name, label: item.name,
value: item.code, value: item.code,
})) }));
const targetColumn = this.option.column.find( const targetColumn = this.option.column.find(
(col) => col.prop === "materialCode" (col) => col.prop === "materialCode"
) );
if (targetColumn) { if (targetColumn) {
targetColumn.dicData = dicData targetColumn.dicData = dicData;
} }
}) })
.catch((error) => { .catch((error) => {
this.$message.error("加载类别数据失败,请刷新重试"); this.$message.error("加载类别数据失败,请刷新重试");
}) });
}, },
handleLog() { handleLog() {
this.dialogLogVisible = true; this.dialogLogVisible = true;
@ -219,7 +233,7 @@ export default {
window.console.log(error); window.console.log(error);
loading(); loading();
} }
) );
}, },
// //
rowUpdate(row, index, done, loading) { rowUpdate(row, index, done, loading) {

Loading…
Cancel
Save