迁移oa部分页面:施工进度和每日报工
This commit is contained in:
37
api/common/upload.js
Normal file
37
api/common/upload.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import { getToken } from '@/util/auth'
|
||||
|
||||
const BASE_URL = 'http://110.41.139.73:8080'
|
||||
|
||||
export function uploadImage(filePath) {
|
||||
console.log('[uploadImage] 开始上传:', filePath)
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.uploadFile({
|
||||
url: BASE_URL + '/system/oss/upload',
|
||||
filePath,
|
||||
name: 'file',
|
||||
header: {
|
||||
'Authorization': 'Bearer ' + getToken()
|
||||
},
|
||||
success: (res) => {
|
||||
console.log('[uploadImage] 上传响应:', res)
|
||||
try {
|
||||
const data = typeof res.data === 'string' ? JSON.parse(res.data) : res.data
|
||||
if (data.code === 200) {
|
||||
console.log('[uploadImage] 上传成功:', data.data)
|
||||
resolve(data.data) // { ossId, url }
|
||||
} else {
|
||||
console.error('[uploadImage] 上传失败:', data)
|
||||
reject(data.msg || '上传失败')
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[uploadImage] 解析返回数据失败:', e, res.data)
|
||||
reject('上传返回格式错误')
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('[uploadImage] 上传接口调用失败:', err)
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user