增强办公

This commit is contained in:
2026-04-17 12:07:27 +08:00
parent ed75298558
commit e76028bf43
17 changed files with 1008 additions and 2309 deletions

View File

@@ -1,7 +1,5 @@
import { getToken } from '@/util/auth'
import request from "@/util/oaRequest"
const BASE_URL = 'http://110.41.139.73:8080'
import request, { BASE_URL } from "@/util/oaRequest"
export function uploadImage(filePath) {
console.log('[uploadImage] 开始上传:', filePath)
@@ -53,81 +51,74 @@ export function uploadImage(filePath) {
export function uploadFile(file, options = {}) {
const {
allowedTypes = ['doc', 'xls', 'ppt', 'txt', 'pdf', 'docx', 'xlsx', 'png', 'jpg', 'jpeg', 'zip', 'rar', '7z', 'dwg'],
maxSize = 200, // 默认200MB
maxSize = 200,
extraData = 1
} = options
return new Promise((resolve, reject) => {
// 文件类型验证
const ext = file.name.split('.').pop().toLowerCase()
if (allowedTypes && !allowedTypes.includes(ext)) {
reject(new Error(`文件格式不正确,请上传${allowedTypes.join('/')}格式文件!`))
return
}
const fileName = file?.name || file?.fileName || file?.originalName || ''
const filePath = file?.path || file?.tempFilePath || file?.url || file?.filePath || ''
const fileSize = Number(file?.size || 0)
// 文件大小验证
if (maxSize && file.size / 1024 / 1024 > maxSize) {
reject(new Error(`上传文件大小不能超过 ${maxSize} MB`))
return
}
console.log('[uploadFile] 入参:', { fileName, filePath, fileSize, type: file?.type, raw: file })
// 验证文件路径
if (!file.path) {
if (!filePath) {
reject(new Error('文件路径为空'))
return
}
console.log('[uploadFile] 开始上传文件:', {
name: file.name,
size: file.size,
path: file.path,
type: file.type
})
const ext = (fileName.split('.').pop() || '').toLowerCase()
if (allowedTypes && ext && !allowedTypes.includes(ext)) {
reject(new Error(`文件格式不正确,请上传 ${allowedTypes.join('/')} 格式文件!`))
return
}
// 处理文件路径(安卓平台)
let filePath = file.path
if (maxSize && fileSize > 0 && fileSize / 1024 / 1024 > maxSize) {
reject(new Error(`上传文件大小不能超过 ${maxSize} MB`))
return
}
let realPath = filePath
// #ifdef APP-PLUS
if (typeof plus !== 'undefined' && plus.io) {
if (!filePath.startsWith('/') && !filePath.startsWith('file://')) {
filePath = plus.io.convertLocalFileSystemURL(filePath)
if (typeof plus !== 'undefined' && plus.io && realPath && !realPath.startsWith('file://') && !realPath.startsWith('/')) {
try {
realPath = plus.io.convertLocalFileSystemURL(realPath)
} catch (e) {
console.warn('[uploadFile] 路径转换失败,使用原始路径', e)
}
}
// #endif
console.log('[uploadFile] 开始上传文件:', { fileName, realPath, fileSize, type: file?.type })
uni.uploadFile({
url: BASE_URL + '/system/oss/upload',
filePath,
filePath: realPath,
name: 'file',
formData: {
isPublic: extraData
},
header: {
'Authorization': 'Bearer ' + getToken()
},
formData: { isPublic: extraData },
header: { Authorization: 'Bearer ' + getToken() },
success: (res) => {
console.log('[uploadFile] 上传响应:', res)
try {
const data = typeof res.data === 'string' ? JSON.parse(res.data) : res.data
if (data.code === 200) {
console.log('[uploadFile] 上传成功:', data.data)
resolve({
ossId: data.data.ossId,
url: data.data.url,
fileName: data.data.fileName,
originalName: file.name
originalName: fileName
})
} else {
console.error('[uploadFile] 上传失败:', data)
reject(data.msg || '上传失败')
reject(new Error(data.msg || '上传失败'))
}
} catch (e) {
console.error('[uploadFile] 解析返回数据失败:', e, res.data)
reject('上传返回格式错误')
reject(new Error('上传返回格式错误'))
}
},
fail: (err) => {
console.error('[uploadFile] 上传接口调用失败:', err)
reject(err)
reject(new Error(err?.errMsg || err?.message || '上传失败'))
}
})
})
@@ -139,7 +130,7 @@ export function uploadFile(file, options = {}) {
* @param {Object} options - 上传选项
* @returns {Promise} 返回上传结果数组
*/
export function uploadFiles(files, options = {}) {
export async function uploadFiles(files, options = {}) {
const {
allowedTypes = ['doc', 'xls', 'ppt', 'txt', 'pdf', 'docx', 'xlsx', 'png', 'jpg', 'jpeg', 'zip', 'rar', '7z', 'dwg'],
maxSize = 200,
@@ -205,7 +196,7 @@ export function listByIds(ossId) {
* @param {Array} ossIds - OSS ID数组
* @returns {Promise} 返回文件信息数组
*/
export function getFilesByIds(ossIds) {
export async function getFilesByIds(ossIds) {
if (!ossIds || ossIds.length === 0) {
return Promise.resolve([])
}