This commit is contained in:
wt 2025-10-10 16:28:27 +08:00
parent f2d67f5d90
commit d72bc9ccd8
16 changed files with 350 additions and 17 deletions

View File

@ -7,7 +7,8 @@
"pages/add/info",
"pages/index/info",
"pages/index/edit",
"pages/about/index"
"pages/about/index",
"pages/today/index"
],
"window": {
"navigationBarTextStyle": "black",
@ -15,6 +16,26 @@
"navigationBarBackgroundColor": "#ffffff"
},
"darkmode": false,
"tabBar": {
"selectedColor": "#54B87E",
"backgroundColor": "white",
"list": [
{
"iconPath": "static/img/home.png",
"selectedIconPath": "static/img/home1.png",
"pagePath": "pages/index/index",
"iconSize": 48,
"text": "首页"
},
{
"iconPath": "static/img/home.png",
"selectedIconPath": "static/img/home1.png",
"pagePath": "pages/today/index",
"iconSize": 48,
"text": "今日农事"
}
]
},
"componentFramework": "glass-easel",
"sitemapLocation": "sitemap.json",
"lazyCodeLoading": "requiredComponents",

View File

@ -0,0 +1,78 @@
// components/picker/index.js
Component({
/**
* 组件的属性列表
*/
properties: {
title: {
type: String,
require: true
},
prop: {
type: String,
require: true
},
value: {
type: String,
require: false
}
},
observers: {
// 监听 visible 的变化
'value': function (newVal, oldVal) {
if (newVal) {
this.setData({
result:newVal
})
}
}
},
/**
* 组件的初始数据
*/
data: {
visible: false,
result: '',
counts: []
},
/**
* 组件的方法列表
*/
methods: {
init() {
var list = []
for (let index = 1; index < 31; index++) {
const item = {
label: index,
value: index
}
list.push(item)
}
this.setData({
counts: list
})
},
confirm(e) {
const value = e.detail.value[0]
this.setData({
result: value,
visible:false
})
this.triggerEvent('ok', {
value: {prop: this.data.prop,value:value}
});
},
onVisibleChange() {
const show = !this.data.visible
if (show) {
this.init()
}
this.setData({
visible: show
})
},
}
})

View File

@ -0,0 +1,9 @@
{
"component": true,
"styleIsolation": "apply-shared",
"usingComponents": {
"t-popup": "tdesign-miniprogram/popup/popup",
"t-picker": "tdesign-miniprogram/picker/picker",
"t-picker-item": "tdesign-miniprogram/picker-item/picker-item"
}
}

View File

@ -0,0 +1,8 @@
<!--components/picker/index.wxml-->
<view>
<t-cell title="{{title}}" note="{{result ? '每'+result +'天':'请选择' + title}}" bordered="{{false}}" hover arrow bind:tap="onVisibleChange"></t-cell>
<t-picker visible="{{visible}}" cancelBtn="取消" confirmBtn="确认" bind:confirm="confirm">
<t-picker-item options="{{counts}}"></t-picker-item>
</t-picker>
</view>

View File

@ -0,0 +1 @@
/* components/picker/index.wxss */

View File

@ -1,4 +1,5 @@
// pages/index/edit.js
const config = require("../../config/config")
const { api } = require("../../utils/api")
Page({
@ -40,6 +41,64 @@ Page({
onInput(e){
const value = e.detail.value
this.setData({newName:value})
},
updateFarms(e){
const value = e.detail.value
console.log(value);
const user = wx.getStorageSync('user')
var data = {id: this.data.info.farms.id,plantId: this.data.info.farms.plantId,userId:user.id}
data[value.prop] = value.value
api('/plant/updateFarm','POST',data,'json').then(res => {
if (res.code === 200){
wx.showToast({
icon:'success',
title: res.msg,
})
}
})
},
upload(){
const _this = this
wx.chooseMedia({
count: 1,
mediaType: ['image'],
sourceType: ['album', 'camera'],
camera: 'back',
success(res) {
const avatarUrl = res.tempFiles[0].tempFilePath
wx.showLoading({
title: '请稍后...',
})
wx.uploadFile({
filePath: avatarUrl,
name: 'file',
header:{
'Authorization': 'Bearer ' + wx.getStorageSync('token'),
},
url: config.baseUrl + '/oss/upload',
success: res => {
var data = JSON.parse(res.data);
if (data.code === 200) {
const params = {ossIds:[data.data.file.id],plantId: _this.data.info.farms.plantId}
api('/plant/uploadImg','POST',params,'json').then(res => {
if (res.code === 200){
wx.showToast({
icon:'success',
title: res.msg,
})
}else {
wx.showModal({
content: res.msg
})
}
})
}
}
})
}
})
},
update(){
@ -48,6 +107,16 @@ Page({
data.name = this.data.newName
}
console.log(data);
api('/plant/updatePlant','POST',data,'json').then(res => {
if (res.code === 200){
this.fetchInfo()
} else {
wx.showModal({
content: res.msg
})
}
this.setData({showDialog:false})
})
},
del(){

View File

@ -1,6 +1,7 @@
{
"usingComponents": {
"t-dialog": "tdesign-miniprogram/dialog/dialog",
"t-cell": "tdesign-miniprogram/cell/cell"
"t-cell": "tdesign-miniprogram/cell/cell",
"picker": "/components/count-picker/index"
}
}

View File

@ -4,7 +4,16 @@
<view class="row padding">
<view class="flex flex-center flex-justify-between">
<view class="flex flex-center flex-justify-start">
<image src="https://res.catter.cn/pub/2025/09/30/20250930143920286.png" class="pic"></image>
<view >
<view class="container">
<image src="https://res.catter.cn/pub/2025/09/30/20250930143920286.png" mode="aspectFill" class="bg"></image>
<view class="tips ">
<view style="background-color: #34343442;height: 100%; width: 100%" class="flex flex-center" bind:tap="upload">
<t-icon name="camera" style="color: white;" size="48rpx"></t-icon>
</view>
</view>
</view>
</view>
<view class="padding">
<view>
{{info.name}}
@ -22,22 +31,22 @@
<view class="white-bg mt-32 " style="border-radius: 16rpx;">
<view style=" padding-top: 16rpx; padding-bottom: 16rpx;">
<t-cell title="浇水" bordered="{{false}}" hover arrow note="每{{info.farms.wateringCycle}}天"/>
<t-cell title="施肥" bordered="{{false}}" hover arrow note="每{{info.farms.slowReleaseFertilizerCycle}}天"/>
<t-cell title="施肥类型" bordered="{{false}}" hover arrow note="水溶肥"/>
<t-cell title="旋转" bordered="{{false}}" hover arrow note="每{{info.farms.rotationCycle}}天"/>
<t-cell title="修剪" bordered="{{false}}" hover arrow note="每{{info.farms.pruningCycle}}天"/>
<picker title="浇水" value="{{info.farms.wateringCycle}}" prop="wateringCycle" bind:ok="updateFarms"></picker>
<picker title="施肥" value="{{info.farms.slowReleaseFertilizerCycle}}" prop="slowReleaseFertilizerCycle" bind:ok="updateFarms"></picker>
<t-cell title="施肥类型" bordered="{{false}}" hover arrow note="水溶肥" />
<picker title="旋转" value="{{info.farms.rotationCycle}}" prop="rotationCycle" bind:ok="updateFarms"></picker>
<picker title="修剪" value="{{info.farms.pruningCycle}}" prop="pruningCycle" bind:ok="updateFarms"></picker>
</view>
</view>
</view>
<view class="flex flex-center">
<t-button theme="danger" icon="delete" shape="round" style="width: 80%;" variant="outline" bind:tap="del">删除植物</t-button>
</view>
</view>
<view class="flex flex-center">
<t-button theme="danger" icon="delete" shape="round" style="width: 80%;" variant="outline" bind:tap="del">删除植物</t-button>
</view>
<t-dialog visible="{{showDialog}}" title="更改名称" confirm-btn="确定" cancel-btn="取消" bind:confirm="update" bind:cancel="changeDialog">
<t-input borderless clearable slot="content" placeholder="请输入新的名称" bind:change="onInput" />
</t-dialog>
<t-dialog visible="{{showDialog}}" title="更改名称" confirm-btn="确定" cancel-btn="取消" bind:confirm="update" bind:cancel="changeDialog">
<t-input borderless clearable slot="content" placeholder="请输入新的名称" bind:change="onInput" />
</t-dialog>
</view>

View File

@ -3,8 +3,30 @@ page {
background-color: #F6F6F6;
}
.pic{
.container {
position: relative;
width: 150rpx;
height: 150rpx;
padding: 0;
flex-shrink: 0;
overflow: hidden; /* 防止内容溢出 */
}
.bg {
width: 100%;
height: 100%;
background-color: rebeccapurple;
border-radius: 16rpx;
z-index: 1;
display: block; /* 必须加,否则 image 不会撑满父容器 */
}
.tips {
position: absolute;
width: 100%;
height: 100%;
z-index: 3;
display: block; /* 必须加,否则 image 不会撑满父容器 */
font-size: 28rpx;
}

View File

@ -19,7 +19,8 @@ Page({
},
fetchInfo(){
api('/plant/detail','GET',{id: this.data.id}).then(res => {
const data ={id: this.data.id}
api('/plant/detail','GET',data).then(res => {
if (res.code === 200){
const tmp = res.data
tmp.farms.suitableFertilizer = tmp.farms.suitableFertilizer.split(',')
@ -27,6 +28,11 @@ Page({
console.log(tmp);
}
})
api('/plant/todayFarm',data).then(res => {
if (res.code === 200){
console.log(res);
}
})
},
goEdit(){

84
pages/today/index.js Normal file
View File

@ -0,0 +1,84 @@
const { api } = require("../../utils/api")
// pages/today/index.js
Page({
/**
* 页面的初始数据
*/
data: {
user:null,
list:[],
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.init()
},
init(){
const tmp = wx.getStorageSync('user')
this.setData({user:tmp})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
this.fetchInfo()
},
fetchInfo(){
api('/plant/todayCare','GET',{userId: this.data.user.id}).then(res => {
if (res.code === 200){
const data = res.data
if (data !== null){
this.setData({list:data})
}
}
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

3
pages/today/index.json Normal file
View File

@ -0,0 +1,3 @@
{
"usingComponents": {}
}

13
pages/today/index.wxml Normal file
View File

@ -0,0 +1,13 @@
<!--pages/today/index.wxml-->
<view>
<view>
<view wx:if="{{list.length === 0}}" class="flex flex-center flex-col " style="margin-top: 268rpx;" >
<view class="empty flex flex-center flex-col">
</view>
<view class="mt-16 flex flex-center flex-col">
<view class="font-16 bold" >已完成所有任务</view>
<view class="font-12 grey mt-16">今天暂无农事需要完成</view>
</view>
</view>
</view>
</view>

9
pages/today/index.wxss Normal file
View File

@ -0,0 +1,9 @@
/* pages/today/index.wxss */
.empty {
width: 140rpx;
height: 140rpx;
background-color:#F6F6F6 ;
border-radius: 140rpx;
background-image: url("https://res.catter.cn/pub/2025/09/30/20250930143142508.png");
background-size: cover;
}

BIN
static/img/home.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
static/img/home1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB