feat(M08-B): 补保洁照片上传和自动建单

This commit is contained in:
Codex
2026-06-26 15:36:05 +08:00
parent f7e0c8d063
commit fe1a08880e
16 changed files with 373 additions and 57 deletions
+45
View File
@@ -26,6 +26,43 @@ function request(path, options = {}) {
})
}
function uploadImage(path, filePath, headers = {}) {
return new Promise((resolve, reject) => {
const token = wx.getStorageSync(TOKEN_KEY)
wx.getFileSystemManager().readFile({
filePath,
success(result) {
wx.request({
url: `${APP_API_BASE_URL}${path}`,
method: 'POST',
data: result.data,
header: {
'x-wechat-appid': WECHAT_APP_ID,
'x-file-name': filePath.split('/').pop() || `cleaning-${Date.now()}.jpg`,
'x-image-content-type': guessImageType(filePath),
'content-type': 'application/octet-stream',
...(token ? { authorization: `Bearer ${token}` } : {}),
...(headers || {}),
},
success(response) {
if (response.statusCode >= 200 && response.statusCode < 300) {
try {
resolve(typeof response.data === 'string' ? JSON.parse(response.data) : response.data)
} catch (error) {
reject(error)
}
return
}
reject(new Error(response.data?.message || `上传失败:${response.statusCode}`))
},
fail: reject,
})
},
fail: reject,
})
})
}
function login() {
return new Promise((resolve, reject) => {
wx.login({
@@ -82,8 +119,16 @@ function requestWechatPayment(params) {
})
}
function guessImageType(filePath) {
const lower = String(filePath || '').toLowerCase()
if (lower.endsWith('.png')) return 'image/png'
if (lower.endsWith('.webp')) return 'image/webp'
return 'image/jpeg'
}
module.exports = {
request,
uploadImage,
login,
ensureLogin,
clearSession,