| | |
| | | <script setup> |
| | | import { ref, computed, watch, onMounted, onUnmounted, nextTick } from 'vue'; |
| | | import { getToken } from "@/utils/auth"; |
| | | import config from '@/config.js'; |
| | | |
| | | // Props 定义 |
| | | const props = defineProps({ |
| | | modelValue: [String, Object, Array], |
| | | action: { type: String, default: "/common/minioUploads" }, |
| | | action: { type: String, default: "/common/commonUploads" }, |
| | | data: { type: Object }, |
| | | limit: { type: Number, default: 5 }, |
| | | fileSize: { type: Number, default: 10 }, // 默认10MB,适合视频 |
| | |
| | | isShowTip: { type: Boolean, default: true }, |
| | | disabled: { type: Boolean, default: false }, |
| | | drag: { type: Boolean, default: false }, // 拍照不需要拖拽 |
| | | statusType: { type: Number, default: "" }, // 用于区分不同状态的上传 |
| | | type: { type: Number, default: "" }, // 用于区分不同状态的上传 |
| | | maxVideoDuration: { type: Number, default: 30 }, // 最大视频时长(秒) |
| | | }); |
| | | |
| | |
| | | |
| | | // 计算属性 |
| | | const uploadFileUrl = computed(() => { |
| | | // 获取基础API地址,适配uniapp环境 |
| | | let baseUrl = ''; |
| | | |
| | | // 尝试多种方式获取baseUrl |
| | | if (process.env.VUE_APP_BASE_API) { |
| | | baseUrl = process.env.VUE_APP_BASE_API; |
| | | } else if (process.env.NODE_ENV === 'development') { |
| | | baseUrl = 'http://192.168.1.147:9036'; |
| | | } else { |
| | | baseUrl = 'http://192.168.1.147:9036'; |
| | | } |
| | | |
| | | // 获取基础API地址,优先使用 config.js 中的 baseUrl |
| | | const baseUrl = config.baseUrl || process.env.VUE_APP_BASE_API || 'http://192.168.1.147:7016'; |
| | | const fullUrl = baseUrl + props.action; |
| | | console.log('上传URL:', fullUrl); |
| | | return fullUrl; |
| | | }); |
| | | const headers = computed(() => { |
| | |
| | | const testServerConnection = () => { |
| | | return new Promise((resolve) => { |
| | | uni.request({ |
| | | url: uploadFileUrl.value.replace('/common/minioUploads', '/common/test'), |
| | | url: uploadFileUrl.value.replace('/common/commonUploads', '/common/commonUploads'), |
| | | method: 'GET', |
| | | timeout: 5000, |
| | | success: (res) => { |
| | |
| | | filePath: filePath, |
| | | name: 'files', |
| | | formData: { |
| | | type: props.statusType || 0, |
| | | type: props.type || 0, |
| | | ...(props.data || {}) |
| | | }, |
| | | header: { |