Files
2026-07-07 18:02:29 +08:00

73 lines
1.8 KiB
JavaScript

import {
get,
post,
baseUrl
} from '@/utils/request.js'
import { useUserStore } from '@/store'
/**
* 请求单位工程
*/
export const reqProjectWorkArea = (projectId)=>get(`BaseInfo/getProjectWorkArea?projectId=${projectId}`)
/**
* 请求焊口位置
*/
export const reqWeldingLocation = ()=>get(`BaseInfo/getWeldingLocation`)
/**
* 根据项目ID单位类型请求单位
*/
export const reqUnitByProjectIdUnitType = (projectId, unitType="")=>get(`Unit/getUnitByProjectIdUnitType?projectId=${projectId}&unitType=${unitType}`)
/**
* 获取待办
*/
export const reqToDoItemByProjectIdUserId = (projectId, personId)=>get(`ToDoItem/getToDoItemByProjectIdUserId?projectId=${projectId}&personId=${personId}`)
/**
* 获取坡口类型列表
*/
export const reqGetGrooveTypeList = ()=>get(`BaseInfo/GetGrooveType`)
/**
* 附件上传
* @param {string} filePath - 本地文件路径
* @param {object} formData - 额外表单参数,如 { typeName: 'TestRecord', ... }
* @param {function} onProgress - 上传进度回调 (progress: number)
* @returns {Promise<array>} 返回服务器返回的附件地址数组
*/
export const uploadAttach = (filePath, formData = {}, onProgress) => {
return new Promise((resolve, reject) => {
const userStore = useUserStore()
const uploadTask = uni.uploadFile({
url: `${baseUrl}FileUpload/Post`,
filePath,
name: 'files',
formData,
header: {
'Content-Type': 'multipart/form-data',
'accept': 'application/json',
'token': userStore.token
},
success: (res) => {
try {
const data = JSON.parse(res.data)
resolve(data)
} catch (e) {
reject(new Error('解析上传响应失败'))
}
},
fail: (e) => {
reject(e)
}
})
if (onProgress) {
uploadTask.onProgressUpdate((res) => {
onProgress(res.progress)
})
}
})
}