From 98af0c8d3e312cea14927c6d68242821fe51e479 Mon Sep 17 00:00:00 2001 From: sdaduanbilei Date: Thu, 4 Dec 2025 11:56:37 +0800 Subject: [PATCH] init --- app.js | 109 ++++++++++++++++++++++-------------- app.json | 3 +- pages/community/index.json | 3 +- pages/community/index.wxml | 10 ++-- pages/community/info.js | 7 +++ pages/community/info.wxml | 10 ++-- pages/community/info.wxss | 1 + pages/garden/index.js | 4 +- pages/garden/index.wxml | 10 ++-- pages/garden/info.js | 11 +++- pages/garden/info.wxml | 7 +-- pages/index/index.js | 29 +++++----- pages/index/index.wxml | 8 +-- pages/store/index.js | 81 +++++++++++++++++++++++++++ pages/store/index.json | 4 ++ pages/store/index.wxml | 32 +++++++++++ pages/store/index.wxss | 7 +++ pages/user/about.wxml | 2 +- pages/user/index.js | 6 ++ pages/user/index.wxml | 7 ++- project.private.config.json | 11 +--- 21 files changed, 265 insertions(+), 97 deletions(-) create mode 100644 pages/store/index.js create mode 100644 pages/store/index.json create mode 100644 pages/store/index.wxml create mode 100644 pages/store/index.wxss diff --git a/app.js b/app.js index be2b106..0a2cbc1 100644 --- a/app.js +++ b/app.js @@ -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); + } + }) + } }) \ No newline at end of file diff --git a/app.json b/app.json index 7fd2619..d245307 100644 --- a/app.json +++ b/app.json @@ -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", diff --git a/pages/community/index.json b/pages/community/index.json index 30c6c4a..d5aa7fa 100644 --- a/pages/community/index.json +++ b/pages/community/index.json @@ -1,7 +1,6 @@ { "navigationBarTitleText": "植趣社区", "usingComponents": { - "t-tabs": "tdesign-miniprogram/tabs/tabs", - "t-tab-panel": "tdesign-miniprogram/tab-panel/tab-panel" + } } \ No newline at end of file diff --git a/pages/community/index.wxml b/pages/community/index.wxml index 3e2add1..1684fb8 100644 --- a/pages/community/index.wxml +++ b/pages/community/index.wxml @@ -1,18 +1,18 @@ - + - + - 第五季 - 23 小时前 + {{item.user.name}} + {{item.createdAt}} diff --git a/pages/community/info.js b/pages/community/info.js index 5485774..2e47af4 100644 --- a/pages/community/info.js +++ b/pages/community/info.js @@ -46,6 +46,13 @@ Page({ }) }, + goPreview(e){ + console.log(e); + const url = e.currentTarget.dataset.url + wx.navigateTo({ + url: '../preview/index?url=' + url, + }) + }, /** diff --git a/pages/community/info.wxml b/pages/community/info.wxml index 43ef45d..b3573e1 100644 --- a/pages/community/info.wxml +++ b/pages/community/info.wxml @@ -3,10 +3,10 @@ - + - 第五季 - 23 小时前 + {{info.user.name}} + {{info.createdAt}} @@ -19,7 +19,7 @@ - + @@ -39,7 +39,7 @@ - + diff --git a/pages/community/info.wxss b/pages/community/info.wxss index efcf935..da5dace 100644 --- a/pages/community/info.wxss +++ b/pages/community/info.wxss @@ -1,4 +1,5 @@ /* pages/community/info.wxss */ + .avatar { height: 80rpx; width: 80rpx; diff --git a/pages/garden/index.js b/pages/garden/index.js index d02fe44..000b15a 100644 --- a/pages/garden/index.js +++ b/pages/garden/index.js @@ -70,8 +70,8 @@ Page({ }) }, goAdd(){ - wx.navigateTo({ - url: '../add/index', + wx.switchTab({ + url: '../community/index', }) }, /** diff --git a/pages/garden/index.wxml b/pages/garden/index.wxml index 4714c96..7e071b9 100644 --- a/pages/garden/index.wxml +++ b/pages/garden/index.wxml @@ -15,13 +15,15 @@ - + + - 暂无任务 + 今日养护得满分! + 植物们正在惬意生长中 - - 添加一颗新的植物 + + 去社区看看吧 diff --git a/pages/garden/info.js b/pages/garden/info.js index fc5266f..8a87aa1 100644 --- a/pages/garden/info.js +++ b/pages/garden/info.js @@ -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(){ diff --git a/pages/garden/info.wxml b/pages/garden/info.wxml index d3a1ac9..9da8579 100644 --- a/pages/garden/info.wxml +++ b/pages/garden/info.wxml @@ -33,13 +33,10 @@ - 🌡 温度适宜:16–23°C + 🌡 温度适宜:{{weather.temperature}} °C - 🌞 今日光照:良好 - - - 💧 湿度 适宜 + 💧 湿度 {{weather.humidity}} % diff --git a/pages/index/index.js b/pages/index/index.js index a1d76df..3827529 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -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, diff --git a/pages/index/index.wxml b/pages/index/index.wxml index d0655c0..bf1969a 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -2,12 +2,12 @@ - - 天气晴朗 + + {{info.weather}} {{info.windDirection}}风{{info.windPower}}级 - - 20 ℃ + + {{info.temperature}} ℃ 今日需养护 2 株植物 diff --git a/pages/store/index.js b/pages/store/index.js new file mode 100644 index 0000000..1522742 --- /dev/null +++ b/pages/store/index.js @@ -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() { + + } +}) \ No newline at end of file diff --git a/pages/store/index.json b/pages/store/index.json new file mode 100644 index 0000000..2df9158 --- /dev/null +++ b/pages/store/index.json @@ -0,0 +1,4 @@ +{ + "navigationBarTitleText": "植物领养中心", + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/store/index.wxml b/pages/store/index.wxml new file mode 100644 index 0000000..850ae7c --- /dev/null +++ b/pages/store/index.wxml @@ -0,0 +1,32 @@ + + + + + 我的兑换币 1 枚 + + + 邀请好友获取更多兑换币 + + + + + + + 需要 {{item.count}} 兑换币 + + + {{item.name}} + + + {{item.tag}} + + + + + 立即领养(付邮) + 获取资格 + + + + + \ No newline at end of file diff --git a/pages/store/index.wxss b/pages/store/index.wxss new file mode 100644 index 0000000..4eb7f39 --- /dev/null +++ b/pages/store/index.wxss @@ -0,0 +1,7 @@ +/* pages/store/index.wxss */ +.grid { + display: grid; + grid-template-columns: auto auto; + grid-row-gap: 8px; + grid-column-gap: 8px; +} \ No newline at end of file diff --git a/pages/user/about.wxml b/pages/user/about.wxml index 9da2a60..d115663 100644 --- a/pages/user/about.wxml +++ b/pages/user/about.wxml @@ -2,7 +2,7 @@ - 长按二维码,加入群聊, + 长按二维码,加入群聊 一起交流种植小技巧 \ No newline at end of file diff --git a/pages/user/index.js b/pages/user/index.js index 1b50f90..2367aee 100644 --- a/pages/user/index.js +++ b/pages/user/index.js @@ -78,6 +78,12 @@ Page({ }) }, + goStore(){ + wx.navigateTo({ + url: '../store/index', + }) + }, + goAbout(){ wx.navigateTo({ url: '../user/about', diff --git a/pages/user/index.wxml b/pages/user/index.wxml index 3452f8b..c00ec3e 100644 --- a/pages/user/index.wxml +++ b/pages/user/index.wxml @@ -46,7 +46,7 @@ - + - + + diff --git a/project.private.config.json b/project.private.config.json index 2b1e46e..d23ac87 100644 --- a/project.private.config.json +++ b/project.private.config.json @@ -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 } ] }