feat: 百科页面
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user