feat: 百科页面

This commit is contained in:
Blizzard
2026-02-10 09:20:24 +08:00
parent b800ea03b5
commit 6ea77c00ce
11 changed files with 476 additions and 196 deletions
+31 -9
View File
@@ -1,6 +1,7 @@
// pages/garden/add/index.js
import { MOCK_PLANTS, CARE_TASK_ICONS } from '../../../utils/mockData';
import request from '../../../utils/request';
import { requestSubscription, checkSubscriptionSettings } from '../../../utils/subscribe';
Page({
data: {
@@ -236,7 +237,6 @@ Page({
placement: newPlantLocation || '',
ossIds: [uploadedImageId],
carePlans: carePlans,
// Default fields as not in UI yet
potMaterial: '',
potSize: '',
sunlight: '',
@@ -245,18 +245,40 @@ Page({
// Submit
wx.showLoading({ title: 'Creating...' });
request.post('/plant/add', payload).then(res => {
request.post('/plant/add', payload).then(async () => {
wx.hideLoading();
wx.showToast({ title: '添加成功', icon: 'success' });
// Refresh previous page (e.g. garden list) if needed
// const pages = getCurrentPages();
// const prevPage = pages[pages.length - 2];
// if (prevPage && prevPage.onRefresh) prevPage.onRefresh();
// Smart Subscription Check
const subStatus = await checkSubscriptionSettings();
if (subStatus === 'accept') {
// Already authorized 'Always', just call API to consume quota
requestSubscription().finally(() => {
wx.navigateBack();
});
} else if (subStatus === 'reject' || subStatus === 'ban') {
// User rejected 'Always', do not disturb
setTimeout(() => wx.navigateBack(), 500);
} else {
// Not set, ask user
wx.showModal({
title: '添加成功',
content: '是否订阅植物养护提醒?',
confirmText: '订阅',
cancelText: '暂不',
success: (res) => {
if (res.confirm) {
requestSubscription().finally(() => {
wx.navigateBack();
});
} else {
wx.navigateBack();
}
}
});
}
setTimeout(() => {
wx.navigateBack();
}, 1000);
}).catch(err => {
wx.hideLoading();
console.error('Add plant failed', err);