feat: login rest

This commit is contained in:
Blizzard
2026-02-12 09:26:39 +08:00
parent e97fd30fa3
commit 5553e2711a
115 changed files with 4090 additions and 3499 deletions
+103
View File
@@ -0,0 +1,103 @@
import request from '../../../utils/request';
Page({
data: {
plantId: '',
recordType: 'growth',
content: '',
image: ''
},
onLoad(options) {
if (options.plantId) {
this.setData({ plantId: options.plantId });
}
},
setRecordType(e) {
const type = e.currentTarget.dataset.type;
this.setData({ recordType: type });
},
onContentInput(e) {
this.setData({ content: e.detail.value });
},
handleChooseImage() {
wx.chooseMedia({
count: 1,
mediaType: ['image'],
sourceType: ['album', 'camera'],
success: (res) => {
this.setData({
image: res.tempFiles[0].tempFilePath
});
}
});
},
handleRemoveImage() {
this.setData({ image: '' });
},
async handleAddRecord() {
if (!this.data.content.trim()) {
wx.showToast({ title: '请填写备注', icon: 'none' });
return;
}
if (!this.data.plantId) {
wx.showToast({ title: '缺少植物ID', icon: 'none' });
return;
}
wx.showLoading({ title: '保存中...', mask: true });
try {
let ossIds = [];
// 1. Upload Image if exists
if (this.data.image) {
const uploadRes = await request.upload(this.data.image);
// Correctly extract ID from nested 'file' object based on API response
if (uploadRes && uploadRes.file && uploadRes.file.id) {
ossIds.push(uploadRes.file.id);
} else if (uploadRes && uploadRes.id) {
// Fallback just in case
ossIds.push(uploadRes.id);
} else {
console.warn('Upload response structure mismatch:', uploadRes);
}
}
// 2. Prepare payload
const mapTitle = { growth: '生长记录', repot: '换盆记录', pest: '病虫害记录', other: '日常记录' };
const title = mapTitle[this.data.recordType] || '日常记录';
const payload = {
plantId: this.data.plantId,
ossIds: ossIds,
name: title,
tag: this.data.recordType,
desc: this.data.content.substring(0, 100),
content: this.data.content
};
// 3. Call Add API
await request.post('/plant/growth/add', payload);
wx.hideLoading();
wx.showToast({ title: '保存成功', icon: 'success' });
// 4. Navigate back, detail page will refresh in onShow
setTimeout(() => {
wx.navigateBack();
}, 1000);
} catch (err) {
wx.hideLoading();
console.error('Add record failed', err);
}
}
});
@@ -0,0 +1,11 @@
{
"navigationBarTitleText": "添加成长记录",
"navigationBarBackgroundColor": "#FFFFFF",
"navigationBarTextStyle": "black",
"backgroundColor": "#F4F6F0",
"usingComponents": {
"t-icon": "tdesign-miniprogram/icon/icon",
"t-image": "tdesign-miniprogram/image/image",
"t-button": "tdesign-miniprogram/button/button"
}
}
@@ -0,0 +1,61 @@
<view class="growth-record-page">
<view class="form-container">
<!-- Record Type -->
<view class="form-group">
<text class="form-label">记录类型</text>
<view class="chip-group">
<view class="chip {{recordType === 'growth' ? 'active' : ''}}" bindtap="setRecordType" data-type="growth">
<t-icon name="thumb-up" size="32rpx" />
<text>生长</text>
</view>
<view class="chip {{recordType === 'repot' ? 'active' : ''}}" bindtap="setRecordType" data-type="repot">
<t-icon name="swap" size="32rpx" />
<text>换盆</text>
</view>
<view class="chip {{recordType === 'pest' ? 'active' : ''}}" bindtap="setRecordType" data-type="pest">
<t-icon name="error-circle" size="32rpx" />
<text>病虫害</text>
</view>
<view class="chip {{recordType === 'other' ? 'active' : ''}}" bindtap="setRecordType" data-type="other">
<t-icon name="file" size="32rpx" />
<text>其他</text>
</view>
</view>
</view>
<!-- Content -->
<view class="form-group">
<text class="form-label">备注</text>
<textarea
class="form-textarea"
placeholder="记录这一刻的变化..."
value="{{content}}"
bindinput="onContentInput"
maxlength="500"
auto-height
/>
</view>
<!-- Image Upload -->
<view class="form-group">
<text class="form-label">添加照片</text>
<view class="record-image-upload">
<view wx:if="{{image}}" class="uploaded-image-box">
<t-image src="{{image}}" mode="aspectFill" width="200rpx" height="200rpx" shape="round" />
<view class="remove-img-btn" bindtap="handleRemoveImage">
<t-icon name="close" size="32rpx" color="#FFF" />
</view>
</view>
<view wx:else class="upload-add-btn" bindtap="handleChooseImage">
<t-icon name="add" size="64rpx" color="#999" />
</view>
</view>
</view>
</view>
<view class="footer-action">
<view class="submit-btn" bindtap="handleAddRecord">
<text>保存记录</text>
</view>
</view>
</view>
+159
View File
@@ -0,0 +1,159 @@
/* pages/plant-detail/growth-record/index.wxss */
page {
background: #F4F6F0;
}
.growth-record-page {
padding: 32rpx;
padding-bottom: 160rpx;
}
.form-container {
background: white;
border-radius: 32rpx;
padding: 32rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.03);
}
.form-group {
margin-bottom: 48rpx;
}
.form-group:last-child {
margin-bottom: 0;
}
.form-label {
display: block;
font-size: 30rpx;
font-weight: 600;
color: #333;
margin-bottom: 24rpx;
}
/* Chip Styles */
.chip-group {
display: flex;
flex-wrap: wrap;
gap: 20rpx;
}
.chip {
padding: 20rpx 32rpx;
background: #F5F5F5;
border-radius: 40rpx;
font-size: 28rpx;
color: #666;
display: flex;
align-items: center;
gap: 12rpx;
border: 2rpx solid transparent;
transition: all 0.2s;
}
.chip.active {
background: #E8F5E9;
color: #558B2F;
border-color: #558B2F;
font-weight: 600;
}
.chip:active {
transform: scale(0.96);
}
/* Textarea */
.form-textarea {
width: 100%;
min-height: 200rpx;
padding: 24rpx;
border: 2rpx solid #e0e0e0;
border-radius: 24rpx;
font-size: 30rpx;
box-sizing: border-box;
background: #FAFAFA;
line-height: 1.6;
}
.form-textarea:focus {
background: white;
border-color: #558B2F;
box-shadow: 0 0 0 6rpx rgba(85, 139, 47, 0.1);
}
/* Image Upload */
.record-image-upload {
display: flex;
flex-wrap: wrap;
gap: 24rpx;
}
.upload-add-btn {
width: 200rpx;
height: 200rpx;
background: #FAFAFA;
border: 2rpx dashed #d9d9d9;
border-radius: 24rpx;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s;
}
.upload-add-btn:active {
background: #F0F0F0;
border-color: #558B2F;
}
.uploaded-image-box {
position: relative;
width: 200rpx;
height: 200rpx;
}
.remove-img-btn {
position: absolute;
top: -16rpx;
right: -16rpx;
width: 44rpx;
height: 44rpx;
background: rgba(0, 0, 0, 0.5);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
z-index: 10;
backdrop-filter: blur(4rpx);
}
/* Footer Action */
.footer-action {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding: 32rpx;
background: white;
box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.05);
z-index: 100;
padding-bottom: calc(32rpx + env(safe-area-inset-bottom));
}
.submit-btn {
width: 100%;
height: 96rpx;
background: linear-gradient(135deg, #689F38, #558B2F);
border-radius: 48rpx;
color: white;
display: flex;
align-items: center;
justify-content: center;
font-size: 32rpx;
font-weight: 600;
box-shadow: 0 8rpx 24rpx rgba(85, 139, 47, 0.3);
}
.submit-btn:active {
transform: scale(0.98);
filter: brightness(0.95);
}