feat: 后端版本迁移修改
This commit is contained in:
@@ -23,7 +23,7 @@ Page({
|
||||
const current = reset ? 1 : this.data.current;
|
||||
this.setData({ loading: true });
|
||||
|
||||
request.get('/plant/chat/history', { current, pageSize: this.data.pageSize })
|
||||
request.post('/plant/chat/history', { current, pageSize: this.data.pageSize })
|
||||
.then(res => {
|
||||
const items = (res.list || []).map(item => ({
|
||||
...item,
|
||||
@@ -82,7 +82,7 @@ Page({
|
||||
content: '确定删除这条问答记录吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
request.post('/plant/chat/history/delete', { id }).then(() => {
|
||||
request.post('/plant/chat/history/delete', { ids: [id] }).then(() => {
|
||||
wx.showToast({ title: '已删除', icon: 'success' });
|
||||
this.fetchHistory(true);
|
||||
});
|
||||
|
||||
@@ -96,7 +96,7 @@ Page({
|
||||
|
||||
request.stream('/plant/chat/stream', { query }, {
|
||||
onChunk: (res) => {
|
||||
const text = this._decode(res.data);
|
||||
const text = this._decode(res.chunk || res.data);
|
||||
|
||||
// Detect non-SSE JSON error (e.g. quota exceeded returns {code:7, msg:"..."})
|
||||
if (!text.startsWith('data: ')) {
|
||||
|
||||
+44
-39
@@ -26,10 +26,10 @@ Page({
|
||||
},
|
||||
|
||||
loadPlantDetail(id) {
|
||||
request.get('/wiki/detail', { id: id }).then(res => {
|
||||
request.get('/plant/wiki/detail', { id: id }).then(res => {
|
||||
const item = res || null;
|
||||
|
||||
if (!item) {
|
||||
if (!item || !item.wiki) {
|
||||
wx.showToast({ title: '未找到该植物', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
@@ -44,57 +44,62 @@ Page({
|
||||
setPlantData(item) {
|
||||
if (!item) return;
|
||||
|
||||
wx.setNavigationBarTitle({ title: item.name });
|
||||
// 兼容两种数据来源:
|
||||
// 1. 从 API 获取: {wiki: {name:...}, imgList: [...]}
|
||||
// 2. 从列表页导航: {id:..., name:..., imgList: [...]} (raw item)
|
||||
const wiki = item.wiki || item;
|
||||
|
||||
// Prepare swiper list
|
||||
wx.setNavigationBarTitle({ title: wiki.name });
|
||||
|
||||
// Prepare swiper list — imgList 在顶层
|
||||
const swiperList = (item.imgList || []).map(img => img.url);
|
||||
|
||||
// Parse lists
|
||||
const commonPests = item.pestsDiseases
|
||||
? item.pestsDiseases.split(',').map(s => s.trim()).filter(Boolean)
|
||||
const commonPests = wiki.pestsDiseases
|
||||
? wiki.pestsDiseases.split(',').map(s => s.trim()).filter(Boolean)
|
||||
: [];
|
||||
const aliasesList = item.aliases
|
||||
? item.aliases.split(/[,,、]/).map(s => s.trim()).filter(Boolean)
|
||||
const aliasesList = wiki.aliases
|
||||
? wiki.aliases.split(/[,,、]/).map(s => s.trim()).filter(Boolean)
|
||||
: [];
|
||||
const reproductionList = item.reproductionMethod
|
||||
? item.reproductionMethod.split(/[,,、]/).map(s => s.trim()).filter(Boolean)
|
||||
const reproductionList = wiki.reproductionMethod
|
||||
? wiki.reproductionMethod.split(/[,,、]/).map(s => s.trim()).filter(Boolean)
|
||||
: [];
|
||||
|
||||
const diffLabels = { 1: '简单', 2: '中等', 3: '较难', 4: '困难', 5: '专家' };
|
||||
|
||||
const plant = {
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
latinName: item.latinName || '',
|
||||
aliases: item.aliases || '',
|
||||
id: wiki.id,
|
||||
name: wiki.name,
|
||||
latinName: wiki.latinName || '',
|
||||
aliases: wiki.aliases || '',
|
||||
aliasesList,
|
||||
genus: item.genus || '',
|
||||
distributionArea: item.distributionArea || '',
|
||||
difficulty: item.difficulty || 0,
|
||||
difficultyLabel: diffLabels[item.difficulty] || '未知',
|
||||
isHot: item.isHot === 1,
|
||||
lifeCycle: item.lifeCycle || '',
|
||||
growthHabit: item.growthHabit || '',
|
||||
reproductionMethod: item.reproductionMethod || '',
|
||||
genus: wiki.genus || '',
|
||||
distributionArea: wiki.distributionArea || '',
|
||||
difficulty: wiki.difficulty || 0,
|
||||
difficultyLabel: diffLabels[wiki.difficulty] || '未知',
|
||||
isHot: wiki.isHot === true || wiki.isHot === 1,
|
||||
lifeCycle: wiki.lifeCycle || '',
|
||||
growthHabit: wiki.growthHabit || '',
|
||||
reproductionMethod: wiki.reproductionMethod || '',
|
||||
reproductionList,
|
||||
lightIntensity: item.lightIntensity || '',
|
||||
lightType: item.lightType || '',
|
||||
optimalTempPeriod: item.optimalTempPeriod || '',
|
||||
stem: item.stem || '',
|
||||
foliageType: item.foliageType || '',
|
||||
foliageColor: item.foliageColor || '',
|
||||
foliageShape: item.foliageShape || '',
|
||||
height: item.height || 0,
|
||||
floweringPeriod: item.floweringPeriod || '',
|
||||
floweringColor: item.floweringColor || '',
|
||||
floweringShape: item.floweringShape || '',
|
||||
flowerDiameter: item.flowerDiameter || 0,
|
||||
fruit: item.fruit || '',
|
||||
pestsDiseases: item.pestsDiseases || '',
|
||||
lightIntensity: wiki.lightIntensity || '',
|
||||
lightType: wiki.lightType || '',
|
||||
optimalTempPeriod: wiki.optimalTempPeriod || '',
|
||||
stem: wiki.stem || '',
|
||||
foliageType: wiki.foliageType || '',
|
||||
foliageColor: wiki.foliageColor || '',
|
||||
foliageShape: wiki.foliageShape || '',
|
||||
height: wiki.height || 0,
|
||||
floweringPeriod: wiki.floweringPeriod || '',
|
||||
floweringColor: wiki.floweringColor || '',
|
||||
floweringShape: wiki.floweringShape || '',
|
||||
flowerDiameter: wiki.floweringDiameter || 0,
|
||||
fruit: wiki.fruit || '',
|
||||
pestsDiseases: wiki.pestsDiseases || '',
|
||||
commonPests,
|
||||
classes: (item.classes || []).map(c => c.name),
|
||||
classes: (item.classIds || []).map(id => ({ id })),
|
||||
imgList: item.imgList || [],
|
||||
isFavorited: (item.hasStar === 1 || item.hasStar === '1')
|
||||
isFavorited: wiki.isStar === true || wiki.isStar === 1
|
||||
};
|
||||
|
||||
this.setData({
|
||||
@@ -109,7 +114,7 @@ Page({
|
||||
const { id, isFavorited } = this.data.plant;
|
||||
const type = isFavorited ? 2 : 1;
|
||||
|
||||
request.get('/wiki/star', { id, type }).then(() => {
|
||||
request.get('/plant/wiki/star', { id, type }).then(() => {
|
||||
const newStatus = !isFavorited;
|
||||
this.setData({
|
||||
'plant.isFavorited': newStatus
|
||||
|
||||
@@ -24,10 +24,13 @@ Page({
|
||||
this.classifyPlant(imagePath);
|
||||
},
|
||||
|
||||
classifyPlant(filePath) {
|
||||
async classifyPlant(filePath) {
|
||||
this.setData({ isLoading: true, hasError: false });
|
||||
|
||||
request.uploadToUrl('/classify/plant', filePath, 'file').then(res => {
|
||||
try {
|
||||
// Directly upload file to classify endpoint without uploading to MinIO file service
|
||||
const res = await request.uploadToUrl('/plant/classify/plant', filePath);
|
||||
|
||||
const results = res.result || [];
|
||||
|
||||
// Map results with percentage scores
|
||||
@@ -46,10 +49,10 @@ Page({
|
||||
topResult: mappedResults.length > 0 ? mappedResults[0] : null,
|
||||
isLoading: false
|
||||
});
|
||||
}).catch(err => {
|
||||
} catch (err) {
|
||||
console.error('Classify failed', err);
|
||||
this.setData({ isLoading: false, hasError: true });
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// Retry identification
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<view class="state-card">
|
||||
<view class="loading-image-wrap">
|
||||
<image src="{{imagePath}}" mode="aspectFill" class="loading-preview" bindtap="previewImage" />
|
||||
<view class="scan-overlay"></view>
|
||||
<view class="scan-line"></view>
|
||||
</view>
|
||||
<view class="loading-info">
|
||||
|
||||
@@ -44,21 +44,38 @@
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Scan line animation */
|
||||
/* Scan overlay breathing effect */
|
||||
.scan-overlay {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: linear-gradient(180deg, rgba(85, 139, 47, 0) 30%, rgba(85, 139, 47, 0.15) 100%);
|
||||
animation: pulseBg 2s ease-in-out infinite alternate;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@keyframes pulseBg {
|
||||
0% { opacity: 0.2; }
|
||||
100% { opacity: 0.65; }
|
||||
}
|
||||
|
||||
/* Premium neon scan line animation */
|
||||
.scan-line {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 4rpx;
|
||||
background: linear-gradient(90deg, transparent, #558B2F, transparent);
|
||||
animation: scan 2s ease-in-out infinite;
|
||||
box-shadow: 0 0 16rpx rgba(85, 139, 47, 0.5);
|
||||
height: 8rpx;
|
||||
background: linear-gradient(90deg, rgba(85, 139, 47, 0) 0%, rgba(139, 195, 74, 1) 50%, rgba(85, 139, 47, 0) 100%);
|
||||
animation: scan 2.2s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite;
|
||||
box-shadow: 0 0 20rpx rgba(139, 195, 74, 0.9), 0 0 40rpx rgba(85, 139, 47, 0.5);
|
||||
}
|
||||
|
||||
@keyframes scan {
|
||||
0% { top: 0; }
|
||||
50% { top: 100%; }
|
||||
100% { top: 0; }
|
||||
0% { top: 0%; opacity: 0.8; }
|
||||
50% { top: 98%; opacity: 1; }
|
||||
100% { top: 0%; opacity: 0.8; }
|
||||
}
|
||||
|
||||
.loading-info {
|
||||
|
||||
+5
-5
@@ -50,7 +50,7 @@ Page({
|
||||
|
||||
// Fetch categories from API
|
||||
fetchCategories() {
|
||||
request.get('/wiki-class/list').then(res => {
|
||||
request.get('/plant/wiki-class/list').then(res => {
|
||||
const list = (res && res.list) || (Array.isArray(res) ? res : []);
|
||||
this.setData({ categories: list });
|
||||
}).catch(err => {
|
||||
@@ -83,7 +83,7 @@ Page({
|
||||
params.classId = [this.data.activeCategory];
|
||||
}
|
||||
|
||||
return request.post('/wiki/page', params).then(res => {
|
||||
return request.post('/plant/wiki/page', params).then(res => {
|
||||
const data = res || {};
|
||||
const list = data.list || [];
|
||||
const total = data.total || 0;
|
||||
@@ -96,8 +96,8 @@ Page({
|
||||
aliases: item.aliases || '',
|
||||
genus: item.genus || '',
|
||||
difficulty: item.difficulty || 0,
|
||||
isHot: item.isHot === 1,
|
||||
isFavorited: item.hasStar === 1,
|
||||
isHot: item.isHot === true || item.isHot === 1,
|
||||
isFavorited: item.hasStar === 1 || item.hasStar === '1',
|
||||
image: (item.imgList && item.imgList.length > 0) ? item.imgList[0].url : '',
|
||||
classes: (item.classes || []).map(c => c.name),
|
||||
// Pass the full item for detail navigation
|
||||
@@ -140,7 +140,7 @@ Page({
|
||||
|
||||
try {
|
||||
// Attempting consistent API pattern
|
||||
await request.get('/wiki/star', { id, type });
|
||||
await request.get('/plant/wiki/star', { id, type });
|
||||
|
||||
const key = `displayedList[${index}].isFavorited`;
|
||||
this.setData({
|
||||
|
||||
Reference in New Issue
Block a user