mirror of
https://github.com/yangzongzhuan/RuoYi-Vue3.git
synced 2025-09-27 14:52:40 +00:00
支持文件&图片组件自定义地址&参数
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
:action="uploadFileUrl"
|
:action="uploadFileUrl"
|
||||||
:before-upload="handleBeforeUpload"
|
:before-upload="handleBeforeUpload"
|
||||||
:file-list="fileList"
|
:file-list="fileList"
|
||||||
|
:data="data"
|
||||||
:limit="limit"
|
:limit="limit"
|
||||||
:on-error="handleUploadError"
|
:on-error="handleUploadError"
|
||||||
:on-exceed="handleExceed"
|
:on-exceed="handleExceed"
|
||||||
@@ -44,6 +45,15 @@ import { getToken } from "@/utils/auth";
|
|||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
modelValue: [String, Object, Array],
|
modelValue: [String, Object, Array],
|
||||||
|
// 上传接口地址
|
||||||
|
action: {
|
||||||
|
type: String,
|
||||||
|
default: "/common/upload"
|
||||||
|
},
|
||||||
|
// 上传携带的参数
|
||||||
|
data: {
|
||||||
|
type: Object
|
||||||
|
},
|
||||||
// 数量限制
|
// 数量限制
|
||||||
limit: {
|
limit: {
|
||||||
type: Number,
|
type: Number,
|
||||||
@@ -76,7 +86,7 @@ const emit = defineEmits();
|
|||||||
const number = ref(0);
|
const number = ref(0);
|
||||||
const uploadList = ref([]);
|
const uploadList = ref([]);
|
||||||
const baseUrl = import.meta.env.VITE_APP_BASE_API;
|
const baseUrl = import.meta.env.VITE_APP_BASE_API;
|
||||||
const uploadFileUrl = ref(import.meta.env.VITE_APP_BASE_API + "/common/upload"); // 上传文件服务器地址
|
const uploadFileUrl = ref(import.meta.env.VITE_APP_BASE_API + props.action); // 上传文件服务器地址
|
||||||
const headers = ref({ Authorization: "Bearer " + getToken() });
|
const headers = ref({ Authorization: "Bearer " + getToken() });
|
||||||
const fileList = ref([]);
|
const fileList = ref([]);
|
||||||
const showTip = computed(
|
const showTip = computed(
|
||||||
@@ -140,6 +150,7 @@ function handleExceed() {
|
|||||||
// 上传失败
|
// 上传失败
|
||||||
function handleUploadError(err) {
|
function handleUploadError(err) {
|
||||||
proxy.$modal.msgError("上传文件失败");
|
proxy.$modal.msgError("上传文件失败");
|
||||||
|
proxy.$modal.closeLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 上传成功回调
|
// 上传成功回调
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
list-type="picture-card"
|
list-type="picture-card"
|
||||||
:on-success="handleUploadSuccess"
|
:on-success="handleUploadSuccess"
|
||||||
:before-upload="handleBeforeUpload"
|
:before-upload="handleBeforeUpload"
|
||||||
|
:data="data"
|
||||||
:limit="limit"
|
:limit="limit"
|
||||||
:on-error="handleUploadError"
|
:on-error="handleUploadError"
|
||||||
:on-exceed="handleExceed"
|
:on-exceed="handleExceed"
|
||||||
@@ -51,6 +52,15 @@ import { isExternal } from "@/utils/validate";
|
|||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
modelValue: [String, Object, Array],
|
modelValue: [String, Object, Array],
|
||||||
|
// 上传接口地址
|
||||||
|
action: {
|
||||||
|
type: String,
|
||||||
|
default: "/common/upload"
|
||||||
|
},
|
||||||
|
// 上传携带的参数
|
||||||
|
data: {
|
||||||
|
type: Object
|
||||||
|
},
|
||||||
// 图片数量限制
|
// 图片数量限制
|
||||||
limit: {
|
limit: {
|
||||||
type: Number,
|
type: Number,
|
||||||
@@ -80,7 +90,7 @@ const uploadList = ref([]);
|
|||||||
const dialogImageUrl = ref("");
|
const dialogImageUrl = ref("");
|
||||||
const dialogVisible = ref(false);
|
const dialogVisible = ref(false);
|
||||||
const baseUrl = import.meta.env.VITE_APP_BASE_API;
|
const baseUrl = import.meta.env.VITE_APP_BASE_API;
|
||||||
const uploadImgUrl = ref(import.meta.env.VITE_APP_BASE_API + "/common/upload"); // 上传的图片服务器地址
|
const uploadImgUrl = ref(import.meta.env.VITE_APP_BASE_API + props.action); // 上传的图片服务器地址
|
||||||
const headers = ref({ Authorization: "Bearer " + getToken() });
|
const headers = ref({ Authorization: "Bearer " + getToken() });
|
||||||
const fileList = ref([]);
|
const fileList = ref([]);
|
||||||
const showTip = computed(
|
const showTip = computed(
|
||||||
|
Reference in New Issue
Block a user