feat(miniprogram): migrate invoice wallet mine and admin from bx-mobile.

Reuse invoice-wallets/invoices APIs with summary, upload, ledgers, and admin proxy upload.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
wuzilongandCursor committed 2026-09-11 23:37:40 +08:00
1 parent 4c24f58b63
commit 1bd0503409
5 files changed
+1491 -7

No files matched your search

+69
View File
@@ -171,4 +171,73 @@ export function bxUploadFile(filePath, opts = {}) {
})
}
/**
* 发票 multipart 上传(POST /invoices,name=files)
* 对齐 bx-mobile FormData:amount / remark / files / targetUserId
* @param {{ amount: number|string, remark?: string, filePath: string, targetUserId?: string|number, showError?: boolean }} opts
*/
export function bxUploadInvoice(opts = {}) {
const showError = opts.showError !== false
const token = uni.getStorageSync(TOKEN_KEY) || ''
const filePath = opts.filePath
if (!filePath) {
return Promise.reject(new Error('请选择发票文件'))
}
const formData = {
amount: String(opts.amount ?? '')
}
if (opts.remark != null && String(opts.remark).trim()) {
formData.remark = String(opts.remark).trim()
}
if (opts.targetUserId != null && opts.targetUserId !== '') {
formData.targetUserId = String(opts.targetUserId)
}
const url = `${API_BASE}/invoices`
return new Promise((resolve, reject) => {
uni.uploadFile({
url,
filePath,
name: 'files',
formData,
header: {
...(token ? { Authorization: `Bearer ${token}` } : {})
},
success: (res) => {
const status = res.statusCode
let body = res.data
if (typeof body === 'string') {
try {
body = JSON.parse(body)
} catch (e) {
body = {}
}
}
if (status === 401) {
onUnauthorized()
reject(new Error('登录已过期'))
return
}
if (status < 200 || status >= 300) {
const message = parseDetailMessage(body) || `上传失败(${status})`
if (showError) uni.showToast({ title: String(message).slice(0, 40), icon: 'none' })
reject(new Error(message))
return
}
if (body && body.code !== undefined && body.code !== 0) {
const message = body.msg || '上传失败'
if (showError) uni.showToast({ title: String(message).slice(0, 40), icon: 'none' })
reject(new Error(message))
return
}
resolve(body)
},
fail: (err) => {
if (showError) uni.showToast({ title: '上传失败', icon: 'none' })
reject(err)
}
})
})
}
export default bxRequest