From ba9ed8d700bfcc14acf5a9c92fe1e932702bb569 Mon Sep 17 00:00:00 2001 From: zhouyanli <593579392@qq.com> Date: Thu, 30 Apr 2026 14:31:20 +0800 Subject: [PATCH] =?UTF-8?q?request=E9=87=8C=E7=9A=84upload=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pageSubPack/api/request.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/property-uniapp-project/pageSubPack/api/request.js b/property-uniapp-project/pageSubPack/api/request.js index d26d509..3ef8483 100644 --- a/property-uniapp-project/pageSubPack/api/request.js +++ b/property-uniapp-project/pageSubPack/api/request.js @@ -104,3 +104,32 @@ export const get = (url, data) => request(url, data, 'GET'); export const post = (url, data) => request(url, data, 'POST'); export const deleteMethod = (url, data) => request(url, data, 'DELETE'); export const putMethod = (url, data) => request(url, data, 'PUT'); +// 通用文件上传 +export const upload = (filePath, url) => { + return new Promise((resolve, reject) => { + uni.uploadFile({ + url: baseUrl + url, + filePath: filePath, + name: 'file', + header: { + "Authorization": "Bearer " + (uni.getStorageSync("token") || ''), + "clientid": "resident" + }, + success: (res) => { + if (res.statusCode === 200) { + const data = JSON.parse(res.data); + if (data.code === 200) { + resolve(data); + } else { + reject(data.msg || '上传失败'); + } + } else { + reject('上传失败'); + } + }, + fail: (err) => { + reject(err); + } + }); + }); +}; \ No newline at end of file