This commit is contained in:
sdaduanbilei 2025-12-04 11:56:37 +08:00
parent 42dc47724f
commit 98af0c8d3e
21 changed files with 265 additions and 97 deletions

109
app.js
View File

@ -1,49 +1,76 @@
import {
api
api
} from './utils/api';
import {
publisher
publisher
} from "./utils/login-sdk";
App({
onLaunch() {
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
api("/auth/miniLogin?code=" + res.code).then(res => {
if (res.code === 200) {
wx.setStorageSync('openId', res.data.user.miniOpenId)
wx.setStorageSync('sessionKey', res.data.user.sessionKey)
if (res.data.user.id){
wx.setStorageSync('user', res.data.user)
wx.setStorageSync('token', res.data.token)
} else {
wx.showModal({
title: '提示',
content: '登录过期,请重新登陆',
confirmText: '去登录',
complete: (res) => {
if (res.confirm) {
wx.navigateTo({
url: '../login/index',
})
}
}
})
wx.removeStorageSync('token')
wx.removeStorageSync('user')
}
publisher.emit("login");
} else {
wx.navigateTo({
url: '../login/index',
})
}
})
},
fail:err => {
console.log(err);
onLaunch() {
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
api("/auth/miniLogin?code=" + res.code).then(res => {
if (res.code === 200) {
wx.setStorageSync('openId', res.data.user.miniOpenId)
wx.setStorageSync('sessionKey', res.data.user.sessionKey)
if (res.data.user.id) {
wx.setStorageSync('user', res.data.user)
wx.setStorageSync('token', res.data.token)
} else {
wx.showModal({
title: '提示',
content: '登录过期,请重新登陆',
confirmText: '去登录',
complete: (res) => {
if (res.confirm) {
wx.navigateTo({
url: '../login/index',
})
}
}
})
wx.removeStorageSync('token')
wx.removeStorageSync('user')
}
} else {
wx.navigateTo({
url: '../login/index',
})
}
})
}
// location
wx.getFuzzyLocation({
type: 'wgs84',
success(res) {
const data = {
latitude: res.latitude + "",
longitude: res.longitude + ""
}
api('/auth/getLocation', 'GET', data).then(res => {
if (res.code === 200) {
wx.setStorageSync('city', res.data)
const tmp = wx.getStorageSync('weather')
if (tmp) {
publisher.emit("login");
} else {
api('/auth/getWeather', 'GET', res.data).then(res => {
if (res.code === 200) {
wx.setStorageSync('weather', res.data)
}
})
}
}
})
},
fail(err) {
console.log(err);
}
})
},
fail: err => {
console.log(err);
}
})
}
})

View File

@ -15,7 +15,8 @@
"pages/community/add",
"pages/badge/index",
"pages/user/about",
"pages/community/info"
"pages/community/info",
"pages/store/index"
],
"window": {
"navigationBarTextStyle": "black",

View File

@ -1,7 +1,6 @@
{
"navigationBarTitleText": "植趣社区",
"usingComponents": {
"t-tabs": "tdesign-miniprogram/tabs/tabs",
"t-tab-panel": "tdesign-miniprogram/tab-panel/tab-panel"
}
}

View File

@ -1,18 +1,18 @@
<!--pages/community/index.wxml-->
<view>
<t-tabs defaultValue="{{0}}" bind:change="onTabsChange" bind:click="onTabsClick" t-class="custom-tabs">
<!-- <t-tabs defaultValue="{{0}}" bind:change="onTabsChange" bind:click="onTabsClick" t-class="custom-tabs">
<t-tab-panel label="推荐" value="0" />
<t-tab-panel label="最新" value="1" />
<t-tab-panel label="我的" value="2" />
</t-tabs>
</t-tabs> -->
<view class="padding">
<view wx:for="{{list}}" class="padding row mb-32" data-id="{{item.id}}" bind:tap="goInfo">
<view class="flex flex-center flex-justify-start">
<image src="https://res.catter.cn/pub/2025/09/30/20250930143142508.png" class="avatar"></image>
<image src="{{item.user.avatar.url}}" class="avatar"></image>
<view class="ml-16">
<view class="bold">第五季</view>
<view class="font-12 grey">23 小时前</view>
<view class="bold">{{item.user.name}}</view>
<view class="font-12 grey">{{item.createdAt}}</view>
</view>
</view>
<view class="mt-16">

View File

@ -46,6 +46,13 @@ Page({
})
},
goPreview(e){
console.log(e);
const url = e.currentTarget.dataset.url
wx.navigateTo({
url: '../preview/index?url=' + url,
})
},
/**

View File

@ -3,10 +3,10 @@
<view style="padding-bottom: 200rpx;">
<view wx:if="{{info}}" class="padding row mb-32" data-id="{{item.id}}" bind:tap="goInfo">
<view class="flex flex-center flex-justify-start">
<image src="https://res.catter.cn/pub/2025/09/30/20250930143142508.png" class="avatar"></image>
<image src="{{info.user.avatar.url}}" class="avatar"></image>
<view class="ml-16">
<view class="bold">第五季</view>
<view class="font-12 grey">23 小时前</view>
<view class="bold">{{info.user.name}}</view>
<view class="font-12 grey">{{info.createdAt}}</view>
</view>
</view>
<view class="mt-16">
@ -19,7 +19,7 @@
</view>
</view>
<view wx:else class="grid">
<view class="item" wx:for="{{info.imgList}}">
<view class="item" wx:for="{{info.imgList}}" data-url="{{item.url}}" bind:tap="goPreview">
<view>
<image src="{{item.url}}" style="width: 100%;height: 30vw; border-radius: 16rpx;" mode="aspectFill" b></image>
</view>
@ -39,7 +39,7 @@
</view>
<view class="white-bg padding" style="border-bottom: #F6F6F6 1rpx solid;" wx:for="{{info.commentList}}">
<view class="flex flex-center flex-justify-start flex-aligin-start">
<t-avatar class="avatar-example" shape="round" wx:if="{{item.user.avatar}}" image="item.user.avatar" size="60rpx" />
<t-avatar class="avatar-example" shape="round" wx:if="{{item.user.avatar}}" image="{{item.user.avatar.url}}" size="60rpx" />
<t-avatar class="avatar-example" shape="round" wx:else image="https://res.catter.cn/pub/2025/12/02/202512021046843.jpg" size="60rpx" />
<view class="full-width">
<view class="font-12 ml-16 flex flex-center flex-justify-between">

View File

@ -1,4 +1,5 @@
/* pages/community/info.wxss */
.avatar {
height: 80rpx;
width: 80rpx;

View File

@ -70,8 +70,8 @@ Page({
})
},
goAdd(){
wx.navigateTo({
url: '../add/index',
wx.switchTab({
url: '../community/index',
})
},
/**

View File

@ -15,13 +15,15 @@
</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>
<image src="https://res.catter.cn/pub/2025/12/04/20251204110325575.png" style="width: 280rpx;height: 280rpx;"></image>
</view>
<view class="mt-16 flex flex-center flex-col">
<view class="font-16 bold">暂无任务</view>
<view >今日养护得满分!</view>
<view class="mt-16">植物们正在惬意生长中</view>
</view>
<view style="width: 100vw; margin-top: 48rpx; " class="flex flex-center">
<t-button theme="primary" style="width: 60%;" size="small" shape="round" bind:tap="goAdd">添加一颗新的植物</t-button>
<view style="width: 100vw; margin-top: 48rpx; " class="flex flex-center flex-col">
<t-button theme="primary" style="width: 60%;" size="small" shape="round" bind:tap="goAdd">去社区看看吧</t-button>
</view>
</view>

View File

@ -8,7 +8,8 @@ Page({
*/
data: {
id:'',
farms:[]
farms:[],
weather:null
},
/**
@ -16,6 +17,14 @@ Page({
*/
onLoad(options) {
this.setData({id:options.id})
this.init()
},
init(){
const tmp = wx.getStorageSync('weather')
if(tmp){
this.setData({weather:tmp})
}
},
fetchInfo(){

View File

@ -33,13 +33,10 @@
<view class="white-bg padding flex flex-center flex-justify-between">
<view class="font-12">
<view>
🌡 温度适宜:1623°C
🌡 温度适宜:{{weather.temperature}} °C
</view>
<view>
🌞 今日光照:良好
</view>
<view>
💧 湿度 适宜
💧 湿度 {{weather.humidity}} %
</view>
</view>
<view>

View File

@ -16,7 +16,8 @@ Page({
rightList: [],
leftHeight: 0,
rightHeight: 0,
hotList:[]
hotList:[],
info:null
},
/**
@ -38,23 +39,23 @@ Page({
*/
onShow() {
this.fetchList()
this.fethcLocation()
this.init()
},
fethcLocation(){
wx.getFuzzyLocation({
type: 'wgs84',
success (res) {
console.log(res);
const latitude = res.latitude
const longitude = res.longitude
console.log(latitude,longitude);
},
fail(err){
console.log(err);
init(){
const tmp = wx.getStorageSync('weather')
if(tmp){
this.setData({info:tmp})
}
const city = wx.getStorageSync('city')
api('/auth/getWeather', 'GET', city).then(res => {
if (res.code === 200) {
wx.setStorageSync('weather', res.data)
}
})
})
},
fetchList() {
api('/plant/page', 'POST', {
current: 0,

View File

@ -2,12 +2,12 @@
<view>
<!-- top -->
<view class="top primary-bg">
<view style="padding-top: 128rpx; padding-left: 32rpx;" class="white">
<view class="bold font-16">天气晴朗</view>
<view style="padding-top: 128rpx; padding-left: 32rpx;" class="white" wx:if="{{info}}">
<view class="bold font-16">{{info.weather}} {{info.windDirection}}风{{info.windPower}}级</view>
<view>
<view class="flex flex-center flex-justify-start">
<t-icon name="fog-sunny" size="32"></t-icon>
<view class="bold mt-16 ml-16" style="font-size: 40px;">20 ℃ </view>
<t-icon wx:if="{{info.weather === '雾'}}" name="fog" size="34"></t-icon>
<view class="bold mt-16 ml-16" style="font-size: 40px;">{{info.temperature}} ℃</view>
</view>
<view wx:if="{{leftList.length > 0}}">
<view> 今日需养护 2 株植物</view>

81
pages/store/index.js Normal file
View File

@ -0,0 +1,81 @@
// pages/store/index.js
Page({
/**
* 页面的初始数据
*/
data: {
list:[
{
name:'傲娇薄荷•斯基',
tag:'夏日续命草',
url:'https://res.catter.cn/pub/2025/12/04/20251204113223290.png',
count:1,
status:0
},
{
name:'呆萌多肉•丸子',
tag:'佛系晒太阳',
url:'https://res.catter.cn/pub/2025/12/04/20251204113419078.png',
count:2,
status:1
}
]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

4
pages/store/index.json Normal file
View File

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "植物领养中心",
"usingComponents": {}
}

32
pages/store/index.wxml Normal file
View File

@ -0,0 +1,32 @@
<!--pages/store/index.wxml-->
<view>
<view class="flex flex-center primary-bg padding">
<view class="white">
我的兑换币 1 枚
</view>
<view class="ml-16" style="color: orange;">
邀请好友获取更多兑换币
</view>
</view>
<view class="grid margin">
<view wx:for="{{list}}">
<view class="white-bg row">
<image style="width: 100%; border-top-left-radius: 16rpx; border-top-right-radius: 16rpx;" src="{{item.url}}" mode="aspectFill"></image>
<view style="background-color: #C35D4B;margin-top: -10rpx; padding: 8rpx;" class="font-12 white">需要 {{item.count}} 兑换币</view>
<view style="padding: 0 16rpx;" class="mt-16">
<view class="font-14 w400">
{{item.name}}
</view>
<view class="mt-5">
<t-tag shape="round" size="small">{{item.tag}}</t-tag>
</view>
</view>
<view class="flex flex-center mb-16 mt-16" style="padding-bottom: 32rpx;">
<t-button size="small" style="width: 90%;" shape="round" theme="primary" wx:if="{{item.status === 0}}">立即领养(付邮)</t-button>
<t-button size="small" style="width: 90%;" shape="round" theme="danger" wx:if="{{item.status === 1}}">获取资格</t-button>
</view>
</view>
</view>
</view>
</view>

7
pages/store/index.wxss Normal file
View File

@ -0,0 +1,7 @@
/* pages/store/index.wxss */
.grid {
display: grid;
grid-template-columns: auto auto;
grid-row-gap: 8px;
grid-column-gap: 8px;
}

View File

@ -2,7 +2,7 @@
<view class="content padding">
<view class="flex flex-aligin-center flex-col padding row">
<image src="https://res.catter.cn/kaka/2024/11/02/1730546862685.JPG" style="height: 960rpx;" show-menu-by-longpress></image>
<view class="padding">长按二维码,加入群聊</view>
<view class="padding">长按二维码,加入群聊</view>
<view class="padding">一起交流种植小技巧</view>
</view>
</view>

View File

@ -78,6 +78,12 @@ Page({
})
},
goStore(){
wx.navigateTo({
url: '../store/index',
})
},
goAbout(){
wx.navigateTo({
url: '../user/about',

View File

@ -46,7 +46,7 @@
</view>
</view>
<view class="white-bg padding mt-32 flex flex-center flex-justify-between" style="border-radius: 16rpx;">
<!-- <view class="white-bg padding mt-32 flex flex-center flex-justify-between" style="border-radius: 16rpx;">
<view class="flex flex-center flex-col">
<view class="avatar flex flex-center" style="background-color: #E2B43F3C;">
<t-icon name="thumb-up" style="color: #E2B43F;" size="24"></t-icon>
@ -74,13 +74,14 @@
</view>
<view class="mt-16">我的互动</view>
</view>
</view>
</view> -->
</view>
<view style="padding: 0 32rpx">
<view class="row" style="padding-top: 8rpx; padding-bottom: 8rpx;margin-bottom: 32rpx;">
<t-cell title="免费领取绿植" hover arrow />
<t-cell title="植物百科" hover arrow />
<t-cell title="植物领养中心" hover arrow bind:tap="goStore" />
<t-cell title="提醒设置" hover arrow />
<t-cell title="加入微信群" hover arrow bind:tap="goAbout" />
<t-cell title="用户协议" hover arrow bind:tap="goPrivate" />

View File

@ -24,18 +24,11 @@
"miniprogram": {
"list": [
{
"name": "pages/add/index",
"pathName": "pages/add/index",
"name": "pages/store/index",
"pathName": "pages/store/index",
"query": "",
"scene": null,
"launchMode": "default"
},
{
"name": "pages/community/info",
"pathName": "pages/community/info",
"query": "id=d7082150-c68d-11f0-b4a9-bc2411e64a23",
"launchMode": "default",
"scene": null
}
]
}