Browse Source

feat: 修改上传地址

DESKTOP-USV654P\pc 3 months ago
parent
commit
71dcdf8bf6

+ 16 - 9
apps/web-baicai/src/components/form/components/bc-upload.vue

@@ -5,6 +5,7 @@ import type { PropType } from 'vue';
 
 
 import { computed, onMounted, reactive, ref, watch } from 'vue';
 import { computed, onMounted, reactive, ref, watch } from 'vue';
 
 
+import { useAppConfig } from '@vben/hooks';
 import { useAccessStore } from '@vben/stores';
 import { useAccessStore } from '@vben/stores';
 
 
 import { Button, message, Upload } from 'ant-design-vue';
 import { Button, message, Upload } from 'ant-design-vue';
@@ -12,17 +13,11 @@ import { Button, message, Upload } from 'ant-design-vue';
 import { FileApi } from '#/api';
 import { FileApi } from '#/api';
 import { Icon } from '#/components/icon';
 import { Icon } from '#/components/icon';
 
 
-type UploadParams = {
-  allowSuffix: string;
-  directory: string;
-  folderId: Number | String;
-  path: string;
-};
-
 defineOptions({
 defineOptions({
   name: 'Upload',
   name: 'Upload',
   inheritAttrs: false,
   inheritAttrs: false,
 });
 });
+
 const props = defineProps({
 const props = defineProps({
   value: {
   value: {
     type: [Number, String] as PropType<number | string>,
     type: [Number, String] as PropType<number | string>,
@@ -31,7 +26,7 @@ const props = defineProps({
   action: {
   action: {
     // 上传的地址
     // 上传的地址
     type: String,
     type: String,
-    default: `${import.meta.env.VITE_GLOB_API_URL}/file/upload`,
+    default: '',
   },
   },
   headers: {
   headers: {
     // 上传请求的 headers
     // 上传请求的 headers
@@ -64,6 +59,14 @@ const props = defineProps({
   },
   },
 });
 });
 const emits = defineEmits(['update:modelValue']);
 const emits = defineEmits(['update:modelValue']);
+const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD);
+type UploadParams = {
+  allowSuffix: string;
+  directory: string;
+  folderId: Number | String;
+  path: string;
+};
+
 const accessStore = useAccessStore();
 const accessStore = useAccessStore();
 const fileList = ref<UploadFile[]>([]);
 const fileList = ref<UploadFile[]>([]);
 // const attrs = useAttrs();
 // const attrs = useAttrs();
@@ -74,6 +77,10 @@ const bindProps = computed(() => {
     name: props.uploadName || 'file',
     name: props.uploadName || 'file',
   };
   };
 });
 });
+
+const getAction = computed(() => {
+  return props.action ?? `${apiURL}/file/upload`;
+});
 const getFileList = async (val: number | string | undefined) => {
 const getFileList = async (val: number | string | undefined) => {
   if (!val) {
   if (!val) {
     if (fileList.value.length > 0) fileList.value = [];
     if (fileList.value.length > 0) fileList.value = [];
@@ -160,7 +167,7 @@ onMounted(async () => {
   <Upload
   <Upload
     v-model:file-list="fileList"
     v-model:file-list="fileList"
     v-bind="bindProps"
     v-bind="bindProps"
-    :action="action"
+    :action="getAction"
     :data="uploadParams"
     :data="uploadParams"
     :disabled="disabled"
     :disabled="disabled"
     :headers="getHeaders"
     :headers="getHeaders"

+ 4 - 1
apps/web-baicai/src/views/system/personal/components/update-avatar.vue

@@ -4,6 +4,7 @@ import type { UploadChangeParam } from 'ant-design-vue';
 import { computed } from 'vue';
 import { computed } from 'vue';
 
 
 import { alert } from '@vben/common-ui';
 import { alert } from '@vben/common-ui';
+import { useAppConfig } from '@vben/hooks';
 import { useAccessStore, useUserStore } from '@vben/stores';
 import { useAccessStore, useUserStore } from '@vben/stores';
 
 
 import { Avatar, Upload } from 'ant-design-vue';
 import { Avatar, Upload } from 'ant-design-vue';
@@ -19,8 +20,10 @@ defineProps({
 const accessStore = useAccessStore();
 const accessStore = useAccessStore();
 const userStore = useUserStore();
 const userStore = useUserStore();
 
 
+const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD);
+
 const getAction = computed(() => {
 const getAction = computed(() => {
-  return `${import.meta.env.VITE_GLOB_API_URL}/user/avatar`;
+  return `${apiURL}/user/avatar`;
 });
 });
 const headers = {
 const headers = {
   Authorization: `Bearer ${accessStore.accessToken}`,
   Authorization: `Bearer ${accessStore.accessToken}`,