diff --git a/app.js b/app.js index 0a2cbc1..7da3997 100644 --- a/app.js +++ b/app.js @@ -17,6 +17,13 @@ App({ if (res.data.user.id) { wx.setStorageSync('user', res.data.user) wx.setStorageSync('token', res.data.token) + publisher.emit("login"); + // 生成邀请码 + api('/personal/inviteCode/code','GET').then(res => { + if (res.code === 200){ + wx.setStorageSync('inviteCode', res.data) + } + }) } else { wx.showModal({ title: '提示', @@ -52,7 +59,7 @@ App({ wx.setStorageSync('city', res.data) const tmp = wx.getStorageSync('weather') if (tmp) { - publisher.emit("login"); + console.log("succ"); } else { api('/auth/getWeather', 'GET', res.data).then(res => { if (res.code === 200) { @@ -67,10 +74,14 @@ App({ console.log(err); } }) + + }, fail: err => { console.log(err); } }) + + } }) \ No newline at end of file diff --git a/app.wxss b/app.wxss index 69e52a8..4a6fd49 100644 --- a/app.wxss +++ b/app.wxss @@ -194,6 +194,10 @@ page { .blue { color: blue; } + + .font-black { + color: #000000E6 !important; + } .font-12{ font-size: 12px; diff --git a/pages/community/index.wxml b/pages/community/index.wxml index 1684fb8..8281b83 100644 --- a/pages/community/index.wxml +++ b/pages/community/index.wxml @@ -33,7 +33,7 @@ - + {{item.likeCount}} diff --git a/pages/community/info.js b/pages/community/info.js index 2e47af4..c437b14 100644 --- a/pages/community/info.js +++ b/pages/community/info.js @@ -1,4 +1,6 @@ -const { api } = require("../../utils/api") +const { + api +} = require("../../utils/api") // pages/community/info.js Page({ @@ -7,9 +9,9 @@ Page({ * 页面的初始数据 */ data: { - id : '', - info:null, - content:'', + id: '', + info: null, + content: '', }, @@ -22,38 +24,50 @@ Page({ this.fetchInfo() }, - fetchInfo(){ - api('/post/detail','GET',{id: this.data.id}).then(res => { - if (res.code== 200){ + fetchInfo() { + api('/post/detail', 'GET', { + id: this.data.id + }).then(res => { + if (res.code == 200) { const tmp = res.data - this.setData({info:tmp}) + this.setData({ + info: tmp + }) } }) }, - input(e){ + input(e) { const value = e.detail.value console.log(value); this.data.content = value }, - add(){ - const data = {content: this.data.content, postId: this.data.id,parentId: this.data.id,rootId:this.data.id} + add() { + const data = { + content: this.data.content, + postId: this.data.id, + parentId: this.data.id, + rootId: this.data.id + } console.log(data); - api('/comment/add','POST',data,'json').then(res => { - if (res.code === 200){ + api('/comment/add', 'POST', data, 'json').then(res => { + if (res.code === 200) { this.fetchInfo() } }) }, - goPreview(e){ - console.log(e); - const url = e.currentTarget.dataset.url - wx.navigateTo({ - url: '../preview/index?url=' + url, + goPreview(e) { + + // 在上一页的 js 文件中 + const currentUrl = e.currentTarget.dataset.url; // 获取当前点击的图片链接 + const list = this.data.info.imgList.map(e => e.url) + wx.previewImage({ + current: currentUrl, // 当前显示图片的http链接 + urls: list// 需要预览的图片http链接列表 }) }, - + /** * 生命周期函数--监听页面初次渲染完成 diff --git a/pages/community/info.wxml b/pages/community/info.wxml index b3573e1..0698e5a 100644 --- a/pages/community/info.wxml +++ b/pages/community/info.wxml @@ -13,10 +13,10 @@ {{info.content}} - - - - + + + + diff --git a/pages/index/index.js b/pages/index/index.js index 3827529..c831ba6 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -16,15 +16,22 @@ Page({ rightList: [], leftHeight: 0, rightHeight: 0, - hotList:[], - info:null + hotList: [], + info: null, + needCare: 0, + inviteCode: '' }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { - + const code = options.inviteCode + if (code) { + api('/personal/inviteCode/accept', 'GET', { + inviteCode: code + }) + } }, /** @@ -42,20 +49,62 @@ Page({ this.init() }, - init(){ + init() { const tmp = wx.getStorageSync('weather') - if(tmp){ - this.setData({info:tmp}) + if (tmp) { + this.setData({ + info: tmp + }) + } else { + 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) + api('/auth/getWeather', 'GET', res.data).then(res => { + if (res.code === 200) { + wx.setStorageSync('weather', res.data) + this.setData({info:res.data}) + } + }) + + } + }) + }, + fail(err) { + console.log(err); + } + }) } - const city = wx.getStorageSync('city') - api('/auth/getWeather', 'GET', city).then(res => { + const inviteCode = wx.getStorageSync('inviteCode') + if (inviteCode) { + this.setData({ + inviteCode: inviteCode + }) + } + + + api('/plant/needCare', 'GET').then(res => { if (res.code === 200) { - wx.setStorageSync('weather', res.data) + this.setData({ + needCare: res.data + }) } }) }, - + goTask() { + wx.switchTab({ + url: '../garden/index', + }) + }, + + fetchList() { api('/plant/page', 'POST', { current: 0, @@ -70,7 +119,10 @@ Page({ this.fetchHotList() return } - this.setData({leftList:[],rightList:[]}) + this.setData({ + leftList: [], + rightList: [] + }) const tmps = res.data.list.map(e => { e.pic = e.imgList[0].url e.cover = e.imgList[0] @@ -78,7 +130,7 @@ Page({ }) this.addItems(tmps) - + this.setData({ list: tmps }) @@ -86,14 +138,20 @@ Page({ }) }, - fetchHotList(){ - api('/library/list','POST',{isHot:0,current:0,pageSize:6},'json').then(res => { - if (res.code === 200){ + fetchHotList() { + api('/library/list', 'POST', { + isHot: 0, + current: 0, + pageSize: 6 + }, 'json').then(res => { + if (res.code === 200) { const data = res.data.list.map(e => { e.pic = e.imgList[0].url return e }) - this.setData({hotList:data}) + this.setData({ + hotList: data + }) } }) }, @@ -101,26 +159,26 @@ Page({ addItems(newItems) { let h1 = 0; let h2 = 0; - newItems.forEach((item,index) => { + newItems.forEach((item, index) => { // 动态获取图片尺寸 - if (index % 2 === 0) { - this.data.leftList.push(item); - h1 += item.cover.height / item.cover.width; - } else { - this.data.rightList.push(item); - h2 += item.cover.height / item.cover.width; - } - this.setData({ - leftList: this.data.leftList, - rightList: this.data.rightList, - }); - + if (index % 2 === 0) { + this.data.leftList.push(item); + h1 += item.cover.height / item.cover.width; + } else { + this.data.rightList.push(item); + h2 += item.cover.height / item.cover.width; + } + this.setData({ + leftList: this.data.leftList, + rightList: this.data.rightList, + }); + }); }, - goInfo(e){ + goInfo(e) { console.log(e); - const id = e.currentTarget.dataset.id + const id = e.currentTarget.dataset.id wx.navigateTo({ url: '../garden/info?id=' + id, }) @@ -142,7 +200,7 @@ Page({ goAdd() { const tmp = wx.getStorageSync('user') - if (tmp.phone.length === 0){ + if (tmp.phone.length === 0) { wx.navigateTo({ url: '../login/index', }) @@ -184,6 +242,18 @@ Page({ * 用户点击右上角分享 */ onShareAppMessage() { + return { + title: '发现一个宝藏养花神器', + imageUrl: "https://res.catter.cn/pub/2025/12/08/20251208112039694.png", + path: '/pages/index/index?inviteCode=' + this.data.inviteCode + }; + }, + onShareTimeline() { + return { + title: '发现一个宝藏养花神器', + imageUrl: "https://res.catter.cn/pub/2025/12/08/20251208112039694.png", + path: '/pages/index/index?inviteCode=' + this.data.inviteCode + }; } }) \ No newline at end of file diff --git a/pages/index/index.wxml b/pages/index/index.wxml index bf1969a..31d6f70 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -2,16 +2,17 @@ - - {{info.weather}} {{info.windDirection}}风{{info.windPower}}级 - - - - {{info.temperature}} ℃ + + {{info.weather}} {{info.windDirection}}风{{info.windPower}}级 + + + + + {{info.temperature}} ℃ - - 今日需养护 2 株植物 - 龟背竹长期未更新照片 + + 今日需养护 {{needCare}} 株植物 + @@ -19,9 +20,9 @@ - + - + {{item.name}} @@ -51,9 +52,9 @@ - + - + {{item.name}} diff --git a/pages/preview/index.wxml b/pages/preview/index.wxml index 68845a2..9bd68e9 100644 --- a/pages/preview/index.wxml +++ b/pages/preview/index.wxml @@ -1,6 +1,26 @@ - - + + + + + + + + + + \ No newline at end of file diff --git a/pages/store/index.js b/pages/store/index.js index 1522742..fd8bd29 100644 --- a/pages/store/index.js +++ b/pages/store/index.js @@ -1,3 +1,5 @@ +const { api } = require("../../utils/api") + // pages/store/index.js Page({ @@ -41,7 +43,15 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { + this.fetchList() + }, + fetchList(){ + api('/claim/list','POST',{current:0,pageSize:10,name:'',keyword:''},'json').then(res => { + if (res.code === 200){ + console.log(res); + } + }) }, /** diff --git a/pages/store/index.wxml b/pages/store/index.wxml index 850ae7c..f200040 100644 --- a/pages/store/index.wxml +++ b/pages/store/index.wxml @@ -2,7 +2,7 @@ - 我的兑换币 1 枚 + 我的阳光值 1 枚 邀请好友获取更多兑换币 diff --git a/pages/user/index.js b/pages/user/index.js index 2367aee..6bf3781 100644 --- a/pages/user/index.js +++ b/pages/user/index.js @@ -1,4 +1,6 @@ -const { api } = require("../../utils/api") +const { + api +} = require("../../utils/api") const config = require("../../config/config") // pages/user/index.js Page({ @@ -7,8 +9,9 @@ Page({ * 页面的初始数据 */ data: { - user:null, - info:null + user: null, + info: null, + inviteCode: '' }, /** @@ -16,9 +19,15 @@ Page({ */ onLoad(options) { const tmp = wx.getStorageSync('user') - if (tmp){ - this.setData({user:tmp}) + if (tmp) { + this.setData({ + user: tmp + }) } + const inviteCode = wx.getStorageSync('inviteCode') + this.setData({ + inviteCode: inviteCode + }) }, /** @@ -34,11 +43,13 @@ Page({ onShow() { this.fetchInfo() }, - fetchInfo(){ - api('/personal/personal','GET').then(res => { - if (res.code === 200){ + fetchInfo() { + api('/personal/personal', 'GET').then(res => { + if (res.code === 200) { const tmps = res.data - this.setData({info:res.data}) + this.setData({ + info: tmps + }) } }) }, @@ -62,7 +73,7 @@ Page({ tmps.avatar = data.data.file tmps.avatarId = data.data.file.id _this.setData({ - user:tmps + user: tmps }) _this.update() } @@ -70,27 +81,27 @@ Page({ }) }, - update(){ - api('/user/update','POST',this.data.user,"json").then(res => { - if (res.code === 200){ + update() { + api('/user/update', 'POST', this.data.user, "json").then(res => { + if (res.code === 200) { } }) }, - goStore(){ + goStore() { wx.navigateTo({ url: '../store/index', }) }, - goAbout(){ + goAbout() { wx.navigateTo({ url: '../user/about', }) }, - goPrivate(){ + goPrivate() { wx.openPrivacyContract() }, @@ -127,6 +138,18 @@ Page({ * 用户点击右上角分享 */ onShareAppMessage() { + return { + title: '发现一个宝藏养花神器', + imageUrl: "https://res.catter.cn/pub/2025/12/08/20251208112039694.png", + path: '/pages/index/index?inviteCode=' + this.data.inviteCode + }; + }, + onShareTimeline() { + return { + title: '发现一个宝藏养花神器', + imageUrl: "https://res.catter.cn/pub/2025/12/08/20251208112039694.png", + path: '/pages/index/index?inviteCode=' + this.data.inviteCode + }; } }) \ No newline at end of file diff --git a/pages/user/index.wxml b/pages/user/index.wxml index c00ec3e..879fcc6 100644 --- a/pages/user/index.wxml +++ b/pages/user/index.wxml @@ -2,7 +2,7 @@ - + diff --git a/pages/user/index.wxss b/pages/user/index.wxss index 066b22b..f87c7b9 100644 --- a/pages/user/index.wxss +++ b/pages/user/index.wxss @@ -20,7 +20,7 @@ button::after { .avatar-wrapper { padding: 0; - + color: #000000E6 !important; background-color: rebeccapurple !important; width: 280rpx; } diff --git a/project.private.config.json b/project.private.config.json index d23ac87..2f8334e 100644 --- a/project.private.config.json +++ b/project.private.config.json @@ -23,12 +23,19 @@ "condition": { "miniprogram": { "list": [ + { + "name": "pages/index/index", + "pathName": "pages/index/index", + "query": "inviteCode=7NQJHCKT", + "scene": null, + "launchMode": "default" + }, { "name": "pages/store/index", "pathName": "pages/store/index", "query": "", - "scene": null, - "launchMode": "default" + "launchMode": "default", + "scene": null } ] }