feat: Add plant identification feature with image upload, classification results display, and integration into the wiki page.

This commit is contained in:
Blizzard
2026-02-10 14:02:35 +08:00
parent 6ea77c00ce
commit 6f88bc656b
15 changed files with 1481 additions and 491 deletions
+62 -1
View File
@@ -166,6 +166,67 @@ class WxRequest {
});
}
/**
* Upload file to a specific URL path
* @param {string} urlPath API path (e.g. '/classify/plant')
* @param {string} filePath Local file path
* @param {string} name Form field name (default: file)
* @param {Object} formData Additional form data
*/
uploadToUrl(urlPath, filePath, name = 'file', formData = {}) {
let config = {
url: this.baseUrl + urlPath,
header: { ...this.header },
filePath: filePath,
name: name,
formData: formData
};
config = this.interceptors.request(config);
return new Promise((resolve, reject) => {
wx.uploadFile({
url: config.url,
filePath: config.filePath,
name: config.name,
formData: config.formData,
header: config.header,
success: (res) => {
let data;
try {
data = JSON.parse(res.data);
} catch (e) {
data = { code: 500, msg: 'Response parse error', data: res.data };
}
const responseObj = { ...res, data: data };
const processedResponse = this.interceptors.response(responseObj);
const { statusCode, data: finalData } = processedResponse;
if (statusCode >= 200 && statusCode < 300) {
const businessCode = finalData.code;
if (businessCode === 200) {
resolve(finalData.data);
} else {
this.handleError({
errMsg: finalData.msg || 'Upload Error',
code: businessCode
});
reject(finalData);
}
} else {
this.handleError({ errMsg: `HTTP Error: ${statusCode}`, ...res });
reject(res);
}
},
fail: (err) => {
this.handleError({ errMsg: 'Upload Network Error', ...err });
reject(err);
}
});
});
}
get(url, data = {}, header = {}) {
return this.request({ url, method: 'GET', data, header });
}
@@ -178,7 +239,7 @@ class WxRequest {
// Initialize with default instance
const request = new WxRequest({
baseUrl: 'http://192.168.0.184:8889',
//baseUrl: 'https://prod.sundynix.cn/plant',
//baseUrl: 'https://go.sundynix.cn/api',
header: {
'Content-Type': 'application/json'
}