优化代码生成上传图片

This commit is contained in:
不做码农 2021-12-07 22:41:49 +08:00
parent cf43e9d077
commit c169ec18cd
2 changed files with 37 additions and 29 deletions

View File

@ -105,7 +105,7 @@ namespace ZR.CodeGenerator
//图片
sb.AppendLine(" <el-col :span=\"24\">");
sb.AppendLine($" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">");
sb.AppendLine($@" <UploadImage :icon=""form.{columnName}"" column='{columnName}' :key=""form.{columnName}"" @handleUploadSuccess=""handleUploadSuccess"" />");
sb.AppendLine($@" <UploadImage v-model=""form.{columnName}"" column=""{columnName}"" @input=""handleUploadSuccess"" />");
sb.AppendLine(" </el-form-item>");
sb.AppendLine(" </el-col>");
}
@ -160,7 +160,7 @@ namespace ZR.CodeGenerator
sb.AppendLine(" <el-col :span=\"12\">");
sb.AppendLine($" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">");
sb.AppendLine($" <el-select v-model=\"form.{columnName}\">");
sb.AppendLine($" <el-option label=\"\"></el-option>");
sb.AppendLine($" <el-option label=\"\" value=\"\"></el-option>");
sb.AppendLine(" </el-select>");
sb.AppendLine(" </el-form-item>");
sb.AppendLine(" </el-col>");

View File

@ -12,7 +12,27 @@
import { getToken } from "@/utils/auth";
export default {
name: "UploadImage",
props: {
value: [String],
column: [String],
//
uploadUrl: {
type: String,
default: "/Common/UploadFile",
},
// , ['png', 'jpg', 'jpeg']
fileType: {
type: Array,
default: () => ["png", "jpg", "jpeg", "webp"],
},
// (MB)
fileSize: {
type: Number,
default: 5,
},
//
showInput: false,
},
data() {
return {
uploadImgUrl: process.env.VUE_APP_BASE_API + this.uploadUrl, //
@ -22,40 +42,29 @@ export default {
imageUrl: "",
};
},
props: {
icon: {
type: String,
watch: {
// v-model
value: {
immediate: true,
deep: true,
handler: function (val) {
if (val) {
this.imageUrl = val;
} else {
this.imageUrl = "";
}
},
},
// form
column: { type: String },
//
uploadUrl: {
type: String,
default: "Common/UploadFile",
},
// , ['png', 'jpg', 'jpeg']
fileType: {
type: Array,
default: () => ["png", "jpg", "jpeg"],
},
// (MB)
fileSize: {
type: Number,
default: 5,
},
},
mounted() {
this.imageUrl = this.icon;
},
methods: {
handleUploadSuccess(res) {
this.$emit(`handleUploadSuccess`, res, this.column);
this.$emit(`input`, res, this.column);
this.imageUrl = res.data;
this.loading.close();
},
// loading
handleBeforeUpload(file) {
console.log(file)
console.log(file);
let isImg = false;
if (this.fileType.length) {
let fileExtension = "";
@ -98,7 +107,6 @@ export default {
this.loading.close();
},
},
watch: {},
};
</script>